How uofu-emb-26/ota works
1. What this repo is
- This is an embedded OTA update system for an STM32F072 target.
- The core architectural pattern is bootloader + dual application slots (A/B swap), so firmware can be updated without field intervention.
2. System boundary
- The repository contains the STM32-side firmware and build tooling.
- The transport path described in the README includes a Raspberry Pi Pico bridge over UART and a Wi‑Fi server, but those external components are not in this repo.
- On the MCU, the firmware does not appear to implement Wi‑Fi itself; it relies on an incoming update stream from the external bridge.
3. Execution model
- The code is split into a bootloader path and a firmware/application path.
- bootloader.c / bootloader_main.c handle startup and slot selection.
- main.c is the standard CubeMX-generated entrypoint for the firmware side.
- stm32f0xx_it.c, system_stm32f0xx.c, and the HAL MSP file provide the low-level runtime scaffolding.
4. Flash partitioning
- The linker scripts define the memory layout:
- STM32F072XX_FLASH.ld
- STM32F072_BOOTLOADER.ld
- STM32F072_APP_A.ld
- STM32F072_APP_B.ld
- This is the main architectural mechanism for A/B swapping: the bootloader occupies one region, and the two firmware images live in separate flash slots.
- The choice of linker scripts suggests separate build targets or image layouts for bootloader vs. application slots.
5. Boot decision and failover
- The bootloader’s responsibility is to decide which slot to run based on stored metadata and image validity.
- The expected behavior is: on reset, inspect OTA state, choose the active/healthy image, and fall back if the new image is incomplete or invalid.
- This is the reliability boundary of the system: the bootloader must preserve a known-good image.
6. Update/write path
- flash_update.c is the main boundary for programming flash.
- It likely handles erase/program operations, page alignment, and write verification.
- The OTA data path is therefore: receive update bytes → write to inactive flash slot → verify → mark valid → reboot.
7. Metadata and state
- ota_metadata.c / ota_metadata.h store persistent OTA state such as slot status, validity, and possibly version or boot flags.
- This metadata is what lets the bootloader know whether to boot slot A, slot B, or stay on the existing image.
- In an A/B system, metadata is as important as the image bytes themselves because it controls rollback safety.
8. Hardware/platform dependencies
- The project is built on STM32Cube HAL/CMSIS for STM32F0.
- The driver stack under Drivers/STM32F0xx_HAL_Driver and Drivers/CMSIS is vendor-supplied support, not application logic.
- The MCU peripherals visible in the dependencies include UART, flash, RCC, GPIO, CRC, and USB-related low-level support.
9. Communication assumptions
- The README describes an update pipeline that goes server → Wi‑Fi chip → Pico → UART → STM32.
- Architecturally, the STM32 side is the final receiver and flash writer; the upstream network protocol is abstracted away before it reaches this repo.
- This keeps the firmware small and deterministic, which is appropriate for a bootloader.
10. Build system and code generation
- The project uses CMake plus STM32CubeMX-generated sources (OTA.ioc, cmake/stm32cubemx).
- CMakePresets.json and the toolchain files indicate cross-compilation for ARM embedded targets.
- The repo is set up for reproducible firmware builds rather than a generic desktop application workflow.
11. Developer/support tooling
- flash_new_data.py and flash_commands.txt are repository-side utilities for provisioning or testing firmware/update payloads.
- PROJECT_HANDOVER.md and notes.txt suggest the repo is also being used as an engineering handoff artifact, which is useful for documenting flash layout and update procedure.
12. How to draw the architecture
- A good diagram should show:
- external update server,
- Wi‑Fi/Pico transport bridge,
- STM32 bootloader,
- flash metadata/state store,
- flash slot A,
- flash slot B,
- boot decision/fallback loop.
- The key flows are incoming firmware data to inactive slot and metadata-driven slot selection on reboot.
Main entry points: bootloader_main.c Boot entry · flash_update.c Flash writer · main.c App entry · ota_metadata.c OTA state
Components 20
External update path
Components outside the STM32 repo boundary that deliver update bytes.
- Update server · Hosts firmware payloads upstream of the embedded transport chain.
- Wi‑Fi bridge · External network-facing hop that forwards update bytes toward the MCU.
- Pico UART · UART relay into the STM32; abstracts the network protocol away from the MCU.
STM32 firmware
MCU-side bootloader, application entrypoints, and OTA flash control.
- Bootloader · Reset-time firmware that chooses the active or fallback image.
OTA/Core/Src/bootloader.c - Boot entry · Bootloader main path that initializes decision flow and jump handling.
OTA/Core/Src/bootloader_main.c - OTA state · Stored slot validity, boot flags, and related update state.
OTA/Core/Src/ota_metadata.c - Flash writer · Erases, programs, and verifies incoming bytes into flash memory.
OTA/Core/Src/flash_update.c - App entry · Standard CubeMX-generated firmware main function for the application side.
OTA/Core/Src/main.c - Slot A · Primary application partition defined by its linker layout.
OTA/STM32F072_APP_A.ld - Slot B · Secondary application partition used for OTA swaps and rollback.
OTA/STM32F072_APP_B.ld - Boot flash · Bootloader-reserved linker layout and MCU memory map.
OTA/STM32F072_BOOTLOADER.ld
Platform support
Vendor HAL/CMSIS runtime and low-level startup scaffolding.
- Interrupts · Exception and peripheral interrupt vectors for the MCU runtime.
OTA/Core/Src/stm32f0xx_it.c - HAL MSP · Peripheral and low-level HAL setup used by Cube-generated code.
OTA/Core/Src/stm32f0xx_hal_msp.c - System init · CMSIS system clock and core startup support.
OTA/Core/Src/system_stm32f0xx.c - Startup asm · MCU reset and initial stack/vector table setup.
OTA/startup_stm32f072xb.s - STM32 HAL · ST-provided hardware abstraction layer used by the firmware.
OTA/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c - CMSIS · Core and device definitions for STM32F0 and Cortex-M0.
OTA/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h
Build and tooling
Cross-compilation, generated project files, and operator utilities.
- CMake build · Cross-compilation and generated build orchestration for embedded targets.
OTA/CMakeLists.txt - CubeMX config · Source of truth for pinout, peripherals, and generated project settings.
OTA/OTA.ioc - Flash tools · Repo-side scripts and commands used to provision or test update images.
OTA/flash_new_data.py
Connections 20
- Update server → Wi‑Fi bridge: firmware stream · Update payload originates from the server.
- Wi‑Fi bridge → Pico UART: relay · External bridge forwards the stream over the transport chain.
- Pico UART → Flash writer: incoming bytes · STM32 receives update data for flash programming.
- Bootloader → Boot entry: starts · Reset flow enters bootloader main logic.
- Boot entry → OTA state: reads state · Bootloader inspects stored slot metadata before choosing an image.
- Boot entry → Slot A: selects A · May jump to slot A when it is valid and active.
- Boot entry → Slot B: selects B · May jump to slot B when it is valid and active.
- Boot entry → Boot flash: runs from · Bootloader executes from its reserved flash region.
- Flash writer → Slot B: writes inactive · Incoming image is programmed into the inactive application slot during OTA.
- Flash writer → Slot A: fallback write · Can target either slot depending on the current active image and update plan.
- Flash writer → OTA state: marks valid · Update completion updates persistent boot state and validity flags.
- OTA state → Boot entry: drives decision · Stored state governs next boot slot and rollback behavior.
- App entry → Interrupts: uses · Application runtime relies on interrupt handlers.
- App entry → HAL MSP: uses · Application runtime uses HAL board support initialization.
- App entry → System init: boots with · Application startup depends on core clock and system setup.
- System init → Startup asm: entry chain · Reset vector and startup assembly hand off to system initialization.
- STM32 HAL → Flash writer: flash access · Vendor HAL provides flash, UART, RCC, GPIO, and CRC primitives.
- CMSIS → System init: core defs · CMSIS supplies the MCU/device and core support definitions.
- CMake build → CubeMX config: generates · CMake build is paired with CubeMX-generated project configuration.
- CMake build → Flash tools: supports · Build ecosystem is complemented by repository-side flashing utilities.