2021-12-16 02:09 AM
I am working with the STM32F446 microcontroller and compiling with Eclipse/GCC.
Short version: I have two functions, main1(int argc, char* argv[]) and main2(int argc, char* argv[]) and I want to be able to goto back and forth between the two many times. What do I need to do to ensure that this will always work properly? In particular, I'm concerned about the stack and the Core General Purpose Registers R0...R12. Will these be "confused" if they all of a sudden find themselves executing inside a different function or will it be just fine since I always goto the BEGINNING of the respective functions?
Long version: I need to make my own USB-bootloader (no, the built-in bootloader doesn't fit my needs) and I have two Eclipse projects, bootloader project at sectors 0-3 and application project at sectors 4-7. I need to somehow be able to switch between bootloader mode and application mode (and vice versa) without dropping the USB-connection (hence, I can't reset the microcontroller). If I switch between the two projects using function CALLS, then I'm afraid I will run of out stack in case someone switches back and forth many times, that's why I want to switch between the two using goto instead.
2021-12-16 06:17 AM
This would require that I lock all the USB-functions to specific addresses in flash, correct? So if I use the functions in stm32f4xx_ll_usb.c then I'd have to modify each function I actually use by adding an __attribute__ ((__section__(".XXXXXX"),used)) and then add the corresponding sections in the linker script, where the addresses of the sections would be specified?
2021-12-16 06:34 AM
Its a standard way for jumps between functions in C, see https://en.wikipedia.org/wiki/Setjmp.h. But, this is not aware of boot loaders/flash sectors etc. so it won't do the whole trick for you. Just the "C" way to unwind the call stack on the fly.
hth
KnarfB
2022-01-13 06:27 PM
Leave bootloader at the beginning of FLASH, ensure that it jumps to application, flash it and leave it there. The debugging for application will work. If necessary, make some special build of the bootloader for debugging purposes.