Skip to content

998. Firmware update via CAN

Nathan zhou edited this page Nov 3, 2025 · 5 revisions

(ai paraphrase) The goal is to allow a MRC or PC host to transmit new firmware to the ESP32 completely through the CAN network, following the FRC CAN specification.

1. General Concept

The ESP32 can enter a dedicated Firmware Update Mode, where it behaves as a Device Type 31 (Firmware Updater).
In this state, normal user functions are disabled and the firmware only listens for update-related CAN messages.

All update communication uses extended CAN frames at 1 Mbps, using the standard FRC CAN message ID layout:

CAN_ID = (deviceType << 24) | (manufacturerID << 16) | (apiID << 6) | (deviceNumber & 0x3F)
  • Device Type: 31 (firmware updater)

  • Manufacturer ID: 0x08 (Team custom device)

  • Device Number: user-assigned

  • API ID: identifies the update command type (see below)


2. Boot Behavior and Update Entry

On Startup

When the ESP32 powers up, it checks a flag stored in EEPROM named enterUpdateMode.

  • If the flag is false, the device performs its normal initialization.

  • If the flag is true, it immediately skips normal initialization and enters Firmware Update Mode.
    The flag is cleared automatically so that after the next reboot, the device returns to normal operation.

This ensures the device cannot become permanently stuck in update mode.

Entering Update Mode from Normal Operation

During normal operation, the CAN receive task continuously listens for control commands.

When a message with API ID 0x001 is received, and the last data byte (byte 7) equals 0xFF,
the ESP32 interprets this as a firmware update request.

It then:

  1. Sets the EEPROM flag enterUpdateMode = true

  2. Sends an optional acknowledgment frame

  3. Performs a software reboot

After reboot, the device detects the flag and starts in update mode, ready to accept the new firmware.


3. Update Mode CAN Protocol

When in Firmware Update Mode, all communication follows a fixed CAN message structure.
Only specific API IDs are used to identify each phase of the update.

Direction API ID Function Description
Host → ESP32 0x100 Firmware Metadata Announces firmware size, total chunk count, and chunk length.
Host → ESP32 0x120 – 0x136 Firmware Chunks Contains raw binary data of the new firmware (8 bytes per frame).
Host → ESP32 0x105 Checksum Sends firmware checksum (CRC32 or SHA-256) for final verification.
ESP32 → Host 0x101 Chunk Request ESP32 requests which chunk index should be sent next.
Host → ESP32 0x001 Enter Update Mode Control message used during normal operation; triggers reboot into updater mode when last byte = 255.

8. References

Summary:
The ESP32’s CAN-based firmware update process enables reliable field updates using standard FRC-style CAN frames.
It can be triggered remotely, performs robust chunked transfer with checksum validation, and guarantees recovery to a known-good firmware image.

Clone this wiki locally