2017-12-04 01:55 AM
I am working with the stm32f7 microcontroller and I have 2 projects, a bootloader project and an application project. The bootloader resides in the beginning of the flash memory and the application resides in the end. If I want to switch execution from application to bootloader or vice versa with a goto-statement to the other project's main-function, what registers (stack pointer, program counter, etc?) do I need to change to ensure correct execution?
2017-12-04 05:19 AM
You can't just change context, the firmwares are built with different RAM utilization as fixed by the linker. ie variables in completely different locations.
You need to transfer control through the SP and PC described in the vector table for the Reset_Handler entry point.
2017-12-04 06:32 AM
No variables are shared between the 2 projects and each of the projects initializes all modules (GPIO-pins, clocks, timers, UART:s, etc) it needs, in its main-function. I don't want to do a software reset because it also resets the USB-module and that means that the USB-connection to the PC (the PC performing the firmware upgrade) will be lost and there's a need to reconnect, which could be slow if the PC has a hard time finding the correct driver.
2017-12-04 08:46 AM
Then carry a flag across in a RAM location that isn't used to flag it should reinitialize USB, etc.
The C run time code initializes the statics before calling main(), so random entry can have risks that variables are initialized as expected. See how qsort() passes functions, review IAP examples.
If you really want to jump into arbitrary code, set up a function pointer with the address and use that to call the code you want.
Perhaps think about how you want to transfer control and pass information, and why it is desirable to ping back and forth.
2017-12-05 03:33 AM
It is fairly easy to pass information between the 2 projects, in the linker script I specify that the RAM is 511 kilobyte instead of 512 and then the last kilobyte will remain untouched at all times (even if doing a software reset).
If I used the function pointer approach, wouldn't I eventually get stack overflow if I keep switching back and forth between application and bootloader enough times? Wouldn't it be kind of like recursive function calling?