How to divide RAM into 2 sections in stm32f4
Hi All,
Am trying to fix the RAM addresses for new global variables in .data segment. For this, I have divided RAM into sections and by using attribute Am fixing address for newly created global variable. It was looks fine, but newly
added global variables are not initializing with default value i.e., 0 and it is persistent variables also getting affect i.e., after reset, persistent variables are initializing with zero instead of retaining the value.
I have created RAM sections like below,
In linker script:
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 120K
RAM2 (xrw) : ORIGIN = 0x20000000 + 120K, LENGTH = 8K.data :
{ . = ALIGN(4); _sdata = .; /* create a global symbol at data start */ *(.data) /* .data sections */ *(.data*) /* .data* sections */. = ALIGN(4);
_edata = .; /* define a global symbol at data end */ } >RAM AT> FLASH .data_user : { . = ALIGN(4); _sdata_user = .; /* create a global symbol at data start */ *(.data_user) /* .data sections */ *(.data_user*) /* .data* sections */. = ALIGN(4);
_edata_user = .; /* define a global symbol at data end */ } >RAM2 AT> FLASHIn startup code, I have added few instructions to initialize new global variables to 0.
movs r1, #0
b LoopCopyDataInit b LoopCopyUserDataInitCopyDataInit:
ldr r3, =_sidata ldr r3, [r3, r1] str r3, [r0, r1] adds r1, r1, #4 LoopCopyDataInit: ldr r0, =_sdata ldr r3, =_edata adds r2, r0, r1 cmp r2, r3 bcc CopyDataInit ldr r2, =_sbss b LoopFillZerobss/* Zero fill the bss segment. */ FillZerobss: movs r3, #0 str r3, [r2], #4 LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 bcc FillZerobssCopyUserDataInit:
ldr r7, =_sdata_user ldr r7, [r7, r5] str r7, [r4, r5] adds r5, r5, #4LoopCopyUserDataInit:
ldr r4, =_sdata_user ldr r7, =_edata_user adds r6, r4, r5 cmp r6, r7 bcc CopyUserDataInit ldr r6, =_sdata_user bcc LoopFillZeroUserDataFillZeroUserbss:
movs r7, #0 str r7, [r6], #4LoopFillZeroUserData:
ldr r7, = _edata_user cmp r6, r7 bcc FillZeroUserbssIn .c file:
__attribute__((section('.user_data'))) int DebugEx1 = 0; // new global variable.
RAM address for
DebugEx1 is came inside .user_data section but, facing above bugs.
Please, Help me out from this problem
regards,
Bhargavi Ale.