Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


vTaskDelay cause HardFault_Handler

Posted by matita87 on August 1, 2017

Hi My application run on stm32F4 with FreeRTOS V9.0.0 and port files SourceportableRVDSARMCM4F (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 HardFaultHandler). The code is: int main(void) { initfoo1() initfoo2() xTaskCreate(aTask, "name",1280, NULL, 6, NULL); initfoo3(); vTaskStartScheduler(); } void aTask() { vTaskDelay(1000);//At this time I have 2 task: this taks and the task Scheduler. bar();//never go here, becaouse a HardFaultHandler 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? Thanks all m

vTaskDelay cause HardFault_Handler

Posted by rtel on August 2, 2017

What is wrong?

Impossible to say from the information provided, but here are some pointers to help you debug:

1) 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 2) Did you check xTaskCreate() returned pass? 3) 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 4) Do you have configASSERT() defined? http://www.freertos.org/a00110.html#configASSERT 5) It looks like you have enough stack, but just for good measure: http://www.freertos.org/Stacks-and-stack-overflow-checking.html 6) Are there any interrupts executing? If so, are the priorities set correctly: http://www.freertos.org/RTOS-Cortex-M3-M4.html

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner