In the STM32F767ZI reference manual, the memory organization is divided into:
FLASH, SRAM1, SRAM2, ITCM and DTCM, but in the linker script, the project is either stored into FLASH or RAM. I want to edit the linker script, so I can store data in a specific memory region.
I am trying to change it from:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
}
To this:
MEMORY
{
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 16K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20020000, LENGTH = 368K
SRAM (xrw) : ORIGIN = 0x2007C000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
}
So I added in the sections this:
_sisram = LOADADDR(.sram);
.sram :
{
. = ALIGN(4);
_ssram = .; /* Create a global symbol at data start */
(.sram) / .data sections */
(.sram) /* .data* sections */
. = ALIGN(4);
_esram = .; /* Define a global symbol at data end */
} >SRAM AT> FLASH
_siitcm = LOADADDR(.itcm);
.itcm :
. = ALIGN(4);
_sitcm = .; /* Create a global symbol at data start */
(.itcm) / .data sections */
(.itcm) /* .data* sections */
. = ALIGN(4);
_eitcm = .; /* Define a global symbol at data end */
} >ITCMRAM AT> FLASH
_sidtcm = LOADADDR(.data);
.dtcm :
{
. = ALIGN(4);
_sdtcm = .; /* Create a global symbol at data start */
(.dtcm) / .data sections */
(.dtcm) /* .data* sections */
. = ALIGN(4);
_edtcm = .; /* Define a global symbol at data end */
} >DTCMRAM AT> FLASH
And then moved to the startup file.
First, I added the following:
.word _sisram
.word _ssram
.word _esram
.word _siitcm
.word _sitcm
.word _eitcm
.word _sidtcm
.word _sdtcm
.word _edtcm
And then the copy loop like this:
// SRAM
ldr r0, =_ssram
ldr r1, =_esram
ldr r2, =_sisram
movs r3, #0
b LoopCopySramInit
CopySramInit:
ldr r4, [r2, r3]
str r4, [r0, r3]
adds r3, r3, #4
LoopCopySramInit:
adds r4, r0, r3
cmp r4, r1
bcc CopySramInit
// ITCM
ldr r0, =_sitcm
ldr r1, =_eitcm
ldr r2, =_siitcm
movs r3, #0
b LoopCopyItcmInit
CopyItcmInit:
ldr r4, [r2, r3]
str r4, [r0, r3]
adds r3, r3, #4
LoopCopyItcmInit:
adds r4, r0, r3
cmp r4, r1
bcc CopyItcmInit
// DTCM
ldr r0, =_sdtcm
ldr r1, =_edtcm
ldr r2, =_sidtcm
movs r3, #0
b LoopCopyDtcmInit
CopyDtcmInit:
ldr r4, [r2, r3]
str r4, [r0, r3]
adds r3, r3, #4
LoopCopyDtcmInit:
adds r4, r0, r3
cmp r4, r1
bcc CopyDtcmInit
So I am basically copying what the mx did to the data section from flash memory to RAM, but when I run, I get this error:
undefined reference to `_ssram'
I tried to change it from .word to .extern, but still I get the same error.
What am I missing? Is there a better way to divide the RAM region to ITCM DTCM and RAM?
-
You probably do not link using this linker script. Check your build system.0___________– 0___________2024年11月21日 17:54:39 +00:00Commented Nov 21, 2024 at 17:54
-
@0___________ Thank you for the reply, I did choose this linker from project properties. unless their is something more I should do?Faisal129– Faisal1292024年11月24日 05:22:51 +00:00Commented Nov 24, 2024 at 5:22