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.

Initializing stack

Other Parts Discussed in Thread: CONTROLSUITE

Is there an assembly code snippet I can add to CodeStartBranch.asm to fill my stack space with a pattern?

  • Hi Jim,

    Right now we do not have an assembly code snipet to do this in controlSUITE.  However, there is a few ways to fill the stack space with a specific pattern.  First, you can write a for loop in assembly to fill the stack with a specific value.

    Or you can use the linker command file to do this for you.  Check out the C28x Assembly Language Tools and User Guide.  http://www.ti.com/lit/ug/spru513h/spru513h.pdf

    1. You can add "fill = value" to a section in the linker command file.  Section 8.5 in the User's Guide.
    2. You can add an assembly directive "--asm_data_fill = value" to fill holes in sections.  Section 4.10 in the User's Guide.  You can access this in CCS under the project's Properties-> Build-> C2000 Compiler-> Advanced Options-> Runtime Model Options.
    3. You can use the linker flag "--fill_value = value" to fill the holes as well.  Section 8.4 of the User's Guide.  You can access this in CCS under the project's Properties-> Build-> C2000 Linker-> Advanced Options-> Runtime Environment.

    Best Regards,

    sal

  • Jim,
    Also look at his e2e thread. http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/196862

    sal
  • The following C-code should do what you want:

    #define STACK_PATTERN   (0xAAAAu)
    
    static uint16_t *globalIterator;
    
    /**
     * @brief Stack intialization
     */
    void stackInit(void)
    {
      uint16_t topOfStack;
    
      globalIterator = &topOfStack;
      while(globalIterator < &vStackEnd)
      {
        *globalIterator = STACK_PATTERN;
        globalIterator++;
      }
    }
    

    The trick is, that globalIterator is initialized by the address of topOfStack variable, thus this variable cannot be assigned to a register (register has no address) and must be allocated on the top of the stack. Then simply fill the rest of the stack by predefined pattern. The vStackEnd is a symbol defined by linker - the address of this symbol is equal to the last address of the stack (see the RUN_END operator in SPRU513h, paragraph 8.5.10.6).