This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Stack initialization with constant

Doe Keil IDE support initializing stack space with a constant? For example with a #define. If not, please does someone have ARM Cortex M3/M4 assembler code to do that and where should it be located? For example in startup*.s prior to the branch to main?

Parents Reply Children
  • Hmmm.

    The area gets cleared by the scatter loader (executed between startup and entry to main).

    This is where I have previously started using a slightly more complex scatter file. Using an UNINIT section for the segment that I din't want to be touched by the scatter loader.

  • OK. Thanks for the hint. I see the project's scatter file *.sct in \Obj\ folder and that I can specify a different one by unchecking the target Options/Linker/Use Memory Layout from Target Dialog checkbox.

    So how do I get the STACK into an UNINIT'd section please? ... or where can I find instructions to make a new scatter file?

  • Sorry, I don't have much time now ... but here's a scatter file I've modified from one of the Blinky examples. I gave it a quick try and the stack is not now being cleared.

    In the IDE, select this one (or the one that you'll modify accordingly).

    LR_ROM1 0x00000000 0x04000000  {    ; load region size_region
      ER_ROM1 0x00000000 0x04000000  {  ; load address = execution address
       *.o (RESET, +First)
       *(InRoot$$Sections)
       .ANY (+RO)
      }
    
      RW_RAM1 0x20000000 0x00400000  {  ; RW data
       .ANY (+RW +ZI)
      }
    
      RW_STACK +0 UNINIT ALIGN 16       ; RW data - Stack <<< THIS SECTION IS WHAT I ADDED
      {
        *.o (Stack)
      }
    }
    

  • Thanks very much for your generous help. It appears to work now as you described with the stack left full of 0xcccccccc.

  • Hi John,

    Why modify the scatter file?
    It's not easy to put the code in the stack initalisation?
    The ram is initialized before.

    __user_initial_stackheap
    
                     LDR     R0, =Stack_Mem            ; Test stack
                     LDR     R1, =Stack_Size           ;
                     LDR     R2, =0xCCCCCCCC           ;
    Fill             STR     R2, [R0], #4              ;
                     SUBS    R1,#4                     ;
                     BNE     Fill                      ;
    
    
                    LDR     R0, =  Heap_Mem
                    LDR     R1, =(Stack_Mem + Stack_Size)
                    LDR     R2, = (Heap_Mem +  Heap_Size)
                    LDR     R3, = Stack_Mem
                    BX      LR
    
                    ALIGN
    

    thank you for your thread, it helped me a lot.