2025-01-11 11:16 AM - last edited on 2025-01-13 10:29 AM by Andrew Neil
Hi community, I´m using an STM32F411RE with which I plan to create a custom bootloader with specific functions located on sector 7 of flash memory. These functions will read the data stored in an external EEPROM that contains a .hex file, which should then be read and written to address sector 0 of the flash memory. Once this is completed, the new program will be executed. (Perhaps it may be better to switch up the sectors?)
In other words, the idea is to update the STM32 firmware whenever there is a new update by querying a webpage, which will then respond to the STM32 and send the .hex file to be stored in the external EEPROM. The STM32 will enter bootloader mode once all data has been sent, load the new firmware into the flash memory, and execute the new program. I’ve attached an image to reinforce the idea.
2025-01-11 12:07 PM
Ok, and what's stopping you in doing this?
Perhaps break this down and implement the pieces, the read/write of the internal flash, the read/write of the EEPROM. Look at how you want to transfer the data, over serial, common protocols like X/Y-Modem, something with it's own flow control and error checking etc.
I'd probably use sector zero as the boot, as that's where the MCU expects to find the first code.
2025-01-13 09:28 AM
Ok thanks for your response @Tesla DeLorean, my main question was if the idea was feasible to begin with. I'm a beginner using the bootloader and the eeprom, so i was looking videos about how to use a custom bootloader because the videos that i watch always use the default bootloader (the one accessed by the boot0 pin), i agree with you that a bootloader on sector zero is the best idea so based on your experience and knowledge do you know where I could find information about how to create a custom bootloader. Please and thank you.
Kind regards.
2025-01-13 10:28 AM - edited 2025-01-13 10:30 AM
As a beginner, start with smaller incremental goals.
Is it possible, yes in the broad sense, you can stage updates in EEPROM or QSPI NOR FLASH, and then subsequently apply them to Internal Flash
Can you probe the web? Not directly, but an app on the PC could, or something running on the STM32 with access to WiFi, Cellular, etc, could send an HTTP type request, or access an FTP server.
One could send a .HEX over a serial link to an STM32, you'd need to process and decode that, and pace the ingestion as the Internal Flash Erase and Write are slow and blocking, so you'd need some flow control to prevent data loss. Perhaps use a protocol that accomodates that directly.
Perhaps look to ST's IAP examples (In Application Programming)
The ISP (In System Programming) via the System Loader has a method to move binary data into memory. The USART protocol is described here, you could code a PC side app to implement this.
2025-01-13 09:24 PM - edited 2025-01-20 06:51 PM
Are you looking for a firmware plan?
You might need two STM32 programs or firmware staff to implement IAP and OTA for STM32, the bootloader and the main application.
You could issue an update action either in the bootloader or in your main application.
Issue update in your bootloader:
Powerup -> Bootloader -> Main app -> any update ? No -> Stay in Main app and do your things.
Yes -> Set update flag -> reboot to bootloader -> get firmware package and save in NV memory -> Success? No, try again.
Yes -> Clear update flag and set new main app jump address. Then reboot and jump to main app.
Perform Update in your main app:
Powerup -> Bootloader -> Main app -> any update ? No -> Stay in Main app and do your things.
Yes -> get firmware package and save in NV memory -> Success? No, try again.
Yes -> set new jump address and reboot
In both way, you need to determine whether the main app is in good health in bootloader stage. If the target main app is corrupted, then go brick rescue.
You might consider the data security and integrity of the firmware transferred. Additional, some memory area in RAM may need to be set non-initialized to maintain information while reboot.
Also it is recommended to keep a brick rescue area with read-only option whenever the main app firmware updated is corrupted.
2025-01-17 03:58 PM
Hello @Tesla DeLorean I've been working on what you told me and there's just one roadblock that I've found.
Your suggestion of using the web is very close to what I intend to do, we are using a SIM7600 to send HTTP Requests to our webpage and it displays it in real time. Although my main concern is how to "download" the .hex and then transfer it to the memory, I've been trying to think of a solution but nothings has come about, using a FTP Server is a good idea since the SIM7600 has SD interface and so does the STM32F411RE and I thought about them sharing an SD Card to save the files and update from there but I don't want to add another port that the user has to interact with (installing the sd card) and the sizes are way too big for what I want to do, and downloading a file gets me confused because if I download a file to the internal memory of the SIM7600 it then has to be send through the UART and all the Hex values are then converted to ASCII Characters so we end up having to redirect processing power to translating them into HEX values.
Would you be so kind to help me with a solution for this connundrum that has given me many sleepless nigths? What would you do if you had to save the file to the EEPROM? I'm not against using another form of Storage as long as it's cheap and soldered.
Thank you in advance.
2025-01-17 04:34 PM - edited 2025-01-17 04:36 PM
Kindness is not quite a right word in this case, don't you think? ))