2020-10-29 06:09 AM
I have the STM32G030K6T.
Connecting a magnet to my magnet detector causes HAL_GPIO_EXTI_Rising_Callback and removing the magnet causes HAL_GPIO_EXTI_Falling_Callback. I think I have too much code inside these functions. Inside these functions I'm fading LEDs up and down using HAL_TIM_SET_COMPARE. Executing these functions takes about 0.3 seconds. When I'm quickly connecting and disconnecting the magnet, the main program becomes unresponsive and only rising and falling callbacks are executed after this. My main program takes voltage measurements and runs a simple state machine.
What happens when these callbacks are "stacked" too much? Why does the main program become unresponsive?
EDIT: If I'm transmitting a lot of UART messages in main program the unresponsiveness happens fast. If i remove the UART messages the program might run for a while longer. Assuming I'm connecting and disconnecting the magnet for the whole time.
2020-10-29 07:30 AM
removed
2020-10-29 07:55 AM
Callbacks are done under interrupt context. You should be very brief. Put your fading code elsewhere.
They are not stacked, they will be missed, and at some point will saturate the processor such that the interrupt handler keeps re-entering to service the next signal (see tail-chaining), and no foreground code execution will occur. ie the entire time will be spent in the handler and callbacks that calls.
Have your Hard Fault Handler output some actionable data if it ends up there.