arduino / arduino/ArduinoCore-sam
invalid conversion from 'void (*)()' to 'void (*)()' when using optimization flags with interrupts
- Dominant language
- HTML
- Stars
- 91
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
I had some toruble recently with a simple program using interrupts and optimization flags on the due:
#pragma GCC push_options
#pragma GCC optimize ("O3")
void setup() {
Serial.begin(115200);
pinMode(7, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(7), changeState, RISING);
}
void loop() {
Serial.println("loop");
delay(1000);
}
void changeState() {
Serial.println("changed state");
}
When trying to compile with the optimization options, I get the following error:
sketch_feb02a:6: error: invalid conversion from 'void (*)()' to 'void (*)()' [-fpermissive]
attachInterrupt(digitalPinToInterrupt(7), changeState, RISING);
^
arduino-1.8.5\portable\packages\arduino\hardware\sam\1.6.11\cores\arduino/WInterrupts.h:28:6: error: initializing argument 2 of 'void attachInterrupt(uint32_t, void (*)(), uint32_t)' [-fpermissive]
void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);
^
exit status 1
invalid conversion from 'void (*)()' to 'void (*)()' [-fpermissive]
Which seems really odd to me. When removing the first two lines of my code, it compiles fine.
I really have no clue why this happens but maybe someone here can use this. Maybe it's a bug, maybe I shouldn't have used these flags in the first place.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the error with the provided sketch, the Arduino Due target, and the two GCC optimization pragmas. Start by comparing the attachInterrupt call in the sketch with the declaration in arduino-1.8.5\portable\packages\arduino\hardware\sam\1.6.11\cores\arduino/WInterrupts.h; done means the sketch compiles with optimization enabled without the invalid-conversion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100