2018-04-12 05:37 PM
I would like to access a global object in my main.cpp from stm32l0xx_it.c.
In particular, I've created a LED object with a member function called update(). I'd like to be able to run the update function from within a timer based interrupt to change the state of the LED pins based on the internal state of the LED object. At the moment I'm just using the systick interrupt for prototyping purposes.
I've attached a small project demonstrating what I'd like to do.
#stm32-interrupts2018-04-12 11:40 PM
Perhaps others might browse through 5Mb of zipped sources.
I would like to access a global object in my main.cpp from stm32l0xx_it.c.
Basically just the standard way - if the variable is visible within the stm32l0xx_it.c module (global), you can directly access it. Be aware of race conditions when accessing variables from asynchronous handlers.
From a design point of view, it makes no sense to make volatile process input/output globally visible.
2018-04-13 05:57 AM
Like the previous person I haven't looked into the 5+ MB zip...
But basically, if the LED is connected to a GPIO pin, it can be toggled with just one memory write instruction. This should be OK in a interrupt handler, with either 'HAL' or 'LL' library for the GPIO.
Any other C++ stuff with objects and so on should be carefully inspected.
Good luck,
-- pa
2018-04-13 06:31 AM
The IRQ Handlers don't need to be in stm32l0xx_it.c you can make callable functions in main.cpp using the form
extern 'C' void USART1_IRQHandler(void)
{
...
}
Or create a wrapper function in main.cpp with similar C calling (avoids name mangling) that you can call from stm32l0xx_it.c