Jump to content

msp432 - run code from ram using arm-none-eabi-gcc in CCS

Recommended Posts

I noticed that if you use the TI arm compiler in CCS 6.x you can easily run code from ram.  Unfortunately, it doesn't seem like they have implemented that for the arm-none-eabi-gcc compiler. Attached is a zip file project you can import into CCS.  It is configured to run the msp432 at 48MHz using the high frequency crystal.   It is also configured to generate small code using the nano.specs newlib configuration.


In the default linker script, the data segment uses all the available ram starting at the base address of 0x20000000.  The msp432 provides another bus address for SRAM at the base address of 0x01000000.  This alias address is used to provide single cycle access to code in ram. I modified the the linker script in this project (msp432p401r.lds) so that the first 512 bytes of ram are reserved for code. 

/* adjust based address for fixed size of 512 bytes (0x200) for code in ram */
/* NOTE: if you change this size, make sure you adjust .vtable offset also */
SRAM_DATA  (RW) : ORIGIN = 0x20000000+0x200, LENGTH = 0x00010000-0x200

Additonally, a new section called .ramfunc is used to collect any code put into the ".ramfunc" section. You do this using the gcc specific _attribute__((section(".ramfunc"))) directive.  When the chip resets, code has been added to copy the instruction code from flash to ram.

extern uint32_t __ramfunc_load__;
extern uint32_t __ramfunc_start__;
extern uint32_t __ramfunc_end__;
void resetISR(void)
    /* Copy .ramfunc code and data segment initializers from flash to SRAM. */
    volatile uint32_t *pui32Src, *pui32Dest;
    pui32Src = &__ramfunc_load__;
    for(pui32Dest = &__ramfunc_start__; pui32Dest < &__ramfunc_end__; )
        *pui32Dest++ = *pui32Src++;

Attachment blink_cmsis_gcc.zip:



In CCS, go to Project Menu and select the "Import CCS Projects ..." and select the archive file button. Use the file dialog to select the location where you downloaded the attached blink_cmsis_gcc.zip file.


BTW: This is using the new CMSIS headers.


Running in the debugger (note the address 0x10000FC of the code in the disassembly window)


Link to post
Share on other sites
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...