STM32F20x custom bootloader
Hi Everyone!
I am writing a custom bootloader for STM32F207ZGT6. I divided the 1 Mb flash into 2 sections. The first one is 128 kbytes, my bootloader is loaded to this section. The second one is 896 kbytes, my main application is loaded here. I use the following code to the jump:
typedef void (*pFunction)(void); pFunction Jump_To_Application; uint32_t JumpAddress; . . . JumpAddress = 0x08020000 + 4; Jump_To_Application = (pFunction) JumpAddress; __set_MSP(0x20000000); Jump_To_Application();
I pasted the "+ 4" to the code because of endianness, but I may be wrong. My main application starts from 0x08020000. I set this in uVision. I ran to the following problem: When the Jump_To_Application() function is called, a HardFault is generated and its handler is called.
Anyone has a tip?
I am all ears.
I completely forgot one more thing: of course, the calculated address of the entry point should be compatible with the type of the function argument. I should have used int everywhere: it's shorter and it does the job:
((void (*)(int))(1+(int)launch_fw_code))(FW_START);
It's kind of misleading to pass a pointer to code as an int. But making it a pointer to a function would not clear things up much: we still would have to do some type casting in order to add 1 to the address. It's still a mess.
Hi Mike,
Many thanks for your explanation.
(I regularly discover that, I am not a good C programmer.)
(1+launch_fw_code) == &launch_fw_code[1]