cancel
Showing results for 
Search instead for 
Did you mean: 

Need help to execute program from SRAM

tejas
Associate II
Posted on May 21, 2015 at 12:39

Hi, 

I want to execute my code from SRAM of STM32F100. 

I basically want to copy a program from flash to SRAM and execute the program from SRAM

Please help me understand how this can be addressed.

Regards 

Tejas

#flash #stm32f100 #sram
3 REPLIES 3
Posted on May 21, 2015 at 14:30

What's the stumbling block here? Building the code for a different address, or the copying part?

Assuming you have a part with 64KB of RAM, I'd split it in two halves, and have code in the ResetHandler to copy the body in RAM and then forking to it.

Have the linker build the Code portion for 0x20000000[0x8000] and the Data portion for 0x20008000[0x8000]. To make the flashing easier I'd probably need to rebase the .HEX file so the ST-LINK Utilities could deliver it, or just convert it to a .BIN and tell the tools explicitly where to write it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tejas
Associate II
Posted on May 27, 2015 at 09:24

Actually, I've not started coding on this section. I wanted to start with understanding on how to copy binary from flash to RAM and execute files from RAM.

 

My main aim is to copy the 'In application program' to RAM and execute the program from RAM so that I have a option to even re write entire flash.

fenugrec
Associate II
Posted on May 27, 2015 at 16:16

If you want to run the same code (i.e. the same binary image) loaded both at 0x2000 and 0x0800, you will need to generate ''position-independant code'', there are usually compiler options for that.

Or, what I would do is tweak the linker script to make it use a VMA of 0 and a LMA in flash (0x0800). In normal operation (run from flash), set the core to map the flash area @ 0. When you want to run from ram, you copy the whole image to RAM, change the memory mapping so RAM is mapped @ 0, and just keep going. ( Make sure you have enough RAM for both your stack and your code !)