Replace the vanetza-idf port with his current station firmware (microbu-firmware e4e4bd8: main/, components/microbu_v2x, components/vanetza, external/vanetza) and re-apply the MicrOBU additions, each marked "MicrOBU:" in the sources: - V2X_RX (opcode 0x90): every received ITS message, signed or not, through gn_unwrap.c, because the stack drops unsigned and foreign-root traffic. 0x85 is the spec's RAW_FRAME and 0x86 is reserved. The body is built in v2x_rx.hpp. - Unsigned transmission (geonet.c) for security profile 1 or station security 0, from a random MAC per configuration. - Radio polled from STATION_CONFIGURE on; manual country policy, TX power read-back, static RX buffer, short frames ignored. - Battery guard (battery_policy.hpp): deep sleep below 3.30 V with no phone on USB. - No USB writes without a host; last_frame_ms() for the guard. - 80 KB NVS with the app at 0x20000, 8 MB flash, XIAO ESP32-C5 board, 20 dBm. Remove the old C firmware, the bench listener and the old vanetza-idf copy. Add docs/station-link.tex as revision 2 of the interface reference (V2X_RX, unsigned sending, battery rule, revision history). Add 39 host unit tests (make firmware in test/host) next to the existing chain, replay, fuzz and battery tests, and point tools/station_status_watch.py at the new CONFIRM-based status.
6.9 KiB
obu-firmware: build and flash
Board: Seeed XIAO ESP32-C5. One USB-C port, the chip's native USB Serial/JTAG (VID/PID 0x303A/0x1001); no UART bridge. 8 MB flash. The same port flashes the board, carries the phone's station link and carries the log (as LOG frames, type 0x7F), so the PC and the phone take turns on it. Over BLE the phone does not need the cable.
Toolchain
ESP-IDF 6.0.2 exactly (C:\Espressif\frameworks\esp-idf-v6.0.2): components/microbu_v2x
pins the C5 radio's private Wi-Fi driver ABI to it. Not the receiver firmware's 6.1, not
obu-cam-transmistter's 5.5.4. Exporting two IDFs in one PowerShell window fails; open a fresh
window, or clear $env:IDF_PYTHON_ENV_PATH and $env:IDF_PATH first.
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
$env:IDF_TOOLS_PATH = "C:\Espressif"
C:\Espressif\frameworks\esp-idf-v6.0.2\export.ps1
cd C:\Users\Ashin\AndroidStudioProjects\MicrOBU\obu-firmware
idf.py set-target esp32c5 # once per clean build folder
idf.py build # first build ~20 min; downloads espressif/esp-boost into managed_components/
Flash
Use a full flash (bootloader + partition table + app), never app-flash: the partition table is
not Niklas Dathe's (80 KB NVS, app at 0x20000).
idf.py -p COM6 flash
If the running firmware has taken the USB port down (or the board holds an unrelated image),
auto-reset fails with "No serial data received". Unplug, hold BOOT, plug in, release. If the flasher
stub then fails to start (seen 2026-11-10 with esptool 5.4 on this board), flash without it, from
build/:
python -m esptool --chip esp32c5 -p COM6 --no-stub --before=no-reset --after=hard-reset write-flash "@flash_args"
A board left in download mode comes back after unplugging and replugging without BOOT.
Before flashing a board you did not flash yourself, read its app descriptor
(esptool read-flash 0x10000 0x100; esp_app_desc_t starts at 0x20): project name microbu_firmware
is this firmware, obu_firmware an older MicrOBU one, arduino-lib-builder an Arduino sketch.
Back the flash up first to firmware-backups/ (gitignored).
First flash onto a board with other firmware
Erase the NVS range once, so no old Wi-Fi or BLE data sits in the new 80 KB NVS:
python -m esptool --chip esp32c5 -p COM6 erase-region 0x9000 0x15000
Then: the boot log shows BLE advertising started as 'micrOBU-XXXX' and station task ready; the
radio stays off until the app (or tools/station_status_watch.py --configure) sends
STATION_CONFIGURE; the app provisions the demo credentials on the first Connect. A phone that was
paired before must forget micrOBU-XXXX in Android's Bluetooth settings and pair again (passkey
123456, CONFIG_MICROBU_BLE_PASSKEY).
Look at the board from the PC
py -3.11 tools/station_status_watch.py COM6 30 --configure --rx
prints the log, the STATUS snapshot once a second (uptime, signing and radio counters, heap, battery) and the first V2X_RX messages heard on air. DTR/RTS stay low in the script because toggling them resets the board.
Production OBU checklist (board with the cell connected)
- Before touching the board: read its app descriptor and back its flash up (see above). Check the cell polarity with a multimeter before it goes on the BAT pads; the slide switch can stay off while flashing, USB powers the board.
- Erase the NVS range, then a full
idf.py -p COMx flash(or the--no-stubrecipe if the stub fails). Unplug and replug the cable without BOOT afterwards. py -3.11 tools/station_status_watch.py COMx 20 --configure --rx: expectBLE advertising started as 'micrOBU-XXXX', a STATUS line every second,configured=1after the configure, andbattery=close to the multimeter reading on the cell. The firmware has no calibration trim any more: if the two differ by more than about 50 mV, note both values (aCONFIG_MICROBU_BATTERY_SCALE_PERMILLEoption of the earlier port can be added back).- Switch the cell on, unplug USB, check the board keeps running (LED pulses on RX, the phone connects
over BLE). Then work down
TODO.md("obu-firmware on Niklas Dathe's microbu-firmware"). - Know the shutdown rule before leaving it unattended: with the cell below 3.30 V, no phone on USB and more than 60 s after boot, the board deep-sleeps and only wakes every 5 minutes to check; it runs again from 3.60 V (charge it over USB). A board that "went dead" on a flat cell is this, not a crash.
- Install the app built from this commit on the phone: the app and firmware of 2026-11-10 only talk
to each other (CONFIRM/STATUS_REQUEST, V2X_RX 0x90). The phone must forget an old
micrOBU-XXXXbond and pair again (passkey 123456), because the NVS was erased.
Battery and pins (XIAO ESP32-C5)
The prototype runs on a 3.7 V LiPo on the BAT pads (cell + through a slide switch to BAT+,
− to BAT−); the board's charger charges it from USB. Check the polarity with a multimeter
first: reversed, it destroys the board. The cell has no protection board, so only the firmware
stops an over-discharge, and nothing stops a short.
| Pin | GPIO | Used for |
|---|---|---|
| on-board | GPIO6 | BAT_VOLT_PIN: BAT+ through the board's own 100 kΩ / 100 kΩ divider (ADC1); nothing to wire |
| on-board | GPIO26 | BAT_VOLT_PIN_EN: load switch for that divider, high only while measuring; nothing to wire |
| native USB | GPIO13 / GPIO14 | USB D− / D+ |
| (user LED) | GPIO27 | yellow LED, active low: pulses on TX/RX (CONFIG_MICROBU_STATUS_LED) |
Only the cell's + and − go to the BAT pads; the cell's two extra wires (temperature / ID) stay unconnected, the firmware does not use them. The voltage measurement needs no further wiring. BatteryMonitor (battery_monitor.cpp) reports the calibrated cell voltage as battery_mv in
STATUS (octets 129-130, 0 = no cell or no sensor). BatteryPolicy (battery_policy.hpp, host-tested
in test/host) adds the protection, every 5 s: the smoothed voltage below 3.30 V for 30 s, more than
60 s after boot and with no frame from a phone on USB in the last 5 s, puts the board into deep
sleep; it wakes every 300 s, measures, and runs again from 3.60 V. A phone on USB powers the board,
so no shutdown happens then. Thresholds: menuconfig -> micrOBU firmware. The app shows
low/critical from the same voltage and its own thresholds.
If the build fails
idf.py fullclean, then build again. A "provided by component(s) ... not in the requirements list"
error means a header moved to another IDF component: add it to REQUIRES in main/CMakeLists.txt.
Going back
firmware-backups/ (gitignored, on the lab laptop) holds full or 4 MB images of the boards as they
were before they were reflashed. Restore with
python -m esptool --chip esp32c5 -p COM<N> write-flash 0 <image>. The previous C firmware is in
git history (last commit before the port: 7285fa1; the vanetza-idf port: 1c3a66e).