I want to copy the flash code into the ram ,but I am not familiar with the steps,could you give me some advice about how to achive my goal?
Qiuchi
2017/12/29
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I want to copy the flash code into the ram ,but I am not familiar with the steps,could you give me some advice about how to achive my goal?
Qiuchi
2017/12/29
Hello Qiu,
1. Define the memory location for flash API in cmd file
For example: FLASH_API (RX) : origin=0x00000020 length=0x000014E0
2. Define the section for flash API in cmd file
For example:
/* creates an output section named flashAPI */
/* Load the code to FLASH_API (defined in memory{} */
/* Run the code in SRAM */
/* The value of the symbol api_load is the starting load address */
/* The value of api_run is the starting run address */
flashAPI :
{
Fapi_UserDefinedFunctions.obj (.text)
flash_operation.obj (.text) /* your flash erase/program/read etc obj files*/
--library= ..\..\..\lib\F021_API_CortexR4_BE.lib (.text)
} load = FLASH_API, run = SRAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)
3. Define a function to copy flashAPI section to SRAM (assembly code)
For example:
;-------------------------------------------------------------------------------
;
; Copy the Flash API from flash to SRAM.
;
.def _copyAPI2RAM_
.asmfunc
_copyAPI2RAM_
.ref api_load
flash_load .word api_load
.ref api_run
flash_run .word api_run
.ref api_size
flash_size .word api_size
ldr r0, flash_load
ldr r1, flash_run
ldr r2, flash_size
add r2, r1, r2
copy_loop1:
ldr r3, [r0], #4
str r3, [r1], #4
cmp r1, r2
blt copy_loop1
bx lr
.endasmfunc
3. Call the function in your main()
For example:
_copyAPI2RAM_();