# kiko283/mbed-os-fota-main-application architecture

> Architecture diagram of the GitHub repository kiko283/mbed-os-fota-main-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kiko283/mbed-os-fota-main-application
- Repository: https://github.com/kiko283/mbed-os-fota-main-application

## Overview

This is an Mbed OS cellular firmware-over-the-air (FOTA) application. Its main workflow powers and configures a SARA-R4xx modem, brings up cellular networking, publishes device telemetry over MQTT, checks for a newer firmware version over HTTP, and downloads the image into external SPI flash. It then resets so the separate bootloader can install the staged image. The README documents the external-flash and bootloader roles; sampled excerpts do not show every FOTA helper implementation, so uncertain internal connections are omitted.

Main entry points: [`source/main.cpp`](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp) (Application loop), [`source/fota_cellular.cpp`](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp) (FOTA coordinator), [`bootloader/bootloader.bin`](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/bootloader/bootloader.bin) (Bootloader image), [`source/sara_r4xx.cpp`](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/sara_r4xx.cpp) (SARA-R4xx driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application control"]
  node_main["Application loop<br/>[main.cpp]"]
  node_watchdog["Watchdog thread<br/>[main.cpp]"]
  node_tracing["Tracing setup<br/>[tracing.h]"]
end

subgraph group_connectivity["Cellular connectivity"]
  node_modem["SARA-R4xx driver<br/>[sara_r4xx.cpp]"]
  node_serial["Modem serial link<br/>[main.cpp]"]
  node_cell_network["Cellular network"]
  node_mqtt["MQTT telemetry<br/>[fota_cellular.cpp]"]
end

subgraph group_update["Firmware update"]
  node_fota["FOTA coordinator<br/>[fota_cellular.cpp]"]
  node_version_check["Version check<br/>[fota_cellular.cpp]"]
  node_image_download["Image download<br/>[fota_cellular.cpp]"]
end

subgraph group_device["Device storage and install"]
  node_spi_flash[("External SPI flash")]
  node_reset["System reset<br/>[fota_cellular.cpp]"]
  node_bootloader["Bootloader image<br/>[bootloader.bin]"]
  node_mcu_flash[("MCU firmware")]
end

node_device_user(("Device startup"))
node_mqtt_broker(("MQTT broker"))
node_firmware_service(("Firmware service"))

node_device_user -->|"starts"| node_main
node_main -->|"starts thread"| node_watchdog
node_main -->|"opens tracing"| node_tracing
node_main -->|"creates"| node_modem
node_main -->|"provides serial"| node_serial
node_modem -->|"uses"| node_serial
node_main -->|"creates context"| node_cell_network
node_main -->|"runs"| node_fota
node_fota -->|"powers and configures"| node_modem
node_fota -->|"connects"| node_cell_network
node_fota -->|"invokes"| node_mqtt
node_mqtt -->|"uses TCP"| node_cell_network
node_mqtt -->|"publishes telemetry"| node_mqtt_broker
node_fota -->|"checks update"| node_version_check
node_version_check -->|"requests version"| node_firmware_service
node_fota -->|"starts download"| node_image_download
node_image_download -->|"requests image"| node_firmware_service
node_image_download -->|"erases and writes"| node_spi_flash
node_fota -->|"resets on update"| node_reset
node_reset -->|"boots"| node_bootloader
node_bootloader -.->|"reads staged image"| node_spi_flash
node_bootloader -.->|"installs firmware"| node_mcu_flash

click node_main "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp"
click node_watchdog "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp"
click node_fota "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp"
click node_modem "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/sara_r4xx.cpp"
click node_serial "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp"
click node_mqtt "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp"
click node_version_check "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp"
click node_image_download "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp"
click node_reset "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp"
click node_bootloader "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/bootloader/bootloader.bin"
click node_tracing "https://github.com/kiko283/mbed-os-fota-main-application/blob/main/include/tracing.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_watchdog,node_tracing toneBlue
class node_modem,node_serial,node_cell_network,node_mqtt toneAmber
class node_fota,node_version_check,node_image_download toneMint
class node_spi_flash,node_reset,node_bootloader,node_mcu_flash toneRose
class node_device_user,node_mqtt_broker,node_firmware_service toneIndigo
```

## Components

### Application control

- [Application loop](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp): `source/main.cpp`
- [Watchdog thread](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp): `source/main.cpp`
- [Tracing setup](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/include/tracing.h): `include/tracing.h`

### Cellular connectivity

- [SARA-R4xx driver](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/sara_r4xx.cpp): `source/sara_r4xx.cpp`
- [Modem serial link](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/main.cpp): `source/main.cpp`
- **Cellular network**
- [MQTT telemetry](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp): `source/fota_cellular.cpp`

### Firmware update

- [FOTA coordinator](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp): `source/fota_cellular.cpp`
- [Version check](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp): `source/fota_cellular.cpp`
- [Image download](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp): `source/fota_cellular.cpp`

### Device storage and install

- **External SPI flash**
- [System reset](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/source/fota_cellular.cpp): `source/fota_cellular.cpp`
- [Bootloader image](https://github.com/kiko283/mbed-os-fota-main-application/blob/main/bootloader/bootloader.bin): `bootloader/bootloader.bin`
- **MCU firmware**

### Other components

- **Device startup**
- **MQTT broker**
- **Firmware service**

## Connections

- Device startup → Application loop: starts
- Application loop → Watchdog thread: starts thread
- Application loop → Tracing setup: opens tracing
- Application loop → SARA-R4xx driver: creates
- Application loop → Modem serial link: provides serial
- SARA-R4xx driver → Modem serial link: uses
- Application loop → Cellular network: creates context
- Application loop → FOTA coordinator: runs
- FOTA coordinator → SARA-R4xx driver: powers and configures
- FOTA coordinator → Cellular network: connects
- FOTA coordinator → MQTT telemetry: invokes
- MQTT telemetry → Cellular network: uses TCP
- MQTT telemetry → MQTT broker: publishes telemetry
- FOTA coordinator → Version check: checks update
- Version check → Firmware service: requests version
- FOTA coordinator → Image download: starts download
- Image download → Firmware service: requests image
- Image download → External SPI flash: erases and writes
- FOTA coordinator → System reset: resets on update
- System reset → Bootloader image: boots
- Bootloader image → External SPI flash: reads staged image
- Bootloader image → MCU firmware: installs firmware
