How to read and write to memory

I ordered a Electron, I still struggle to understand how the writing, flashing, reading from the flash memory works. As far as I understand, the Electron is a ST microcontroller and I can use JTAG debug the device.

How does one usually read or write to the device?

Firmware is flashed either using us or over the air. Is that what you were asking about?

Firmware is split into three parts:

  • Bootloader
  • System firmware (Particle Device OS)
  • User firmware

All three parts can be flashed individually by:

  • Over-the-air (cellular for the Electron)
  • USB

In most cases, users work at a higher level only updating their user firmware based on the Particle APIs and selected STM32 APIs which are sufficient for most uses.

It’s possible to program it as a raw STM32 device, but while possible, isn’t a supported use case and will involve some experimentation to get it to work.

Thank you for your answer. Is it also supported to read Bootloader, System firmware and user firmware via Particle APIs or STM32 APIs?

You can read out the firmware binaries by USB (using dfu-util) or JTAG/SWD off-device.

On the device itself, the STM32 memory maps flash and uses XIP (execute-in-place) so you can read out the flash just by access it as memory. The memory maps are in the datasheet.

1 Like

Thank you, @rickkas7. Therefore it suppose it is in theory possible to flash a modified version of the system firmware and bootloader, right?

System firmware can be flashed by USB (–dfu or --serial), JTAG/SWD, or OTA. If you are taking the Particle system firmware, building locally and using the --program-dfu option is usually the easiest because it’s done right out of the makefiles.

Building a bootloader is also possible using the local toolchain. That can only be flashed in USB serial (–serial) mode, OTA, or JTAG/SWD. The reason is that DFU mode runs out of the bootloader, and since the STM32 does XIP, DFU mode cannot replace the bootloader because the code is running out of the bootloader.