2026-09-23 17:27:54 +02:00
# obu-firmware
2026-11-11 00:13:57 +01:00
The production OBU firmware: the ESP32-C5 half of the MicrOBU station (Seeed XIAO ESP32-C5).
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
## Since 2026-11-10: Niklas Dathe's microbu-firmware architecture
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
This tree is the current station firmware written by Niklas Dathe (`microbu-firmware` , HAW GitLab
urban-mobility-lab/microbu/microbu-firmware, commit e4e4bd8) with the MicrOBU additions below. The
earlier port of their older `microbu-esp32c5` (vanetza-idf, 2026-09-23) is gone.
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
Layout:
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
| Path | What |
| --- | --- |
| `main/` | station and link service: `station.cpp` , `link_*` , `serial_link.cpp` , `simple_ble.cpp` , `c5_radio.cpp` , board controls, battery |
| `components/microbu_v2x/` | station wrapper, security entity, device PKI client (unchanged from Niklas Dathe's firmware) |
| `components/vanetza/` | ESP-IDF component around Vanetza (unchanged) |
| `external/vanetza/` | patched upstream Vanetza source (unchanged, see its `UPSTREAM` ) |
| `docs/station-link.tex` | the link interface reference this firmware and the app implement: **revision 2** , Niklas Dathe's revision 1 plus our extensions (the original PDF is `microbu-firmware/docs/station-link.pdf` ; build ours with `pdflatex` , no LaTeX is installed on the lab laptop) |
| `cmake/no_efuse_writes.cmake` | build guard: nothing in this firmware may program eFuses |
2026-11-11 15:32:42 +01:00
| `test/host/` | PC tests (`make` in that folder): the MicrOBU C code (`gn_unwrap.c` , `geonet.c` ), the battery policy and, with `make firmware` , 40 unit tests of the link codec, V2X_RX and the policies |
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
Take a newer release from Niklas Dathe by copying `firmware/{main,components,cmake}` and
`external/vanetza` over these folders and re-applying the `MicrOBU:` changes (search the sources
for that word). Nothing is fetched from or pushed to their repository.
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
Board: `CONFIG_MICROBU_BOARD_XIAO_C5` (sdkconfig.defaults). Their default is `mainboard-v5` , the
custom PCB; pick it in `menuconfig -> micrOBU firmware -> Board` .
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
### MicrOBU additions (search for `MicrOBU`)
2026-09-23 17:27:54 +02:00
2026-11-11 00:13:57 +01:00
- **Reception of everything on air: `V2X_RX` , opcode `0x90` .** The stack decapsulates strictly, so it
drops unsigned traffic (the bench sim car) and everything signed under a root other than the
provisioned one (every RSU). Every received data frame therefore also goes through `gn_unwrap.c`
(`Station::forward_raw` ) and reaches the phone as `V2X_RX` . Body: `u16 port, i8 rssi, u8 flags
(bit0 GBC area, bit1 signed), i32 lat, i32 lon, u16 distance_a, ITS payload` . `0x85` is the spec's
`RAW_FRAME` debug capture and `0x86` is reserved by Niklas Dathe, hence `0x90` . BTP ports 2001
CAM, 2002 DENM, 2003 MAPEM, 2004 SPATEM, 2018 VAM pass; a message over 494 bytes does not fit a
512-octet link message and is dropped and counted (not fragmented).
- **Unsigned transmission.** Niklas Dathe's station signs everything. A request with GN security
profile 1 (or 0 while the station is configured `security = 0` ) goes out unsigned with
`geonet.c` 's header and the position of the last PoTi (`Station::unsecured_request` ), from a
2026-11-11 15:02:39 +01:00
random locally administered MAC drawn at every STATION_CONFIGURE, or the MAC the phone names in the 16-octet STATION_CONFIGURE (address_configuration 0), which also sets the address of signed frames: a ride rotates it with the pseudonym, the CAM pinger keeps one. The app's "Sign outgoing
2026-11-11 00:13:57 +01:00
messages" setting decides per message. It bypasses the BLE collision guard's queue but not the
guard itself.
- **Radio polled from configure on**, not from the first PoTi, so the 16-frame queue never overflows
while the phone has not sent a fix yet.
- **Radio bring-up** from the previous C firmware: manual country policy (5 GHz channels on), TX
power read-back logged, 2.4 KB receive buffer static instead of on the Wi-Fi task's stack, frames
too short to be GN packets ignored rather than counted as lost.
- **Battery guard.** Niklas Dathe's firmware only reports `battery_mv` in STATUS. A XIAO cell has no
protection board, so `battery_policy.hpp` (smoothing, warning hysteresis, shutdown) deep-sleeps the
board below 3.30 V for 30 s when no phone is on USB, re-checks every 5 min, and runs again from
3.60 V. Thresholds: `menuconfig -> micrOBU firmware` .
2026-11-11 14:17:38 +01:00
- **Battery reading fix** (`battery_monitor.cpp` , found on the XIAO 2026-11-11: `battery_mv` was 0). At
`CONFIG_FREERTOS_HZ=100` `vTaskDelay(pdMS_TO_TICKS(5))` is zero ticks, so the switched divider never
settled before the ADC read it and every sample fell below the 2.5 V validity floor. It is now a 5 ms
busy wait, and GPIO26 is set up with `gpio_config` . Worth telling Niklas Dathe: his mainboard-v5 has no
switched divider and is not affected. With the fix the XIAO reads 4153-4156 mV on a charging cell.
2026-11-11 00:13:57 +01:00
- **Serial link**: no write attempt while no USB host is connected; `last_frame_ms()` tells the battery
guard whether a phone is powering the board.
- **Partition table**: 80 KB NVS (Niklas Dathe's 24 KB filled up and BLE bonds stopped persisting),
app at `0x20000` . A plain app-only flash of an older layout is wrong: flash everything.
- **Flash size 8 MB** (XIAO), TX power ceiling 20 dBm (`radio_policy.hpp` admits 20 dBm on channel 180).
2026-11-11 15:32:42 +01:00
- **ATT MTU 517** (`CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU` , Niklas Dathe's 512): the app asks for 517 and a 494-octet
V2X_RX is a 512-octet link message, which needs a value of 512, i.e. an MTU of 515. At 512 such a message was
split into fragments the app does not reassemble.
- **Link-layer address.** A signed station without a named MAC uses the address derived from its ticket; with the
16-octet STATION_CONFIGURE the phone names it (see "Unsigned transmission"). The CAM and VAM station ID still
rotates in the app; the app now rotates the MAC with it on a ride and keeps one fixed for the bench pinger.
2026-08-04 17:58:07 +02:00
2026-11-11 00:13:57 +01:00
### Link spec revision 2
2026-08-04 17:58:07 +02:00
2026-11-11 00:13:57 +01:00
`docs/station-link.tex` is revision 2 of the interface reference: Niklas Dathe's revision 1 (microbu-firmware
e4e4bd8, kept unchanged as `microbu-firmware/docs/station-link.pdf` ) plus a section "MicrOBU extensions": `V2X_RX`
(0x90), unsigned transmission (security profile 0x01, or 0x00 with `security` 0; random MAC per configure),
the battery shutdown rule, no USB writes without a host, and a revision history. The wire format of
2026-11-11 15:32:42 +01:00
revision 1 is unchanged, so a revision 1 host still works. Build the PDF with `pdflatex station-link.tex`
(twice) and commit it with the `.tex` ; the LaTeX build files next to it are ignored. The section "Naming the MAC"
documents the 16-octet STATION_CONFIGURE, which revision 1 retires but the station still decodes.
### Dropped from the earlier MicrOBU version, and why
The first port (2026-09-23) carried a few things that Niklas Dathe's current firmware makes unnecessary:
- **Bench listener** (`CONFIG_MICROBU_BENCH_LISTEN` ): his `RAW_CAPTURE` / `RAW_FRAME` does the same over the link.
- **BLE pauses advertising while USB is in use**: his TX guard now holds each frame out of the BLE connection-event windows.
- **Battery flags at STATUS octets 103-105**: his layout puts channel-load fields there; the app derives low (3.50 V)
and critical (3.30 V) from `battery_mv` at octet 129.
- **The ETSI test channel** and the UART0 console: the log travels as LOG frames on the USB link.
- **`CONFIG_MICROBU_BATTERY_SCALE_PERMILLE` **: his battery code has no trim. The XIAO's reading was never compared
with a multimeter on the glued-in cell; the app shows 4.14-4.16 V on a charging cell, close to the charger's 4.20 V.
### What Niklas Dathe's latest firmware added over his earlier one
The station grew from about 580 to 1,360 lines. From his commit messages (not all of it read line by line): ITS clock
slewing, a TX guard against BLE collisions, stale-request refusal (`generated_at_ms` ), a pending queue that replaces an
unsent VAM with a newer one, Adaptive DCC with channel-busy-ratio measurement, declared radio operating points from
EN 302 571 measurements, robust CCA counters and TX retry, heap diagnostics, asn1c tables kept in flash, BLE with no
eFuse-based gates, an on-device TS 102 941 client (enrolment and authorisation relayed by the phone, trust bootstrap and
update), the `RAW_CAPTURE` debug path, fragmentation of link messages, the XIAO and `mainboard-v5` boards, and the
battery reading.
### Measured on the bench, 2026-11-11
Production XIAO on COM10, Pixel 9 Pro on BLE, COM3 board as an on-air listener (details and open points in `TODO.md` ):
the simulated car's CAMs reach the app; signed CAMs from the phone (tickets 1) and unsigned ones are heard by the
listener; over USB with BLE off 95.7 % of 300 signed CAMs were heard and over BLE with the screen on 95.7 % of 188, so
the BLE link adds no measurable loss; the BLE bond survives a board reset. `tools/station_tx_test.py` plays the phone
over USB and reads the station's own raw capture, which shows the 802.11 source address of what leaves the radio.
2026-08-04 17:58:07 +02:00
2026-11-11 00:13:57 +01:00
### What the new firmware changes for the phone
2026-08-04 17:58:07 +02:00
2026-11-11 00:13:57 +01:00
See `docs/station-link.tex` (revision history at its end). In short: `RESULT` /`STATUS` became `CONFIRM` (0x80) with the 131-octet
status in `CONFIRM.detail` of `STATUS_REQUEST` ; STATION_CONFIGURE is 6 octets (type, channel, power,
2026-11-11 15:32:42 +01:00
security, beaconing; no MAC unless the 16-octet form names one, else the address derives from the ticket); BTP-DATA.request carries
2026-11-11 00:13:57 +01:00
`generated_at_ms` (requests older than 1 s are refused); request bodies up to 1536 and indications up
to 65535 octets are fragmented; logs travel as LOG frames (0x7F) on the USB link, so a XIAO needs no
UART adapter any more.
Credentials: the app ships `assets/demo-chain.vcr` , a throwaway chain with psid 36 (CAM) and 638 (VAM).
Not EU-registered: receivers that verify against the EU trust list drop what it signs.
Time: TimestampIts counts TAI milliseconds since 2004 (TS 102 894-2), 5 leap seconds ahead of UTC;
the app's `ItsTime` follows that.