2

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?

Peter Mortensen
31.3k22 gold badges110 silver badges134 bronze badges
asked Nov 21, 2024 at 7:48
2
  • You probably do not link using this linker script. Check your build system. Commented 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? Commented Nov 24, 2024 at 5:22

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.