Files
MicrOBU/obu-firmware
Ashin Walpola 462e1898ff Run the overnight bench test on the spare board, and document it
Track the bench scripts (run_overnight.py and its stages, the link and ITS
client libraries, the phone-vs-node comparison) with the first reports.

Changes for the spare XIAO (no cell):
- run_overnight.py picks the single Espressif board by default and refuses to
  test a build that is not this checkout's HEAD.
- The unsigned soak stops as "transmit path wedged" after 40 resource_limit
  refusals in a row and tries whether a repeated STATION_CONFIGURE clears it.
- "Refused requests put nothing on the radio" counts only own transmissions;
  frames heard from other stations are copied by RAW_CAPTURE too.
- start_overnight.ps1: optional build and flash, host C tests in the
  background, Windows kept awake. setup_workstation.ps1 checks and installs
  git, Python 3.11, pyserial, asn1tools, MSYS2 gcc and make, ESP-IDF 6.0.2.
- obu-firmware/docs/overnight-bench-test.tex (and PDF) describe the test, the
  workstation set-up and the findings of the 2026-11-25 runs.
2026-11-25 14:43:34 +01:00
..

obu-firmware (micrOBU ESP32-C5)

The firmware of the production MicrOBU: the ESP32-C5 half of the station, on the Seeed XIAO ESP32-C5. It is the station firmware written by Niklas Dathe (microbu-firmware, HAW GitLab urban-mobility-lab/microbu/microbu-firmware, commit e4e4bd8) with the MicrOBU additions listed in NOTES.md. The phone builds CAM and VAM messages; this firmware adds BTP and GeoNetworking, signs, transmits over ITS-G5, and hands every received ITS message back to the phone.

flowchart LR
  App[Android app: facilities and HMI] <-->|USB or encrypted BLE| Link[Station link]
  App -->|STATUS_REQUEST, 1 Hz| Link
  Link -->|CONFIRM with status| App
  Link <--> Wrapper[microbu_v2x]
  Wrapper <--> GN[Vanetza BTP and GeoNetworking]
  Wrapper <--> Security[Security and device PKI client]
  Security <--> NVS[NVS credentials and keys]
  GN <--> Radio[ESP32-C5 ITS-G5 radio]
  Radio -->|every data frame| Raw[gn_unwrap.c, MicrOBU]
  Raw -->|V2X_RX 0x90, signed or not| Link
  Link -->|unsigned request| Geo[geonet.c, MicrOBU]
  Geo --> Radio
  Battery[Battery guard, MicrOBU] -.->|deep sleep below 3.30 V| Radio
target: ESP32-C5
SDK: ESP-IDF-6.0.2            # exactly; the radio driver ABI is pinned to it
board: Seeed-XIAO-ESP32-C5    # 8 MB flash, one native USB-C port
other_board: mainboard-v5     # the custom PCB, menuconfig -> micrOBU firmware -> Board
runtime:
  main/: station-and-link-service
  components/microbu_v2x: station-wrapper-and-security      # Niklas Dathe, unchanged
  components/vanetza: ESP-IDF-component                     # Niklas Dathe, unchanged
  external/vanetza: patched-upstream-source                 # see external/vanetza/UPSTREAM
link:
  spec: docs/station-link.tex (revision 2; revision 1 is Niklas Dathe's)
  transports: USB Serial/JTAG (0xAA55 frames) and BLE GATT (service 0000c175-...)
  max_message: 512 octets, fragmented above that by the spec
microbu_extensions:
  V2X_RX: opcode 0x90, every ITS message heard on air, verified or not
  receive_paths: V2X_RX and the spec's RAW_FRAME both stay; the app chooses (Settings > Receive path), RAW_CAPTURE mode 3 turns raw on
  unsigned_tx: security profile 1, or 0 with station security 0
  radio: polled from STATION_CONFIGURE on
  battery_guard: deep sleep below 3.30 V, no phone on USB, runs again from 3.60 V
flash_layout:
  nvs: 80 KB at 0x9000
  app: 3 MB at 0x20000
telemetry:
  battery: calibrated-divider-voltage     # GPIO6, enabled by GPIO26, only + and - are wired
  temperature: unavailable
  charger_source: unavailable
keys:
  backend: ESP32-PSA
  storage: NVS
  NVS_encryption: only-if-flash-encryption-already-active
  eFuse_writes: forbidden                  # cmake/no_efuse_writes.cmake

Build and flash

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
$env:IDF_TOOLS_PATH = "C:\Espressif"
C:\Espressif\frameworks\esp-idf-v6.0.2\export.ps1
cd obu-firmware
idf.py set-target esp32c5      # once per clean build folder
idf.py build
idf.py -p COMx flash           # full flash, never app-flash: the partition table is ours
menuconfig -> micrOBU firmware -> Board, battery thresholds, BLE passkey, TX BLE guard, status LED

Everything else (the --no-stub fallback, reading a board's app descriptor before flashing, the production checklist with the cell, battery and pins): FLASHING.md.

Using it

The log arrives as LOG frames (type 0x7F) on the USB link, so a XIAO needs no UART adapter. To see the board from the PC:

py -3.11 tools/station_status_watch.py COMx 30 --configure --rx
py -3.11 tools/station_tx_test.py COMx --seconds 60 --mac 02:aa:bb:cc:dd:01   # plays the phone, reads the raw own-TX capture

It prints the log, the 131-octet STATUS once a second (uptime, signing and radio counters, heap, battery) and the first V2X_RX messages. Status exchange: the host sends STATUS_REQUEST every 1000 ms; CONFIRM.detail contains the snapshot.

Received messages reach the phone on two paths that both stay in the firmware: V2X_RX (ours, always on, already unwrapped, one message up to 494 octets, fragmented above that up to 2300) and RAW_FRAME (the spec's debug capture, on after RAW_CAPTURE, the whole radio frame, fragmented when large). The Android app has a switch for which one it consumes; the board always sends V2X_RX. See NOTES.md.

flowchart LR
  Air[ITS-G5 frame on air] --> Radio[C5 radio, promiscuous RX]
  Radio --> Stack[Vanetza stack: decap and verify]
  Radio --> Unwrap[gn_unwrap.c: 802.11, LLC, GN, BTP, signature envelope]
  Radio -->|only while RAW_CAPTURE is on| Cap[Raw capture tap: ITS5 record]
  Stack -->|verified only| Ind[BTP_DATA_INDICATION 0x81]
  Unwrap -->|always, signed or not, fragmented above 494 octets| Rx[V2X_RX 0x90, MicrOBU]
  Cap -->|fragmented if large| Raw[RAW_FRAME 0x85, spec]
  Ind --> Link[Station link: USB or BLE]
  Rx --> Link
  Raw --> Link
  Link --> App[Android app]
  App -->|Receive path: V2X_RX| UseA[uses V2X_RX, ignores RAW_FRAME]
  App -->|Receive path: Raw frames| UseB[reassembles, unwraps with GnUnwrap, ignores V2X_RX]

BLE pairing

# as documented for Niklas Dathe's BLE code, which this firmware does not modify
BLE_pairing:
  compile_time: CONFIG_MICROBU_BLE_PASSKEY
  default: 123456
  disable_value: 0
  unprovisioned_station: USB-only
  bond_storage: NVS            # 80 KB, so the bond persists
  owner: first-bond-only
  remote_bond_replacement: refused
  hardware_security: existing-state-only
  generate_hardware_keys: forbidden

The passkey is public, so the link is encrypted but not protected against an active attacker during the first pairing. A phone that was paired before must forget micrOBU-XXXX in Android's Bluetooth settings after the board's NVS was erased. BLE and ITS-G5 share one RF front end: the firmware holds a frame out of the BLE connection-event windows (CONFIG_MICROBU_TX_BLE_GUARD; calibrated for a 20 ms connection interval only). The bond is one per board and survives a reset; with several micrOBUs nearby pair the right one in Android first (FLASHING.md).

Tests

$env:PATH = "C:\msys64\ucrt64\bin;C:\msys64\usr\bin;$env:PATH"
cd obu-firmware\test\host
make firmware      # 40 unit tests: link codec, STATUS, reassembly, V2X_RX, policies. PASS or FAIL per test
make               # everything: chain, replay of recorded frames, fuzz, battery, firmware

These run on the PC and cannot test the radio, BLE, NVS or USB. What still needs a board, a phone or a second ESP32-C5 is listed in ../TODO.md. More: test/host/README.md.

More

NOTES.md Every MicrOBU addition and why, what changed for the phone
FLASHING.md Toolchain, flashing, bring-up checklist, battery and pins
docs/station-link.pdf The link interface reference, revision 2 (source: station-link.tex)
external/vanetza/LICENSE.md Vanetza licence
external/vanetza/UPSTREAM Upstream revision of the vendored Vanetza
ESP32-C5 flash encryption Existing hardware state only; this firmware never enables it