STM32 FreeRTOS with LibOpenCM3

1.3k views Asked by At

I have a STM32 BluePill Board (STM32F103C8 with 8Mhz Quarz) and tried to upload a small blink program made with LibOpenCM3 and FreeRTOS. But for some reason FreeRTOS hangs in vTaskStartScheduler() the sys_tick_handler also doesn't do anything.

I didn't use a debugger and just placed a gpio_reset inside the sys_tick_handler function and after the vTaskStartScheduler call to test if the code gets executed but it didn't seem to do anything and I can't figure out why. The code is available here: https://gitlab.com/feldim2425/stm32-testing

UPDATE: I debugged with OpenOCD and fount out that it jumps into the hard_fault_handler UPDATE 2: The UsageFault-Status-Register has the NOCP bit set

2

There are 2 answers

0
feldim2425 On BEST ANSWER

Ok I found the issue. Many examples seem to rely on compiler optimization to directly link the vPortSVCHandler, xPortPendSVHandler and xPortSysTickHandler from FreeRTOS into the vector table if you call them inside your own handler vector implementation for sv_call_handler, pend_sv_handler and sys_tick_handler. But that didn't work here, the functions have to be called directly by the processor.

Adding these 3 Lines to the bottom of the FreeRTOSConfig.h file and removing my own function declarations for the vectors fixed the problem:

#define vPortSVCHandler sv_call_handler
#define xPortPendSVHandler pend_sv_handler
#define xPortSysTickHandler sys_tick_handler

The fix is described here: https://www.freertos.org/FreeRTOS_Support_Forum_Archive/January_2012/freertos_LPC1768_FreeRTOS_4964917.html

It is described for CMSIS but the only difference (in this case) are just the names of the vectors/handler functions.

1
aneox On

thank you! i have copy/paste from SPL project to libopencm3, and cant found why i get haurdfault))

I'm convinced once again, zoo of libs its bad idea, i should write on bare cmsis))

-#define xPortSysTickHandler SysTick_Handler
-#define xPortPendSVHandler PendSV_Handler
-#define vPortSVCHandler SVC_Handler

+#define xPortSysTickHandler sys_tick_handler
+#define xPortPendSVHandler pend_sv_handler
+#define vPortSVCHandler sv_call_handler