I'm writing a second bootloader and I'd like to use a magic number to decide if staying in bootloader or running application. Something similar to this:
#include <cr_section_macros.h>
#define START_APPLICATION_MAGIC 0x4C514400
static __NOINIT_DEF uint32_t start_application;
if (start_application == START_APPLICATION_MAGIG) {
run_application();
} else {
/* Stay in the bootloader and waits for new application image
* to write in the Flash. After... */
start_application = START_APPLICATION_MAGIC;
NVIC_SystemReset();
}
Of course, start_application variable shouldn't be zeroed at reset and during startup code. I already used this tecnique in other applications.
Now, the linker puts start_application at address 0x2000149C and it is marked as .noinit in the map file. However it doesn't work.
If I put a break point on NVIC_SystemReset() instruction, I can see the magic number in start_application variable. When I proceed I stop the execution with another breakpoint in ResetISR(), before initializing bss and data sections. Now I see 0 at address 0x2000149C.
I tried to investigate deeper and I noticed all the address starting from 0x20001000 are zero at startup, while previous addresses (4kB) maintain values before reset.
Why this behaviour? I can't understand. The only reason for this could reside in the bootloader in ROM that should always start. However I don't know how much SRAM it uses and where.