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




Loading

Stack Over Flow error

Posted by boogalee on October 25, 2016

Hi.

I am making 802.15.4 protocol over FreeRTOS.

I mad my own 802.15.4 protocol and i had finished port on CC2538.(Tool : CCSv5)

I had succeeded some tasks blinky leds.

I want to try to combine FreeRTOs with 802.15.4. So i tried to make one task including send beacon function.

However there was an error about stack pointer and stack over flow.

I had created task such as below code.

~~~ if (xTaskCreate(BeaconSend, (signed portCHAR *)"BeaconSend", 200, NULL, 3, NULL) == pdTRUE) { //GPIOPinWrite(GPIOCBASE,GPIOPIN3,GPIOPIN3); } ~~~

~~~ static void BeaconSend(void *pvParameters) { //TaskHandlet xHandle; halIntOn() ;

mac_init();   // MAC init & set PANID & Short Addr
while (1) {

	UARTprintf("Send_Beacon - priority : 3\n");

	//Before Send_Beacon SP is 0x200043000
	Send_Beacon();
	// After Send_Beacon  SP is 0x200043000
	vTaskDelay(1000);
}

}

~~~

At the first time i tried, there was a stack over flow.

So i changed system stack size to 768.

But there was a stack over flow again.

I tried to track Stack Pointer. Before calling Send_Beacon() SP is 0x200043000.

After Send_Beacon() SP is 0x200043000 either. I thougth there was no problem about stack size.

However, when i start that task, vApplicationStackOverflowHook() is called and go to infinite loop.

What is the problem? In my guess, Send_Beacon is not needed too much stack size.

Plz help me.


Stack Over Flow error

Posted by rtel on October 25, 2016

Do you have the source code for BeaconSend()? If so view the task's stack in the memory region. Use the debugger to stop on entry to the task. Next get the stack pointer used by the task from the register's window in the debugger and open a memory view at that address. You should see the stack is filled with 0xa5. Now put a break point where SendBeacon() is called and, watching the stack in the memory window, step into the function. You will see the 0xa5's getting overwritten as you step through the function - at what point do all the a5's disappear, so all the stack is consumed?


Stack Over Flow error

Posted by boogalee on October 26, 2016

In the Beacon_Send,

There is ~~~ void mactx(buffert buf, machdrt hdr, addresst *addr, uint8 indir, uint8 ackreq, uint8 DSN) { / * Todo List. * 1. halMcuWaitUs -> Analyze & devicde below codes to CSMA-CA algorithm. * 2. RFISR code change * 3. Receiving Parsing */ Transmimitset(buf, hdr); switch (hdr.macfrmctrl.frametype) { case MACBEACON: case MACACK: //UARTprintf("Send by transmit func.n"); Transmmit(buf, 0, 0); break;

default: {
	//Transmmit(buf, 0, 0);
	//UARTprintf("Send by CSMA_CA\n");
	//csma_send(buf, 0, 0);
}
}

} ~~~ At entry of this fuction, all the a5's was dsiappeared.

I think Transmimit_set() and Transmmit() is too big, Beacuse of two functions, stak over flow was occurred.

Is my guess right ?


Stack Over Flow error

Posted by boogalee on October 26, 2016

I have one more questinos !

What is that mean A5 value and Disappearing A5 means that stack is overflowed ?


Stack Over Flow error

Posted by heinbali01 on October 26, 2016

What is that mean A5 value and Disappearing A5 means that stack is overflowed ?

0xA5 is just a funny pattern: b'10100101'. Indeed it is used to detect how much stack space has been used.

Important: do not use a compiler options that enable checks for stack overflow. That option often causes stack overflows. Please check if this was included.

The FreeRTOS stack warning options normally work nicely. But be aware: the SP moves so fast (in interrupts, during task swaps), that an overflow may be missed.

An alternative method is the following: give more than enough stack to the tasks and measure the lowest stack space available for every task during a long run. If you add N percent, you should have a reliable estimate.

Regards.


Stack Over Flow error

Posted by boogalee on October 26, 2016

Hi Hein Tibosch.

I thought i gave enough stack.

I set system stack size 800, and when i create task, I set stack depth to 300.

But.. it was all failed..


Stack Over Flow error

Posted by heinbali01 on October 26, 2016

Have you checked the compiler options? Is there an option that also check for stack overflows?


Stack Over Flow error

Posted by boogalee on October 27, 2016

Hi, Hein

I think there is no option to check for stack overflow.

In task, A5's changes other value after specific function is called.

That changing means stack is overflowed ?

If so, what is the solution ? decomposing function to several task ?


Stack Over Flow error

Posted by heinbali01 on October 27, 2016

I set system stack size 800, and when i create task

What do you mean with "system stack", is that the initial stack that is used before FreeRTOS is running?

I suppose the size is 800 words, meaning that 3.2 KB of RAM is assigned to that initial stack. You should also see how much is really used, or use the RAM space for other purposes once the kernel is running.

I set stack depth to 300.

Is this the stack of the task, I suppose?

Have you tried a bigger value already?

You can also try debugging to see what happens. Try to follow the value of SP when stepping through the code, especially when calling mac_tx(). You might have to step through the assembler instructions.

Regards.


Stack Over Flow error

Posted by boogalee on October 27, 2016

I think that i found problem !!

i had used memcpy function. i delete it and there was no stack overflow.

Is it possible to affect on stack ?


Stack Over Flow error

Posted by rtel on October 27, 2016

Evidently, yes, although the function should not use much stack itself I would guess the destination of your copy was overwriting the stack.


[ 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