Hi all,
I am using gcc for my Nordic project and I wanted to add the bootloader. After some reading and experimenting the bootloader worked. Now I thought of making a release build using -Os for optimization. The bootloader stopped working sadly. After some debugging I traced it down to StartApplication in bootloader_util_gcc.c This function calls the application in Flash using inline assembly. Looking at this function it was not that strange it dit not work. The parameter start_addr was not used and thus optimized out. So r0 has a undefined value. I personally don't understand how and why it can work by other people who are using this code. I fixed this problem by using the parameters the function is giving me.
static inline void StartApplication(uint32_t start_addr)
{
asm volatile(
"LDR R2, [%0]\t\n"
"MSR MSP, R2\t\n"
"LDR R3, [%0, #0x00000004]\t\n"
"BX R3\t\n"
:
: "l" (start_addr)
: "r3", "r2"
);
}
Now everything it working perfectly :-)
Another thing I am very surprised of is the use of m_uicr_bootloader_start_address. Because this constant is nowhere used and it is also optimized out and thus the hex file does not contain the bootloader start address for the UICR register (0x10001014). To solve this problem I use now:
volatile const uint32_t m_uicr_bootloader_start_address __attribute__ ((section(".uicrBootStartAddress"))) = BOOTLOADER_REGION_START;
Hope this helps other people and I hope Nordic will fix this in their new SDK.
Regards, Marcel