This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TI RTOS Global Variable Overwrite Issue

Hello,

I have numerous tasks and some global variables defined as volatile. I have added a new task and declared a quite large array statically in the new task. The size is around 512Byte. Somehow I see the global variable is overwritten when the new task is added to the program. (when this task is not started everything is fine)

I would say, my problem is very similar to this post:

But I am not sure what to do to solve it.

I have increase the new task stack size over 8192 Byte but the problem still exists (anyway the stackPeak is far below the stackSIze in ROV.

Another question, when I declare an array statically in a task which stack will be used?

Looking forward any help, 

thank you.

  • Chuck Davenport reply doesn't clear for me. Should I replace all of my static array allocation to dynamic in order to keep my global variable safe? And how should be possible to harm an array static declaration to other variable memory address?

    Another experiment:

    As I mentioned I have two tasks, task A and B. Task A initiates a global variable with value 0. This Global var. value changed randomly, and independent from which task started first.

    Update: Changed the Configuration from Debug to Release and I got the following error:

    warning #10247-D: creating output section ".bss" without a SECTIONS specification
    warning #10247-D: creating output section ".data" without a SECTIONS specification
    warning #10247-D: creating output section ".const" without a SECTIONS specification
    warning #10247-D: creating output section ".text" without a SECTIONS specification
    warning #10247-D: creating output section ".bss:.common" without a SECTIONS specification
    warning #10247-D: creating output section ".cinit" without a SECTIONS specification
    "./configPkg/linker.cmd", line 143: warning #10096-D: specified address lies outside memory map
    error #10264: DEFAULT memory range overlaps existing memory range RAM
    error #10010: errors encountered during linking; "TivaC with RTOS.out" not built

  • Daniel,

    I think when you declare a static variable in a task function it will be placed in the .bss section, not on a stack. 

    From your output it looks like you are using the TI compiler on a TivaC.  Is that correct?

    Is it possible that your task function is writing beyond the bounds of the static array, and this is overwriting adjacent globals in .bss?  That seems the most likely explanation…

    Thanks,
    Scott

  • Dear Scott,

    Thank you for your reply. Fortunately I could solve the problem. Let me share what was the problem, maybe helpful for anyone else.

    As I mentioned the Global variable has a random value after certain task started. I placed some breakpoints to the task where I identify the global var. value change and also set my global var. to Expressions in order to monitor its value during code execution.

    In my task there is a function call:

    extern void GPIO_setCallback(unsigned int index, GPIO_CallbackFxn callback);

    to initialize GPIO callback function. After this call the global var. default 0 value has changed randomly. When I disabled the GPIO_SetCallback() , the problem gone.

    Problem was the following:

    /*
     * Array of Pin configurations
     * NOTE: The order of the pin configurations must coincide with what was
     *       defined in EK_TM4C123GXL.h
     * NOTE: Pins not used for interrupts should be placed at the end of the
     *       array.  Callback entries can be omitted from callbacks array to
     *       reduce memory usage.
     */
    GPIO_PinConfig gpioPinConfigs[] = {
    
    
    	// ADC1_CS
    	GPIOTiva_PE_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_MED | GPIO_CFG_OUT_HIGH,
    	// ADC1_DRDY
    	GPIOTiva_PD_6 | GPIO_CFG_IN_PD | GPIO_CFG_IN_INT_FALLING,  // This pin: GPIOTiva_PD_6 has inited two times in this function call
    
    
    };
    

    As you can see in the comment, I have initialized GPIO_Tiva_PD_6 pin two times int gpioPinConfigs[] function. When I removed the duplication the GPIO_SetCallback() has not changed the value of my global variable.

    This was very painful to debug and hard to find this bug in my code, thats why I share my experience with you.

    All the best, and thank you for your time.

  • Daniel,

    I’m glad to hear this is resolved.  Thank you very much for reporting back your resolution for the problem. Hopefully it will help others in the future.

    Best regards,
    Scott