MCUBoot Firmware Update Over-The-Air Example

Over-the-air firmware update with concurrent real-time operation, demonstrating MCUBoot bootmanager integration for secure firmware replacement.

Intent and Usage

This example is designed to work in conjunction with the MCUBoot bootmanager and demonstrates the complete secure firmware update workflow:

  1. Bootmanager Phase: MCUBoot bootmanager validates the currently running application signature and boots the signed application image.

  2. Application Phase: This signed application runs concurrently with:

    • Real-time LED indicator (periodic timer ISR)

    • Background firmware update over UART receiving new firmware image

  3. Firmware Replacement: The application programs the new firmware into the dormant flash bank while maintaining real-time operation.

  4. MCUBoot Revalidation: Upon next power-cycle or reboot, MCUBoot bootmanager validates the new firmware image. If the new firmware is valid and has a greater version number than the currently active image, MCUBoot boots the new firmware.

To fully understand this example, use it alongside the MCUBoot bootmanager example. This example alone demonstrates only the firmware update mechanism; the complete secure boot flow requires MCUBoot bootmanager.

Concurrent Real-Time Operation

Two interrupt-driven activities run simultaneously:

  1. Timer ISR (priority 0, highest) — every 50 us, toggles the heartbeat LED every 500 ms and drives a second status LED that reflects the fw_update state (see below). Demonstrates that real-time foreground tasks stay responsive during a background firmware update.

  2. UART ISR (priority 1) — receives the firmware image in 262-byte packets from mcuboot_fw_update_host.py over UC4 at 115200 baud 8N1. Because the timer interrupt has the higher priority (lower NVIC priority number), it preempts UART processing, so both LEDs keep updating on schedule throughout the transfer.

Status LED

fw_update state

LED

IDLE

Off

READY / DOWNLOADING

Slow blink

ERROR

Fast blink

COMPLETE

Solid on

Firmware Transfer Protocol

The target flash address is fixed by main.c (APP_FW_UPDATE_BANK_ADDRESS), not sent on the wire.

  1. Host sends START packet: image size, expected CRC16.

  2. Host sends DATA packets (256-byte payload each). The application buffers payloads in RAM and erases+programs one flash sector at a time, only once a full sector’s worth has accumulated.

  3. Host sends END packet; the application flushes any leftover partial sector, then reads back the full image from flash and verifies its CRC16.

A PING packet can be sent at any time, including mid-transfer, to query the current state with no side effects - see Packet Format below.

Every packet (including START/END) gets a 5-byte ACK; a non-zero ErrorCode aborts the transfer. A fresh START packet can always restart an update, even after an ERROR.

Packet Format

Incoming (262 bytes): PacketType(1) + SeqNum(1) + PayloadLen(2) + CRC16(2) + Payload(256)

Outgoing ACK (5 bytes): MagicByte(0xAA)(1) + SeqNum(1) + ErrorCode(1) + AckCRC16(2). For a PING response, ErrorCode instead carries the current fw_update state (see fw_update.h’s FwUpdate_StateType).

See fw_update.h for the authoritative field layout, state machine, and error codes.

Configuration

Interface

Pin(s)

Settings

UART

UC4 PA0 (TX), PA1 (RX)

115200 baud, 8 data, no parity, 1 stop

Heartbeat LED

PIN_0

Board-specific, configured via SysConfig

Status LED

PIN_1

Board-specific, configured via SysConfig