I’m using FreeRTOS v10.2.1 via the CMSIS-OS v2 API on an stm32l0 controller.
There’s an instance when start a one-shot timer and when the timer expires, I proceed to set an event flag. I have a thread waiting on these flags succesfully, however when the control loop proceeds back to waiting on the event flag, I hardfault in the PendSV_Handler() function.
So in summary to reproduce:
- Create a one-shot timer
- Create a thread
- Create an event group
- Have thread wait on any flags of the event group
- Start the one-shot timer
- When timer expires, set a flag of the event group
- Thread wakes up, does some processing
- Thread waits on event flags again
- Hardfault on step 8.
Any idea why this is happening? Thanks
Except fatal application programming bugs the main reasons for application crashes are
- stack overflows
- wrong interrupt priorities for certain ports/MCUs e.g. with Cortex-M CPUs
This especially applies to such strange issues like you’ve encountered (code runs fine and next time the same code hardfaults).
You should define configASSERT and also enable stack overflow checking for development/debugging.
Using assertions can help to catch a number of otherwise occurring HardFaults with the possibility to trace back and identify the problem.
configASSERT defined (in FreeRTOSConfig.h as documented) makes debugging a lot easier by stopping the debugger if the application hangs. If the hang is caused by an assertion, the application is halted in the forever loop usually the last part of the assertion code (as in example 2 following the configASSERT link) and check the call stack for the cause of the assertion.
Edit: Do you use FreeRTOS timers or a HW timer ?
Thanks, I enabled stack overflow checking and it turns out the timer task was overflowing.
(I’m using the freertos timers)