Document the MAC rotation (16-octet STATION_CONFIGURE), the ATT MTU of 517, the battery reading fix, pairing and bonds with several boards, tools/station_tx_test.py, what was dropped from the earlier MicrOBU version and what Niklas Dathe's latest firmware added, and the measured results (BLE adds no transmit loss over USB). Test counts: 40 firmware, 131 app.
135 lines
5.9 KiB
Markdown
135 lines
5.9 KiB
Markdown
# 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](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.
|
|
|
|
```mermaid
|
|
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
|
|
```
|
|
|
|
```yaml
|
|
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
|
|
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
|
|
|
|
```powershell
|
|
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
|
|
```
|
|
|
|
```text
|
|
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](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:
|
|
|
|
```powershell
|
|
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.
|
|
|
|
## BLE pairing
|
|
|
|
```yaml
|
|
# 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
|
|
|
|
```powershell
|
|
$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](../TODO.md). More: [test/host/README.md](test/host/README.md).
|
|
|
|
## More
|
|
|
|
| | |
|
|
|---|---|
|
|
| [NOTES.md](NOTES.md) | Every MicrOBU addition and why, what changed for the phone |
|
|
| [FLASHING.md](FLASHING.md) | Toolchain, flashing, bring-up checklist, battery and pins |
|
|
| [docs/station-link.pdf](docs/station-link.pdf) | The link interface reference, revision 2 (source: `station-link.tex`) |
|
|
| [external/vanetza/LICENSE.md](external/vanetza/LICENSE.md) | Vanetza licence |
|
|
| [external/vanetza/UPSTREAM](external/vanetza/UPSTREAM) | Upstream revision of the vendored Vanetza |
|
|
| [ESP32-C5 flash encryption](https://docs.espressif.com/projects/esp-idf/en/v6.0.2/esp32c5/security/flash-encryption.html) | Existing hardware state only; this firmware never enables it |
|