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