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?

  • \$\begingroup\$ Did you forget to add the ISR for the systick exception? Also, this: stackoverflow.com/a/41832089/1850429 \$\endgroup\$ – Jeroen3 May 17 '17 at 17:40
  • \$\begingroup\$ Error occurs while MCU process HAL_Delay() \$\endgroup\$ – VIPPER May 17 '17 at 17:59
  • \$\begingroup\$ Because the HAL_Delay executes in ISR which has lowest priority than ISR you have possibly invoked an wait certain amount of time. \$\endgroup\$ – Marko Buršič May 17 '17 at 18:02
  • \$\begingroup\$ but in my code there is no any other interrupts, only SysTick \$\endgroup\$ – VIPPER May 17 '17 at 18:48
  • \$\begingroup\$ I have no problems when doing the same with CubeMX, which generates project with FreeRTOS included, I know I'm doing something wrong. SysTick has priority set to 15 \$\endgroup\$ – VIPPER May 17 '17 at 18:51

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).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.