My application run on stm32F4 with FreeRTOS V9.0.0 and port files Source\portable\RVDS\ARM_CM4F (imported via RTE Keil).
The main, call some initialization functions, then create the task and then call the vTaskStartScheduler.
The task simply call vTaskDelay(1000) which never return (causing the HardFault_Handler).
The code is:
xTaskCreate(aTask, “name”,1280, NULL, 6, NULL);
vTaskDelay(1000);//At this time I have 2 task: this taks and the task Scheduler.
bar();//never go here, becaouse a HardFault_Handler appears before.
This problem appears almost always.
Note: if I remove all the function before the task creation the vTaskDelay works correctly.
What is wrong?
Could be a problem related to the main “corrupted” (stack pointer)?
If yes, how can I solve it?
What is wrong?
Impossible to say from the information provided, but here are some pointers to help you debug:
- Step through the code to see where the hard fault happens. If it is hard to find because it is occuring in an interrupt (or some place other than where you are stepping) then try this technique: http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html
- Did you check xTaskCreate() returned pass?
- How do you know bar() never gets executed? Could it be executed without you knowing? Your task should either be in an infinite loop so it doesn’t return or call vTaskDelete() before it exits. If bar does execute and return then the task will run off the end and crash. http://www.freertos.org/implementing-a-FreeRTOS-task.html
- Do you have configASSERT() defined? http://www.freertos.org/a00110.html#configASSERT
- It looks like you have enough stack, but just for good measure: http://www.freertos.org/Stacks-and-stack-overflow-checking.html
- Are there any interrupts executing? If so, are the priorities set correctly: http://www.freertos.org/RTOS-Cortex-M3-M4.html