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

Error in startup for GCC (FIXED)

Hi

I've detected that when using the NRF51822 under Eclipse and GCC compilers, global variables are not automatically initialized. This is because an error on the startup file provided by Nordic for GCC environments (not IAR). I'm surprised nobody has commented about this problem on this forum, but I guess about all people is working with IAR or Keil environments.

The problems is because BSS memory zone is not being initialized in the startup file. As I understand, the DATA memory zone is reserved for variables initialized to some value different to zero (NULL), but BSS memory zone is reserved for variables initialized to zero value.

While the startup file initializes the DATA memory variables (variables different than zero), the BSS is not being initialized. This is a problem when trying to use a global variable that should be initialized to zero, but not. I've detected for example bool variables initialized to non legal values, such as 12. It is clear this is a problem. FreeRTOS for example is not able to be initialized due to these problems.

To fix this problem, it is necessary to add the following lines to the gcc_startup_nrf51.s file, line 163:

    	/* data section */
    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:
    
    **/* bss section */
    ldr		r2, =__bss_start__
    ldr 	r3, =__bss_end__
    ldr		r0, =0x00
	subs	r3, r2
	ble		.BS0

.BS1:
	subs	r3, 4
	str     r0, [r2,r3]
	bgt		.BS1
.BS0:

    LDR     R0, =SystemInit
    BLX     R0
    LDR     R0, =main
    BX      R0**

The BSS initializing section has been added under the symbol .LC0, and before SystemInit.

I hope you find this helpful.

Regards,

Elena

Parents
  • No that shouldn't go in the startup file because initialising the bss is something the standard gcc _start method does, that's in the gcc crt0 file which gcc automatically links into every binary even though it's not specified on the command line and is called after the startup you were just editing. It's this file

    lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv6-m/crt0.o

    for the nrf51822, or one similarly named, changes a bit depending on the library option.

    So the reason nobody has commented on it before it because it's not an issue, the BSS is correctly zero-initialised by the standard gcc-linked startup crt0.

    If yours isn't being, I suggest you check your map file and check the binary to see what _start is being linked in. In the one I'm looking at the BSS is initialised 0x18 bytes into the _start routine.

  • I know you're right, but becase there is no complete GCC examples provided by Nordic, and because I tested it what you say and I didn't get it to work, I don't see any other solution at the moment. By the way, thanks for your help and interest.

Reply Children
No Data
Related