Skip to main content
bhargavi ale
Associate II
May 7, 2018
Question

How to divide RAM into 2 sections in stm32f4

  • May 7, 2018
  • 1 reply
  • 1729 views
Posted on May 07, 2018 at 15:37

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> FLASH

In startup code, I have added few instructions to initialize new global variables to 0.

movs r1, #0

b LoopCopyDataInit

b LoopCopyUserDataInit

CopyDataInit:

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 FillZerobss

CopyUserDataInit:

ldr r7, =_sdata_user

ldr r7, [r7, r5]

str r7, [r4, r5]

adds r5, r5, #4

LoopCopyUserDataInit:

ldr r4, =_sdata_user

ldr r7, =_edata_user

adds r6, r4, r5

cmp r6, r7

bcc CopyUserDataInit

ldr r6, =_sdata_user

bcc LoopFillZeroUserData

FillZeroUserbss:

movs r7, #0

str r7, [r6], #4

LoopFillZeroUserData:

ldr r7, = _edata_user

cmp r6, r7

bcc FillZeroUserbss

In .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.

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    May 7, 2018
    Posted on May 07, 2018 at 15:44

    You'll need to step through your assembler code find any bugs or issues with that. The code pasted here has lost all formatting.

    The .MAP file will describe where the linker placed your assorted variables.

    Not sure how the system would know which values you want to be persistent over a reset, those you'd likely need to direct to a NOLOAD/NOINIT type section, and not have your initialization routines touch.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    bhargavi ale
    Associate II
    May 11, 2018
    Posted on May 11, 2018 at 07:19

     ,

     ,

    Thanks for reply clive one.

    After I changed code like below in startup file, new global

    variables started working fine as a normal global variables.

    movs r1, ♯ 0

    b LoopCopyDataInit

    CopyDataInit:

    ldr r3, =_sidata

    ldr r3,

    str r3,

    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, , ♯ 4

    LoopFillZerobss:

    ldr r3, = _ebss

    cmp r2, r3

    bcc FillZerobss

    movs r1, ♯ 0

    b LoopCopyUserRamDataInit

    CopyUserRamDataInit:

    ldr r3, =_siuserdata

    ldr r3,

    str r3,

    adds r1, r1, ♯ 4

    LoopCopyUserRamDataInit:

    ldr r0, =_suser_data

    ldr r3, =_euser_data

    adds r2, r0, r1

    cmp r2, r3

    bcc CopyUserRamDataInit.

    And I need one more help i.e., have moved total *(.text) from .text section

    of flash to user section (it is created by my own) of flash. Now, I want to

    move few static library functions to .text section of flash. I know we can

    move *.o files to particular section by exclude in user section of flash

    and include in .text section, but I want to move only static library

    fuctions.

    Ex: example functions are memset, __sinit &, etc...

    Can you help me out to move those functions?

    Regards,

    Bhargavi Ale.

    On Mon, May 7, 2018 at 7:15 PM, Clive One <,st-microelectronics@jiveon.com>,

    Tesla DeLorean
    Guru
    May 11, 2018
    Posted on May 11, 2018 at 07:46

    Perhaps you can:

    Identify objects within a library

    Have the tool generate 'One ELF Section per Function'

    Use attribute to name section for function(s)

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..