This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

gcc_startup_nrf51.S does not zero-fill bss nrf51822

So if I start a program in debug mode some zero-inited static variables are non-zero.

    ldr    r1, =__etext
    ldr    r2, =__data_start__
    ldr    r3, =__data_end__

    subs    r3, r2
    ble     .LC0

.LC1:
    subs    r3, 4
    ldr    r0, [r1,r3]
    str    r0, [r2,r3]
    bgt    .LC1
.LC0:
  • That code's not the place that bss is initialized, the code you quote is where initialised data is copied into memory, data which is initialised with something other than zero. BSS is zeroed in the standard _start() function linked by gcc. It's defined in newlib/newlib/libc/sys/arm/crt0.S in the gcc distribution, although those files are so ifdef'ed and preprocessed they are somewhat hard to read. It's near the start of start however and is easy to find, just sets the start address into r0, #0 into r1 and bss_end - bss_start into r2 and calls memset.

    So if your static variables aren't initialised, you have a different problem. Single stepping into _start should show you where the BSS zero is done.

  • Thanks, the gcc_startup_nrf51.S file from micro ESB example called main after system init, but not _start. I took file from SDK 9.0.0 and now it's ok.

Related