Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


vApplicationStackOverflowHook cannot wake ...

Posted by Martin Velek on November 14, 2011

please, could someone help me, what I am doing wrong? I have created two tasks, the first is used to generate stack overflow the latter to detect it. In the function vApplicationStackOverflowHook, I am trying to send something (even uninitialized, does not matter) to the queue. The variable pxHigherPriorityTaskWoken is pdTRUE and portYIELD_FROM_ISR() is called. However the vApplicationStackOverflowHook is called again and again. How should I end the vApplicationStackOverflowHook to wake up the function detect_stack_error?

Thank you for your advices.


ARM7 - LPC2478 - v7.0.2

xQueueHandle xQueue;
void stack_error( void * pvParameters ) // priority normal
uint32_t stack[40];

for (int i = 0; i < 50; ++i)
stack = i;

while (1)

void detect_stack_error( void * pvParameters ) // priority highest
xQueue = xQueueCreate(10, sizeof(unsigned char));
unsigned char a;
while (1)
xQueueReceive(xQueue, &a, portMAX_DELAY);
__asm ("NOP\n");

void vApplicationStackOverflowHook(void *pxTask, char *pcTaskName)

portBASE_TYPE pxHigherPriorityTaskWoken;
unsigned char pvItemToQueue;
xQueueSendFromISR( xQueue, & pvItemToQueue, &pxHigherPriorityTaskWoken );


RE: vApplicationStackOverflowHook cannot wake ...

Posted by Richard Damon on November 14, 2011
If you are not running on a system with an MMU, once you have experienced a stack overflow, the system may well be now in an unstable state and not able to continue.

I am also not sure what parts of the API are allowed to be called from the stack overflow routine, and I suspect trying to force a task switch may not be allowed there, as the stack check is happening within the task switch routine.

Normally the overflow hook will be code to somehow output an error message somewhere if possible with primitive code, and then restart the processor.

RE: vApplicationStackOverflowHook cannot wake ...

Posted by Richard on November 14, 2011
Generally, unless you are using an MPU port, you cannot recover from a stack overflow. When you have an MPU, you get notification of the stack overflow before any corruption happens as a trap is triggered as soon as a write outside of the region allocated to the stack is attempted. Most ports don't use an MPU, and you only know a stack overflow has happened some time after it has happened - and at that point you don't know what the system state is so all you know is you know nothing. Generally a stack overflow will corrupt a TCB, so the task you are trying to yield from is already corrupt. Even if you are lucky enough that something sensible happens, you will just re-enter the context switch and detect the stack overflow again.


Also consider that the stack overflow is called from the context switch mechanism. You cannot attempt to re-enter the context switch by requesting a context switch when you are already in a context switch (if that makes any sense at all ;o).

RE: vApplicationStackOverflowHook cannot wake ...

Posted by Yuantu Huang on October 25, 2012
Hi Richard,

Do you mean to use xQueueSend or xQueueSendFromISR all OK in the stack overflow hook function?

void vApplicationStackOverflowHook(xTaskHandle *pxTask, signed portCHAR *pcTaskName)
// do not call portYIELD_FROM_ISR();


void vApplicationStackOverflowHook(xTaskHandle *pxTask, signed portCHAR *pcTaskName)


RE: vApplicationStackOverflowHook cannot wake ...

Posted by Richard Damon on October 26, 2012
The context that FreeRTOS calls the vApplicationStackOverflowHook is not suitable for making calls to most of the FreeRTOS API as you are in the middle of the scheduler.

As I said before, at the point where you have detected that you have overflowed the stack, you are really in a state where you can not trust your system, so trying to continue is really not advised.

RE: vApplicationStackOverflowHook cannot wake ...

Posted by Yuantu Huang on October 28, 2012

Thank you very much. That is the reason why pcTaskName can not be printed sometimes when overflow happens just because no stack is available for the task? As you suggested, could things to do in vApplicationStackOverflowHook be flashing LED or loop forever?

RE: vApplicationStackOverflowHook cannot wake ...

Posted by Richard Damon on October 28, 2012
Yes. At the point that it has detected the problem, there is significant chance that your system memory is corrupted. Any code there should not depend on the rest of the system being operational. An infinite loop is one reasonable process (possible blinking an led also), or rebooting the system. The reboot can possible pass on the information about why the reboot was caused and the new invocation of the system may be able to send out a message about it, hopefully before the problem reoccurs.

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists