Hard fault on blx instruction - STM32F091CBU6
Hello everyone,
I am developing a simple bootloader application where I have the bootloader code located at 0x8000000 and the main firmware at 0x8008000.
To jump from the bootloader to the firmware code I am using this code:
typedef void (*pFunction)(void);
pFunction JumpToFirmware = (pFunction)(*(__IO uint32_t*)(0x8008000 + 4));
__disable_irq();
JumpToFirmware();
For some reason the jump is generating a hard fault, catch by the hardfault event handler. Since there is no fault registers in the Cortex-M0, it is being difficult to track the problem down.
The generated assembly code looks good at JumpToFirmware():
JumpToFirmware();
08002da4: blx r2
I checked and the r2 is correctly loaded with value 0x8008225 (read from the firmware vector table stored at 0x8008000), however blx causes the hard fault. I even tried to straight test with a asm(" blx 0x8008225"), which I believe would be a valid branch, but it still causes the fault.
I also check the target address 0x8008225 and it contains the correct startup code of the main firmware.
Is there something else that must be set before using the blx in this particular scenario?
Gabriel
