Variables in 'noinit' memory space, not starting as 0 . NRF52832

11 Nov 2018

Hi

Got a question around defining variables in 'noinit' ram location. I have defined a section with UNINIT using the following linker code (using the online compiler)..

#! armcc -E

/* Default to no softdevice */
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x0
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x80000
#endif

/* Physical RAM */
#define MBED_RAM_PHYSICAL_START 0x20000000
#define MBED_RAM_PHYSICAL_SIZE 0x10000

/* Reserved areas */
#define MBED_RAM_SOFT_DEVICE_SIZE 0x31d0
#define MBED_RAM_UNINIT_AREA_SIZE 1024

/* If app_start is 0, do not set aside space for the softdevice */
#if MBED_APP_START == 0
#define MBED_RAM_START  MBED_RAM_PHYSICAL_START
#define MBED_RAM_SIZE   MBED_RAM_PHYSICAL_SIZE
#else
#define MBED_RAM_START  (MBED_RAM_PHYSICAL_START + MBED_RAM_SOFT_DEVICE_SIZE)
#define MBED_RAM_SIZE   (MBED_RAM_PHYSICAL_SIZE - MBED_RAM_SOFT_DEVICE_SIZE)
#endif


#define MBED_RAM0_START MBED_RAM_START
#define MBED_RAM0_SIZE  0xE0

#define MBED_RAM1_START (MBED_RAM0_START + MBED_RAM0_SIZE)
#define MBED_RAM1_SIZE  MBED_RAM_UNINIT_AREA_SIZE

#define MBED_RAM2_START (MBED_RAM1_START + MBED_RAM1_SIZE)
#define MBED_RAM2_SIZE  (MBED_RAM_SIZE - MBED_RAM0_SIZE - MBED_RAM1_SIZE)


LR_IROM1 MBED_APP_START MBED_APP_SIZE {
	ER_IROM1 MBED_APP_START MBED_APP_SIZE {
		*.o (RESET, +First)
		*(InRoot$$Sections) 
		.ANY (+RO)
	}

	RW_IRAM0 MBED_RAM0_START UNINIT MBED_RAM0_SIZE { ;no init section
		*(*nvictable)
	}
	RW_IRAM1 MBED_RAM1_START UNINIT MBED_RAM1_SIZE { ;no init section
		*(*noinit)
	}
	RW_IRAM2 MBED_RAM2_START MBED_RAM2_SIZE {
		.ANY (+RW +ZI)
	}
}

and this program code

<<code>> static uint16_t myvar attribute((section("noinit"),zero_init)); <</code>

However, im confused that this variable does not start with a 0 value? Any ideas why it start with a value of 41779 ?

Is it just because the RAM is not zero initialized so its somewhat random?

Thanks

B

13 Nov 2018

If it were to init it, then it might init it when you don't want it to, so it leaves it up to you to decide when and how to initialize that ram.

A somewhat typical method is to create a checksum over the range of no-init data, and if the checksum does not compute, then you can assume it is a first-powerup (or horribly corrupt) and initialize it. Be sure to update the checksum if the data is modified.

14 Nov 2018

thanks