MCU Firmware Update

Last Updated on : 2024-07-30 03:31:16download

This topic describes how to update the MCU. You can specify how an OTA update is triggered. The module only serves as the channel for update transmission, without any data parsing operation.

Trigger mechanisms

Three trigger mechanisms are available:

  • Update notification: Users receive a firmware update notification on the app and choose whether to install updates.
  • Forced update: Users receive a firmware update notification on the app and have no option but to update the firmware.
  • Check for updates: Users will not receive a firmware update notification on the app but need to manually check for new updates.

Update process

Perform the MCU firmware update process as follows:

  1. After the update packet transmission is finished, the module will send the command 0x01 to the MCU to query the product information.

  2. The MCU must reply with the new MCU firmware version number within one minute. The new version number should be consistent with that configured on the Tuya Developer Platform.

Here is how the OTA update works:

MCU Firmware Update

Initiate an update (0x0C)

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x0C
Packet length 2 0x0008
Data 8
  • Data[0-3]: the update file size, 0x000013CF.
  • Data[4-7]: CRC32, 0xC20A5FBB.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example

55 AA 00 0C 00 08 000013CF C20A5FBB DB

The MCU returns the following data.

The MCU returns the offset address to support resumable download.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x0C
Data length 2 0x0001/0x0005
Data 5
  • Data[0]:
    • 0x00: 64 bytes in each packet
    • 0x01: 128 bytes in each packet
    • 0x02: 256 bytes in each packet
  • Data[1-4]: the offset address.
Note: If the data length is 0x0001 and the offset address is not passed in, the download start address will be 0. This is to be compatible with the length 0x0001 in the legacy protocol.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example

55 AA 00 0C 00 01 00 0C        // 64 bytes
55 AA 00 0C 00 01 01 0D        // 128 bytes
55 AA 00 0C 00 01 02 0E        // 256 bytes
55 AA 00 0C 00 05 02 00000800 1A        // Start the download from the offset address of 2048 bytes.

Transmit update package (0X0D)

Example:

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x0D
Data length 2 0x0044 (offset and data length)
Data 4
  • Data[0-3]: the OTA packet offset 0x00000000.
  • Data[4-n]: the OTA payload.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example

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

  • For the first packet, the packet offset is 0x00000000, and the packet length is 256 bytes.

    55 AA 00 0D 01 04 00000000 xxx...xxx XX
    
  • For the second packet, the packet offset is 0x00000100, and the packet length is 256 bytes.

    55 AA 00 0D 01 04 00000100 xxx...xxx XX
    
  • For the third packet, the packet offset is 0x00000200, and the packet length is 18 bytes.

    55 AA 00 0D 01 04 00000200 xxx...xxx XX
    
  • For the last packet, the packet offset is 0x00000212, and the packet length is 0 bytes.

    55 AA 00 0D 00 04 00000212 XX
    

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x0D
Data length 2 0x0000/0x0001
Data 1 Data[0]:
  • 0x00: The CRC32 check succeeds.
  • 0x01: The CRC32 check fails.
Note: The module should wait for the CRC32 check result from the MCU. The legacy protocol is compatible, so it can run properly without any changes. See the example.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example

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

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

    55 AA 00 0D 00 04 00000212 XX
    
  • The MCU returns the following data.

    No response within 10s          // Consider that the CRC32 check succeeded.
    55 AA 00 0D 00 00 0C          // CRC32 check succeeded.
    55 AA 00 0D 00 01 00 0D     // CRC32 check succeeded.
    55 AA 00 0D 00 01 01 0E     // CRC32 check failed.
    

Check file download progress (0xC3)

The MCU can send this command to request the progress of downloading the MCU updates or the NB-IoT updates.

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0xC3
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:

55 AA 00 C3 00 00 C2

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0xC3
Data length 2 0x0002
Data 2 The download status and progress.
BYTE[0] 1
  • 0x00: No file is being downloaded.
  • 0x01: File is being downloaded.
BYTE[1] 1 The download progress in percentage (0 to 100).
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example:

55 AA 00 C3 00 02 01 05 CA