I have an application executing out of FLASH memory however I need some of it to execute out of RAM. How can I do this?
Usually the easiest way to do this is to put the code you want to execute from RAM into the .fast section as on most targets the .fast section is placed into RAM using the default memory placement files. Using a FLASH configuration the .fast section will be loaded into FLASH and copied out of FLASH into RAM by the default startup code before entering the main function.
If you want to be less selective and want to put an entire section or indeed everything in RAM then you will need to modify the section placement file (usually flash_placement.xml for FLASH build configurations) and for each FLASH section you want to run in RAM:
- Create a section in a RAM segment that indicates where you want to the FLASH section to run.
- Modify the Section To Run In property of the FLASH section to be the name of the section in RAM you want the FLASH section to run in. Note that the order of the load sections in the FLASH segment must match the order of the run section in the RAM segment or you will get a cyclic memory section dependency error.
The crt0.s startup code will automatically copy the .data, .text, .fast, .ctors, .dtors and .rodata sections if it detects the load and run addresses are different. If you want any other sections to be copied into RAM on startup you will need to modify the crt0.s file to do this.
Note that we ship two example placement files:
- $(StudioDir)/targets/flash_run_all_from_ram_placment.xml - Everything runs from RAM
- $(StudioDir)/targets/flash_run_text_from_ram_placment.xml - The .text section (code) runs from RAM
If you are using the $(StudioDir)/targets/flash_placement.xml section placement file in your project you should be able to directly replace this with either of these files. To do this:
- Right click on the System Files folder in your project and select Add Existing File and select one of the two placement files.
- Right click on the file you've just added and select Properties
- Set the Configuration to RAM and set the Build Options > Exclude From Build property to Yes
- Right click on the existing flash_placement.xml file in the project explorer and select Remove.
- Rebuild your project.
If you aren't using $(StudioDir)/targets/flash_placement.xml, which maybe the case if you have multiple RAM and FLASH segments, you will need to modify your placement file as described above.
Please sign in to leave a comment.