MCU Firmware Update

Last Updated on : 2024-06-04 07:44:12download

This topic describes how to update the MCU firmware over-the-air (OTA).

  • An over-the-air (OTA) update is the wireless delivery of new software, firmware, or other data to connected devices.

  • The cellular standard protocol supports OTA updates for the MCU. You can upload the update file to the Developer Platform. The cellular module can download the update from the server and send it to the MCU through the serial port. This way, the MCU gets the update and writes it to the local flash memory for installation. For more information, see Update Firmware and Select and Change the Firmware Version.

Processes

The OTA update consumes the memory of the MCU. After a device is paired, an OTA update can be initiated through the preset configuration or check for updates. Here is how the OTA update works:

ModuleMCUInitiate an MCU update.Return the maximum transmission unit.Send the first packet.Store the received firmware data and acknowledge the receipt within 5s.If the MCU fails to acknowledge the receipt within 5s, the module will resend the packet three times. If there is still no response, the update will fail.Send the nth packet.Acknowledge the receipt.Send the last packet.Verify the firmware, switch to the new firmware, and restart.ModuleMCU

Initiate update (0x0a)

The OTA update can be initiated automatically or manually.

  • For automatic updates, when the module detects MCU firmware updates from the cloud, the transmission of the update file automatically starts.
  • For manual updates, the module initiates updates only when updates are confirmed on the app.

The module sends the following data.

  • U: protocol version 0: 0x00

    Field Bytes Description
    Header 2 0x55aa
    Version 1 0x00
    Command 1 0x0a
    Data length 2 0x0004
    Data 4 The size of the update file in bytes. The data type is an unsigned integer, and the data is transmitted in big-endian format.
    Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

    For example, 0x55aa 00 0a 0004 00006800 75 indicates the size of the update file is 26624 bytes (26 KB).

  • U: protocol version 1: 0x01

    Field Bytes Description
    Header 2 0x55aa
    Version 1 0x01
    Command 1 0x0a
    Data length 2 0x004F
    Data 40
    • 4-byte update file. The data type is an unsigned integer, and the data is transmitted in big-endian format.
    • 32-byte MD5 hash.
    • 1-byte update channel.
    • 3-byte version number. For example, version 01.2.04 is 010204.
    Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x0a
Data length 2 0x0001
Data 1 The options for the maximum size of each packet:
  • 0x00: 256 bytes. It is the default value and is compatible with legacy firmware.
  • 0x01: 512 bytes.
  • 0x02: 1,024 bytes.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 0x55aa 03 0a 0001 00 0d

Transmit the updates (0x0b)

  • Data format:

    The update channel (for protocol version 1) + packet offset (unsigned short) + payload.

  • When the MCU receives a frame with a length of four bytes and the fragment offset is equal to or greater than the size of the firmware update, the transfer is completed.

  • For the last packet, the packet offset is the firmware size, and the packet length is 0 bytes.

The module sends the following data.

  • U: protocol version 0 (0x00):

    Field Bytes Description
    Header 2 0x55aa
    Version 1 0x00
    Command 1 0x0b
    Data length 2 The data length is the sum of 0x0004 and the packet length.
    Data 4 + N The first four bytes are fixed as packet offset, and the latter bytes are the actual data.
    Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.
  • U: protocol version 1 0x01:

    Field Bytes Description
    Header 2 0x55aa
    Version 1 0x01
    Command 1 0x0b
    Data length 2 The data length is the sum of 0x0005 and the packet length.
    Data 5 + N
    • Channel ID (1 byte)
    • Packet offset (4 bytes)
    • Payload (n bytes)
    Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Assume that the size of the update is 530 bytes, and the MCU does not need to respond to the last packet.

  • For the first packet, the packet offset is 0x00000000, and the packet length is 256 bytes. The module sends 0x55aa 00 0b 0104 00000000 xx…xx XX.
  • For the second packet, the packet offset is 0x00000100, and the packet length is 256 bytes. The module sends 0x55aa 00 0b 0104 00000100 xx…xx XX.
  • For the third packet, the packet offset is 0x00000200, and the packet length is 18 bytes. The module sends 0x55aa 00 0b 0016 00000200 xx…xx XX.
  • For the last packet, the packet offset is 0x00000212, and the packet length is 0 bytes. The module sends 0x55aa 00 0b 0004 00000212 xx...xx XX.

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x0b
Data length 2 0x0000
Data 0 None
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 0x55aa 03 0b 0000 0d

Notify the MCU of results (0x34 09)

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x34
Data length 2 0x0002
Data 2
  • 0x09 (subcommand): one byte.
  • 0x01 (status): one byte, indicating verification of the update failed.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x34
Data length 2 0x0001
Data 1 0x09 (subcommand)
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.