Bootloader Hardfault on App Entry. Is my application program configured correctly?
- November 4, 2018
- 5 replies
- 3975 views
Hi all,
I'm currently working on a bootloader for the STM32L052 MCU. I have a very simple bootlader at this early stage in the development. I have a simple application program that consists of a flashing LED, it compiles to a 4KB .bin file. I then convert this bin file to a uint8_t array to store in the RAM of the bootloader so I can simply test the writing of the program into flash without developing a UART protocol etc. The final version will be using NFC to download the code.
I have the bootlader program starting at 0x0800 0000 in the FLASH and the application at 0x0800 F000. The bootloader simply writes the array into this location of memory, then sets the MSP to the first 32bit work of the application address and casts the second word as a function and calls it to launch the application. I have used the AN4657 as reference.
However when the application is launched, I get a Hard Fault exception. I think this is due to the way I have the application project setup or perhaps the way I have converted the .bin to a uint8_t array. First, if I run the application directly on the processor the first debug point isn't at the start of the program, but at an offset. I assume this is the startup code. Also, the first work of the bin file isn't the correct value for the stack pointer. In the bin file it's 0x0200 0200 but it should be 0x2000 2000 for my 8KB of RAM.
Attached are my bootloader source files. Could anyone give me some pointers on how I should configure my application project? Should the FLASH start and end be different? Things like that.
Thanks!
