I have implemented bootloaders on the STM32F103 and F107 a number of times, but am struggling with a new one I have done using USB to download the new image when it has finished downloading the new image and is jumping from the bootloader section of the code to the new section.
I have set my software to be programmed by the bootloader to start at
0x08008000 by setting this in my Section Placement Macros:
This clearly sets the code to 0x08008000 and if I run this code from the debugger it runs just fine.
The bootloader itself is 25.5k; if I erase all, load the bootloader, I can see there is nothing at 0x08008000.
If I then run the bootloader and send the relocated code via USB, I can see the bootloader loads the relocated code at 0x08008000 and all looks good.
Once the code is all loader I call this:
volatile unsigned long JumpAddress;
SCB->VTOR = (unsigned long)APPLICATION_START_ADDRESS;
JumpAddress = *(volatile unsigned long*) (APPLICATION_START_ADDRESS + 4);
Jump_To_Application = (pFunction) JumpAddress;
APPLICATION_START_ADDRESS is set as follows in a header file:
#define APPLICATION_START_ADDRESS 0x8008000
However, when I jump into the code, I get partway through the the function in the startup code here:
/* Zero the bss. */
ldr r0, =__bss_start__
ldr r1, =__bss_end__
movs r2, #0
ldr r0, =__tbss_start__
ldr r1, =__tbss_end__
movs r2, #0
And it crashes.
Now, if I change this so that - once the bootloader has already loaded the code and does not try to run the bootloader code, but go straight to the new, relocated image, it seems to run OK.
I am, in both instances, running a FreeRTOS program. If I don't start the scheduler in the bootloader and jump to the relocated program, why would it not crash?
Can anyone think of what I can do so that I can seemlessly go from the bootloader, once it has loaded a new image, into the new image located up at 0x8008000 please? What am I missing here?