Flashing user firmware on Electron from SD card

Hi. I don’t think this question has been asked. Sorry if I missed it.
I have created a shield pcb for the Electron. It contains a microSD card capability run off the SPI lines of the Electron and using standard FAT file storage.
I would like to write a user firmware file (say user.bin) to the SD card from my PC. Then I want to insert it in the shield and activate the boot loader to read the file and reflash user code.
Is this feasible? I know technically it is but are the hooks into the boot loader there so that I can do it? If anyone has ideas or a solution I would be heaps appreciative.


Really good question and I would like to see you make this work out.

Good luck!

Anyone out there? All is quiet.
I extracted this from the documentation on the bootloader.
Over The Air Mode (aka OTA Mode):
This mode is very similar to the factory reset mode. Upon detecting that the OTA_UPDATE_MODE flag is true, the bootloader takes a back up of the current firmware to EXTERNAL_FLASH_BKP_ADDRESS and the copies the firmware from EXTERNAL_FLASH_OTA_ADDRESS to the internal flash memory of the STM32.
It seems that if I can write my bin file to the OTA firmware area and then activate the bootloader it will happen. Is this possible? Anyone with any ideas at all?

That might be something for @jvanier to answer :wink:

Thanks for the ping. This is an interesting idea! I don’t think anybody has explored this option.

For the Electron you’ll need to look at INTERNAL_FLASH_OTA_ADDRESS since it doesn’t have external flash. I don’t know enough details about the OTA flash process to give better guidance in this area.

Another idea would be to adapt the YMODEM flash code to your use case. This is used to update the user application over a serial connection while the device is in listening mode (i.e. without DFU).

So instead of receiving bytes from serial, receive bytes from the SD card.

If you could turn that into a library it would be great!


Thanks for that, I am sure I will be back with questions but it is a start.


@jvanier Just taking up your suggestion I have downloaded the YModem flash code and see that it establishes a YMODEM class which is largely irrelevant to what I want to do, although a guide. However the last call in the YMODEM cpp file is
bool Ymodem_Serial_Flash_Update(Stream serialObj, FileTransfer::Descriptor& file, void reserved)
and this seems to be the key. If I get the new fille into the format required by the FileTransfer class here and just call this function then I am sorted. Is it as simple as this?

1 Like

You’re on the right track. These classes don’t have extensive documentation since they are not meant for external users, so you’ll definitely have to do dine reverse engineering of the required format.

1 Like

Please do share if and when you figure this out if your willing.

Are you only using the SD card for loading new firmware or are you also using that extra memory on the SD card for other data that your application uses?

Using an SD card like you for firmware updates + bitmap image storage sounds like a good thing for my application.

I have found no easy way to flash remotely the Electron + an extra memory chip that would hold the extra bitmap data.

Are you wanting to do this to save on the data usage when updating the firmware on the Electron?

My application will use the SD card for a number of things mainly data recording as the device is part of our data gathering system and I will keep a hard copy on site even though the main access is sending the data to an FTP server.
I have managed to get the SdFat library operational for my device https://github.com/greiman/SdFat-Particle and it would appear to give me the functionality I need there, still starting on the real application code. My plan is that a user could update the firmware by writing it to the SD card, inserting it and powering up. Certainly updating firmware OTA will be an option I will use but I am probably going to use my own SIM cards so I have not worked out yet if that is possible if I separate my device from the Particle SIM system.
I am happy to share the results when I get it going. I will probably chip away at the solution using the YMODEM ideas above for the next few weeks in between other jobs but it seems the most straightforward way to go at the moment.


@jvanier The YMODEM cpp file compiles for me without errors so that is a start. Can I assume that if I build it into a small application where I send the Electron a firmware file using Ymodem format that it should do a firmware change? Is this the basis for the serial flash function in the CLI or a separate function altogether? Thanks

I’m not sure what you are asking exactly. This is something you’ll have to experiment with to validate your assumptions as it’s not something we’ve ever done.

I was able to get this to work; it didn’t even require ymodem!


@rickkas7 That is amazing, I have yet to implement it but I believe you. Thanks, I will report back when I try it

@rickkas7 Rick, that firmware update from SD card works really well, thank you, tested your program then worked it into my own.
Thanks again


@rickkas7 Rick, does loading the system firmware using your marvelous program here need to be altered due to the changes in firmware 0.6.0?
[Electron] System parts reordered from 3,1,2 to 1,2,3 to preserve logical flashing order for OTA/YModem when upgrading. #1065

As long as you have 0.5.3 installed, you only need to put system1.bin, system2.bin and system3.bin on the SD card and it should work properly because I wrote the code expecting 0.6.0.

I think if you are upgrading from an earlier version you would need to upgrade to 0.5.3 first, because that version knows what to do with the 3rd Electron firmware part, even though it doesn’t use it.

1 Like