cancel
Showing results for 
Search instead for 
Did you mean: 

Another STM32CubeIDE question - How do I target code to run from RAM

MikeDB
Lead

I've searched the menus, and tried Google and the STM32CubeIDE's Help button and found nothing. How do I target the code to upload and run from RAM. I'm not using the CubeMX part if that's relevant - code is bare metal.

2 REPLIES 2
turboscrew
Senior III

It's done in linker script. I'm not sure how it works if you try to load the code directly to RAM, but it's usually done such that the code is loaded to flash and copied into RAM by the program. Then, in linker script, you need to use both load addresses and link addresses. Then the code is linked to be run from RAM, but loaded into flash.

Bit like this:

.text2 :
    {
    	. = ALIGN(.,0x8);
        *loader.o(.text)
        *rpi2.o(.text)
        *serial.o(.text)
        *util.o(EXCLUDE_FILE(*instr_util.o).text)
        *gdb.o(.text)
        *(.text)
    } >EXEC AT>LOAD

(From my rpi_stub)

 Here the code is loaded to memory region LOAD, where most of the code is copied to memory region EXEC and run there. The copyer part of the program is not in this section.

IF you load directly on RAM, then you define a memory section in RAM and link the code there. Then you don't need the load address. It's just that restarting may not work. 🙂

MikeDB
Lead

Thanks for your help. I'll read up on those things, then try to find out where in STM32CubeIDE to use them 🙂

I'm using 'H750s which have lots of RAM but limited flash. Intention is I hold programs in a memory card so the H750 flash will just have the boot code and memory card reader and that will load the program from the memory card directly to RAM and then pass execution to it. If there's a reset it could probably check if the RAM image is still intact and if so just jump to it again without reloading but that's for the future.