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.

Assembler code snippet to fill in the stack with a pre-defined value

Other Parts Discussed in Thread: TMS320F28335, CONTROLSUITE

Hello,

I am sure this has been done countless times before me, I just can't find it on the forum or the wiki pages.

I want to fill in the stack with a pre-defined value, probably using some assembler in CodeStartBranch.asm to do it as early as possible. The goal is obviously to get a high watermark when the code is running and evaluate how much stack is actually used.

I am using the TMS320F28335. If someone could post a snippet of assembler code (or point me to a wiki page or some documentation), that would be fantastic! I am sure that will help a lot of other people as well.

Thank you very much.

  • Lori recently educated me on this, The below assembly code should do what you want.

         .sect     ".stack"

         .asg      330000h, addr   ; adjust the address here as you need

         .loop     00C000h           ; adjust the count here as you need

         .long     YOUR_PATTERN

         .eval     addr + 2, addr

         .endloop

    hope it helps.

    Best Regards

    Santosh

  • Hi,

    TI provides an excellent document on how to use online stack overflow protection. See here. Another very easy way to fill the stack with a dummy value is to use the gel file. In your device gel, simply add the following lines to the "OnFileLoaded" method:

    OnFileLoaded(int nErrorCode, int bSymbolsOnly)
    {
     if (!bSymbolsOnly) {
         Device_Cal();
     }
     GEL_MemoryFill(0x50,1,0x100,0xBEEF);
    }

    where the first param is the start addr, the second param declares the page, the third is the length, and the last the pattern. However this is only suitable during developpment, so I recommend online stack supervision nonetheless.

    Hope this helps,

    Andreas

  • Dear Santosh,

    Thank you very much for the code snippet, it indeed does what I need.

    Last question: is there a way to get the start and length of the ".stack" section without refering to hardcoded values?

    Best regards,

      Fabrice

  • Hi Fabrice,

    check you map file there should be __STACK_END and __STACK_SIZE variables defined in there. These come from the default linker command variables. Users can also define their own symbols via the linker command file and refer to these in the code. The C2000 tools (compiler/assembler or linker) guide should talk about these. Or browse through one of the flash based example linker command files in ControlSuite there will atleast on similar usage that you can refer to.

    Hope it helps

    Best Regards

    Santosh

  • Hi Santosh,

    Thank you.

    Final question: does the stack grow upwards or downwards?

    Best regards

  • on C28x stack is incremental, it goes upwards like STACK_START, STACK_START+1, STACK_START+2.....STACK_END

    Best Regards

    Santosh