This is far from the first time I’ve done an STM32 bootloader, but I’m having funky things going on with one for the STM32F107VC.
All compiles and runs fine when running from 0x8000000, but as soon as I relocate the code to 0x8003000 it falls over. To explain what I’ve done:
I’m using Rowley Crossworks and you can move the program around flash very easily by using this Section Placement Macro:
I’ve done it many times in different projects. I can recompile with different flash start addresses and the debugger happily shows you it running from wherever you’ve located it. Both with run-to-complete and FreeRTOS projects this has been fine.
However, when running the STM32F107VC demo that I have modified, it will not work. If I program the device from the debugger or if I run the bootloader and have the bootloader load the new image in at the relocated start point.
I’m getting to here:
static void prvPortStartFirstTask( void )
Whic is assembler:
ldr r0, 0x0800A064 <prvPortStartFirstTask+0x18> [r0 contains 0xe000ed08, location 0xe000ed08 contains 0]
ldr r0, [r0] [Now r0 contains 0, location 0 contains 0xFFFFFFFF]
ldr r0, [r0] [Now r0 conatains 0xFFFFFFFF]
msr msp, r0 [MSP contains 0xfffffffc (!)]
After the svc instruction the program leaps off to 0xfffffffe
I am assuming this is why it’s not running.
If I run the bootloader itself (a stripped down FreeRTOS), when I get to the part that jumps to the application:
volatile unsigned long JumpAddress; SysTick_CounterCmd(SysTick_Counter_Disable); SCB_VTOR = (unsigned long)0x8008000; JumpAddress = *(volatile unsigned long*) (0x8008000 + 4); Jump_To_Application = (pFunction) JumpAddress; Jump_To_Application();
The Jump_To_Application assembly is as follows:
ldr r3, 0x08006AC8 <JumpToNormalApplication+0x3C> [0x08006AC8 contains 0x200079a4]
ldr r3, [r3] [0x200079a4 contains 0x0800828d]
blx r3 [ And so it jumps to 0x0800828d, which is now where it should go!]
So, is this enough information to poke me in the right direction or be able to tell what on earth is going on/wrong?