-
Hi all, My colleague and I have had our brains melted in the last couple of days. I have some code that looks some thing link this
When I compile this on my machine using cmake it works entirely as you'd expect and setInterrupted gets called when the interrupt pin fires. However on their machine ( using the same version of stm32aduino, but using sloeber to compile the interrupt code doesn't run. If however he moves the attachInterrupt function into the drivers begin function everything works as expected. So, a few questions: Is this unexpected behavior expected? Any answers will be greatly appreciated, else this might haunt my dreams forever more :) Thanks Alan |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @Alan01252
if you don't need to set pullup the pinMode is not required when you use the attachinterrupt it will configure the GPIO but keep the PU configuration. |
Beta Was this translation helpful? Give feedback.
Understood @fpistm , googling around etc I think you're right.
Reading main.cpp of stmduino
// Force init to be called first, i.e. before static object allocation.
// Otherwise, statically allocated objects that need HAL may fail.
attribute((constructor(101))) void premain()
{
// trim
init();
}
It sounds like for most scenarios this would work, but I can see how interrupts might act differently.
I hadn't for example considered the case of the interrupt firing before the constructor had completed and I can see how that might cause various problems too.
But in general I'm now leaning towards the fact that almost everything related to GPIO pins etc should be done in a begin function.