Stack Over Flow error

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 : 3n");

    //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

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

In the Beacon_Send, There is ~~~ void mactx(buffert buf, mac_hdr_t hdr, address_t *addr, uint8 indir, uint8 ack_req, uint8 DSN) { / * Todo List. * 1. halMcuWaitUs -> Analyze & devicde below codes to CSMA-CA algorithm. * 2. RFISR code change * 3. Receiving Parsing */ Transmimit_set(buf, hdr); switch (hdr.mac_frm_ctrl.frame_type) { case MAC_BEACON: case MAC_ACK: //UARTprintf(“Send by transmit func.n”); Transmmit(buf, 0, 0); break;
default: {
    //Transmmit(buf, 0, 0);
    //UARTprintf("Send by CSMA_CAn");
    //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

I have one more questinos ! What is that mean A5 value and Disappearing A5 means that stack is overflowed ?

Stack Over Flow error

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

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

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

Stack Over Flow error

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

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

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

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