Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

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

$
0
0

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:

Attached File  blink_cmsis_gcc.zip   14.5KB   0 downloads

 

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)

ccs_ramfunc.png


Viewing all articles
Browse latest Browse all 2077

Trending Articles