I'am trying to run a RTOS on my STM32F407VGT6 board. I downloaded the demo CORTEX_M4F_STM32F407ZG-SK from freeRTOS website and flashed the code using IAR IDE, however the leds are not blinking as expected. while debugging the program i found that the program crashes here:

ldr r0, =0xE000ED08
ldr r0, [r0]
ldr r0, [r0]
msr msp, r0
cpsie i
cpsie f
svc 0 // The program crashes here!!!!

I made some research in freeRTOS FAQ, the section "The application I created compiles, but does not run" seems to treat the same issue but

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

exists in FreeRTOSConfig.h file. Does anyone faced the same issue? or the RTOS that I'am using is not the right one?

  • 1
    \$\begingroup\$ "crashes" = zero information. You should examine the Fault registers and understand what they are telling you. \$\endgroup\$ – Eugene Sh. Aug 26 '15 at 16:29
  • \$\begingroup\$ Thanks @EugeneSh. by "the program crashes" I mean that i am unable to pass to the next instruction. could you please provide me with further information about Fault register? what are the Fault registers in stm32F4 and what value should i have in these registers? \$\endgroup\$ – fedi Aug 26 '15 at 16:43
  • \$\begingroup\$ Read about the Hard Fault exception handling in Cortex-M and your specific chip. Check whether it is the case (by breaking in that ISR). \$\endgroup\$ – Eugene Sh. Aug 26 '15 at 16:46

If your code is 'crashing' on that line, then it is most likely you don't have the FreeRTOS SVC handler installed. I note you included the line:

#define xPortPendSVHandler PendSV_Handler

Which will replace a CMSIS standard name (PendSV_Handler) with the FreeRTOS name, but that is assuming your vector table is using the CMSIS standard name - check that is the case, and that nothing else in your application is replacing the vector table with a different one by re-writing the vector base address register. By the way - FreeRTOS has a very active support forum - always beats me why people ask FreeRTOS questions in any other place than the place specifically where FreeRTOS experts are watching and ready to answer questions.

ARM cortex M4 products are based on ARM7 core architecture

Actually, this is not the case. As confusing as it may seem, ARM7 microcontrollers use an ARMv4 core, whereas Cortex-M4 microcontrollers use an ARMv7 core :o) So that particular FAQ does not apply in this case.


In the FreeRTOS FAQ that you are using did check for point 5

  1. The RTOS scheduler crashes when attempting to start the first task If you are using an ARM7 target then the processor must be in Supervisor mode when the RTOS scheduler is started.

ARM cortex M4 products are based on ARM7 core architecture, see this wikipedia reference and since your snippet clearly shows "vPortStartFirstTask" this completely seems to describe what is going on with your system.

  • \$\begingroup\$ Regardless if this is architecturally applicable or not, the reference manual states that the Control register of the STM32F4 is cleared on reset, which should mean operation starts in privileged mode, so it seems this would only be an issue if something has changed the mode before starting the scheduler. \$\endgroup\$ – Chris Stratton Jun 6 '16 at 19:55
  1. You must remove the SVC_Handler and PendSV_Handler ISR handler in stm32f4xx_it.c file.

  2. The FreeRTOS files must be compiled in c compiler mode not in C++, it is mean that C files must be compiled as C source code and C++ files must be compiled as C++ source code. You can select "Auto(extension-based)" in Language section.

  3. You must add the root of FreeRTOSConfig.h file to preprocessor tab of assembler section of project option window like this:enter image description here


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.