2016-10-09 05:21 AM
Hi
I am trying to write a custom bootloader for the STM32F030XX to upload a firmware through a wirless module (NRF24L01). I already wrote some code handling the upload but I am stuck at how to manage bootloader and user code startup. I am no expert in this so please excuse any wrong assumptions.What I want to do is decide which program to run bootloader or user code at the reset handler entry point. What I already did at an earlier project is to have the reset hanlder start the bootloader stored in ROM if a magic key is set in RAM. I would like to do something similar. After the bootloader successfully writes the user code into flash I just want to invalidate the magic Key and reboot into the normal user program.I imagine running the bootloader is like having two different programs in the flash memory at different starting locations and just needing to decide which one to run. So far I do understand what I am doing but now I think I need to modify the linker script to privide the addresses of these entry points.The default linker script provides the flash address called '_sidata = __etext;' (I am using Coocox)which is referenced in the assembler startup code.How can I modify the linker script (as well as the startup code) so the code can load both programs (user code and bootloader)? Should I just use hardcoded addresses? What would the startup code look like?Or is there a better way to do this? I did not find any good example of this. #bootloader #stm32f0 #startup-cod2016-10-09 06:52 AM
I did not find any good example of this.
ST has a number of IAP examples for the loader/app configuration on the F0. I know I've covered it a bunch of times here on the forum. In the linker script you just need to change the FLASH region, advancing the address and shrinking size for the app, and constraining the size for the loader. The address of the statics and the startup code reading those addresses is solved by the linker. The biggest issue on the Cortex-M0 is remapping the vector table because it no longer uses a register to do this, and you must copy the new table into the base of RAM so it can be mapped/shadowed at address zero.2016-10-09 12:59 PM
Hi Clive
thank you for all the work you put into this forum, your answers helped me out a lot in the past!I did read some of the entries in the forum and also looked at the IAP example from ST but was still confused about the memory layout.Back to my problem: it turns out I had the wrong idea on how this should work. It is actually simpler than I thought but I still can't figure it out.I found some examples that re-map the vector table in the user code but I would like to do this in the bootloader. Could this be done in the startup code i.e. just after the reset handler? The reset handler already checks for a magic key in ram I usually use to jump to the built in UART bootloader. Since the startup code is in assembler this may be more trouble than it is worth. Or do you have an example for this already?Is there any precaution measures to be taken when doing it in the main program of the bootloader, before jumping to the user code? I am thinking clock settings and interrupt stuff that may be initialized in the startup code.2016-10-24 09:31 AM
The open source OpenBLT bootloader has support for the STM32F0 family of microcontrollers, including a demo for the STM32F0-Discovery board.
Perhaps you can use it as a reference to determine how to do the vector table remapping etc.More info at https://www.feaser.com/openblt/-Frank