-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Description
I need to create a region of RAM that is not initialised at power-on (to contain logging data that must survive across a reset). I can do this with GCC_ARM
and IAR
but have completed failed to make it work with ARM
toolchain. Could the merge process to bring together APP and non-APP images be somehow affecting the way my image is being initialised?
I have made my own scatter-link file region, marked as UNINIT
, and, in my __attribute__
call, I am specifying that this is zero_init
RAM (otherwise I'm told that the ARM linker thinks it is Data
RAM and zero-initialises it no matter what you say). For my test code below the .map
file shows that the linker is putting my test variable into the correct region:
Execution Region RW_IRAM1 (Base: 0x200032ac, Size: 0x00000004, Max: 0x00000400, ABSOLUTE, UNINIT)
Base Addr Size Type Attr Idx E Section Name Object
0x200032ac 0x00000004 Zero RW 8 .bss.noinit main.o
Yet with this test code:
#include "mbed.h"
// An unsigned int in an uninitialised RAM area
__attribute__ ((section(".bss.noinit"), zero_init))
unsigned int gRetained;
// Entry point
int main()
{
printf("Retained RAM variable is %d.\n", gRetained);
gRetained++;
printf("Retained RAM variable incremented to %d.\n", gRetained);
printf("Resetting...\n");
wait_ms(1000);
NVIC_SystemReset();
}
...the output I get is:
Retained RAM variable is 0.
Retained RAM variable incremented to 1.
Resetting...
Retained RAM variable is 0.
Retained RAM variable incremented to 1.
Resetting...
Retained RAM variable is 0.
...
If I use GCC_ARM
instead (where the .ld
file already has a noinit
section and the attribute
becomes __attribute__ ((section(".noinit")))
), I get the expected:
Retained RAM variable is 0.
Retained RAM variable incremented to 1.
Resetting...
Retained RAM variable is 1.
Retained RAM variable incremented to 2.
Resetting...
Retained RAM variable is 2.
...
Here is my scatter-link file in full where RW_IRAM1
is the region I'm talking about:
#! 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 0xDC
#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)
}
}
This is on an NRF52832
target (UBLOX_EVK_NINA_B1
). ARMCC
version is 5.06 update 6 (build 750). mbed-os version is 40e9f41b4
"Merge pull request #7821 from klaas019/master".
Issue request type
[x] Question
[ ] Enhancement
[ ] Bug