cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Editing Linker Script

Faisal129
Associate

Hello everyone, I am using STM32F767ZI which in the reference manual has ITCM, DTCM, SRAM1 and SRAM2 
but in the linker script it is just RAM so 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 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 the same error. 

what am I missing ? is there a better way to divided the RAM region to ITCM DTCM and RAM ? 
Thank you for your time.
 

 

2 REPLIES 2
gbm
Lead III

Have you actually declared the data?

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Andrew Neil
Evangelist III