Electrical – FreeRTOS causes SYSTICKACT (HardFault) exception

cortex-m4exceptionfreertoshard-faultstm32

I generated a basic project with CubeMX for STM32F4. After compiling and having successful run, I added FreeRTOS manually. Unfortunately, all the time I'm getting HardFault exception with SYSTICKACT bit in SCB->SHCSR set to 1. What wrong I've done while adding FreeRTOS?

Best Answer

Both the HAL and FreeRTOS use the SysTick - CubeMX does this by calling the FreeRTOS systick handler (vPortSysTickHandler() I think, but might have the name wrong) from its own systick handler. In FreeRTOS you can do the reverse by calling the HAL systick handler from FreeRTOS's tick hook function. Note however that, while FreeRTOS normally runs SysTick at the lowest possible priority, the CubeMX generated code needs the SysTick to run at the highest priority (because its interrupt drivers contains delays that spin on the tick value, and you don't want them to starve out the interrupt they are waiting for).