STM Update
STM can update itself through OTA. It will flash itself through IAP and after verifying the flashed data, it will restart into the new application.
OTA has a few communication enums that can be passed into the Command message:
| Command | Parameter | Description |
|---|---|---|
Ota | OtaErase | Erases the flash and prepares for flashing |
Ota | ShowUpdatePopup | Shows the update popup that notifies the user that an update is underway |
Ota | Start | Tells the instrument that the update will follow |
OtaErase should be sent if the instrument returned 0 in the Ok after the OtaInfo packet.
If there are some packets present on the instrument, we should skip that many packets and continue from where it was last.
ShowUpdatePopup should be sent before a device starts updating and should be sent for both nRF and STM updates. The popup hides when the End is sent at the end of update.
OtaInfo contains a field overall_crc32, which should be compared with the last update that was done, so that we can track if there are some packets of this update already present or not.
OTA has a message called OTA with three fields:
| Field | Description |
|---|---|
seq_num | Number of the packet in the update procedure |
address | The location the bytes will be written to |
byte_array | The bytes to be written |
OTAInfo has a message called OTAInfo with three fields:
| Field | Description |
|---|---|
number_of_packets | Number of all packets in the update procedure |
overall_crc32 | CRC32 calculated over the whole binary |
firmware_version | Version of the new firmware |
OTA also reuses the global End command:
| Command | Parameter | Description |
|---|---|---|
End | Finish the update |
After the End command is sent, the STM verifies the flashed parts of the flash, switches to the new application and reboots.
If the overall checksum doesn't match, it returns N_OK and shows a popup, otherwise it returns OK and reboots.
Replies
Commands OtaErase, Start and End will reply with OK or N_OK commands depending on the status of the command that was executed last.