Hi,
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.
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.
Having 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.