1cba9f30bc
Firmware / build (push) Successful in 10m49s
- ReverseLight: isolated output DO0 (CH422G OC0 -> PC817 -> NPN sink) drives the reverse-lamp relay while the lever is in R on a live bus with ignition on; 10 Hz decision confirmed over 200 ms, written through the panel library's expander object so the backlight cannot undo it; `reverse status|on|off|force` console, default ON (NVS `revlight_en`). Wiki page reverse-lights-output with the wiring. - Sport screen: BMW-style power + torque gauges (lv_meter on a dial-face image, image needle); PNG sources in assets/, tools/png2lvgl.py converter. - Vehicle: final drive ratio + tyre circumference -> road speed, hp from torque; Settings > Vehicle page; `vehicle` console. - Bench simulation (`sim` console) overlays torque / rpm / shaft on the snapshot. - EcuIdent: KWP 1A 86 / 1A 80 read once, stored in NVS, shown on Settings > Vehicle, passive ECU CHANGED? check; `ecu` console. - Ignition fallback from the 0x1D2 lever byte on buses without 0x3B4 (Patrol 2). - Engine data: per-DDE `2C 10` identifier profiles (Patrol 1 vs Patrol 2 rail 00C2 / boost 003A / battery 002F); DiagProbe liveConfigure(). - Wiki: Patrol 2 captures, vehicles page, obd identifier table per DDE, logs.
238 lines
12 KiB
Markdown
238 lines
12 KiB
Markdown
# Commands cheat-sheet — both controllers
|
||
|
||
Everything you type to build, flash, watch and drive the two boards. Kept in the
|
||
Main CTRL repo (this one); the Inst. Cluster repo's README points here.
|
||
|
||
| | Main CTRL | Inst. Cluster |
|
||
|---|---|---|
|
||
| Board | Waveshare ESP32-S3-Touch-LCD-5B (5" touch) | Waveshare ESP32-S3-LCD-1.3 (1.3" round) |
|
||
| Repo / branch | `ESP32-S3-Touch-LCD-5B`, `main` | `ESP32-S3-LCD-1.3`, `master` |
|
||
| Platform | pioarduino (Arduino 3.3.3 / IDF 5.5) | espressif32@6 (Arduino 2.0.17 / IDF 4.4) |
|
||
| Serial | native USB-CDC | CH343 UART |
|
||
| Bench port (2026-09-28) | COM14 | COM10 |
|
||
| OTA target / release | `patrol-a`, `v*` tags → signed release | `patrol-b`, `v*` tags → signed release |
|
||
|
||
Windows ports move around: `pio device list` shows what is plugged in.
|
||
|
||
---
|
||
|
||
## 1. Rules of the road (Windows, this machine)
|
||
|
||
- **PowerShell only.** `pio` refuses to run from Git Bash (`MSys/Mingw is not supported`).
|
||
- `pio` lives at `$env:USERPROFILE\.platformio\penv\Scripts\pio.exe` (no global install). The commands below assume this alias:
|
||
```powershell
|
||
Set-Alias pio "$env:USERPROFILE\.platformio\penv\Scripts\pio.exe"
|
||
```
|
||
- **The two projects share one PlatformIO environment.** Consequences:
|
||
- The first `pio run` after building the *other* project reinstalls the Arduino core and may fail once with `TypeError: expected str, bytes or os.PathLike object, not NoneType`. Run it again.
|
||
- After **any B build**, repair the environment before building A, or A fails with `Failed to install Python dependencies into penv`:
|
||
```powershell
|
||
.\tools\fix_penv_deps.ps1 # run inside the A repo
|
||
```
|
||
- Never build both projects at the same time.
|
||
- **A serial monitor on a port blocks uploads to that port.** Close it (Ctrl+C) first.
|
||
- Opening a port with DTR/RTS asserted resets the board. Always monitor with `--dtr 0 --rts 0`.
|
||
|
||
---
|
||
|
||
## 2. Build and upload
|
||
|
||
Run inside the respective repo folder.
|
||
|
||
### Main CTRL
|
||
```powershell
|
||
cd <path>\ESP32-S3-Touch-LCD-5B
|
||
pio run # build only (dev build, version "dev")
|
||
pio run -t upload --upload-port COM14 # build + flash over USB
|
||
pio run -t clean # wipe the build directory
|
||
```
|
||
First build after a `platformio.ini` change rebuilds the ESP-IDF core (~20 min, `custom_sdkconfig`); later builds take 1–3 min.
|
||
|
||
### Inst. Cluster
|
||
```powershell
|
||
cd <path>\ESP32-S3-LCD-1.3
|
||
pio run
|
||
pio run -t upload --upload-port COM10
|
||
..\ESP32-S3-Touch-LCD-5B\tools\fix_penv_deps.ps1 # ALWAYS after a B build, before the next A build
|
||
```
|
||
|
||
A USB flash writes bootloader, partition table, `boot_app0` and the app into slot 0. It does **not** touch NVS: saved Wi-Fi network, tunables, pairing key and B's cached gauge config survive.
|
||
|
||
---
|
||
|
||
## 3. Serial monitor
|
||
|
||
```powershell
|
||
pio device monitor -p COM14 -b 115200 --dtr 0 --rts 0 --echo # Main CTRL
|
||
pio device monitor -p COM10 -b 115200 --dtr 0 --rts 0 --echo # Inst. Cluster
|
||
```
|
||
Type a command, press Enter. `--echo` shows what you type. Ctrl+C leaves.
|
||
|
||
One-shot commands and logging from a script (A repo, `tools/`):
|
||
```powershell
|
||
python tools\serial_cmd.py COM14 "link status" 3 # send one line, print 3 s of reply
|
||
python tools\serial_logger.py COM14 # log a port to wiki\raw\ until Ctrl+C
|
||
python tools\serial_logger.py COM14,COM10 # both ports at once
|
||
python tools\perf_session.py COM14 # display-performance session (PERF lines)
|
||
python tools\diag_session.py COM14 "diag pids" "diag vin" # scripted OBD probe run with log
|
||
```
|
||
|
||
---
|
||
|
||
## 4. Main CTRL console
|
||
|
||
Type `help` for the list. Unknown lines are reported.
|
||
|
||
### `cfg` — Patrol gauge calibration and alert thresholds (saved in NVS, pushed to B)
|
||
```
|
||
cfg show
|
||
cfg set <name> <value> tach_ppr tach_trim tach_min_hz tach_max_hz
|
||
temp_hz temp_slope(x100) temp_offset temp_min temp_duty_max
|
||
tach_en temp_en coolant_hot gearbox_hot batt_low(x100)
|
||
cfg override off | rpm <n> | duty <n> | both <rpm> <duty> bench test of B's outputs, never saved
|
||
cfg reset
|
||
```
|
||
|
||
### `wifi`
|
||
```
|
||
wifi status connection, saved network, ESP-NOW health
|
||
wifi join <ssid> [pass] join and remember a network (no spaces in the SSID)
|
||
wifi forget drop the remembered network (B is told to forget too)
|
||
wifi scan list networks in range
|
||
wifi on | off
|
||
```
|
||
|
||
### `ota` — this controller's own updates
|
||
```
|
||
ota status version, slot, rollback state
|
||
ota check ask Gitea for the latest release (needs Wi-Fi)
|
||
ota install [force] download, verify, flash the idle slot, reboot (parked only)
|
||
ota rollback boot the previous slot (parked only)
|
||
```
|
||
|
||
### `link` — Inst. Cluster over the link
|
||
```
|
||
link status B's version, pairing, update phase, credentials
|
||
link pair new shared key → B over the UART WIRE (bench, wire connected)
|
||
link unpair forget the key here
|
||
link creds send the remembered Wi-Fi network to B now (normally automatic)
|
||
link ota check | install [force] | rollback drive B's updater (A must be on Wi-Fi, parked)
|
||
```
|
||
|
||
### `diag` — OBD-II probe (the only thing that ever transmits on the CAN bus)
|
||
```
|
||
diag pids scan mode-01 supported-PID bitmaps
|
||
diag pid <hex> one mode-01 request (0C rpm, 70 boost, ...)
|
||
diag dtc mode 03, stored generic DTCs
|
||
diag vin mode 09 PID 02
|
||
diag ecu mode 09 PID 0A
|
||
diag ident [addr] BMW KWP 1A 80 identification (default 12 = DDE)
|
||
diag bmw <addr> <hex...> raw BMW request on 0x6F1, read-only services only
|
||
diag raw on | off CANRAW frame logging
|
||
diag status
|
||
```
|
||
|
||
### `difflock` — diff-lock inputs (DI0 = rear, DI1 = front; Settings → System switch, default OFF)
|
||
```
|
||
difflock status rear / front LOCKED or open, raw CH422G IO byte, read counters
|
||
difflock on | off same as the switch (saved)
|
||
difflock invert on | off polarity, same as the "Inverted" switch (saved): on = NO current means locked
|
||
```
|
||
Wiring: lock wire → DI0 / DI1, `DI_COM` → vehicle ground. If the screen shows locked when unlocked (the Patrol's ground-switched lamp wires do this), turn **Inverted** on. Details: wiki `diff-lock-inputs`.
|
||
|
||
### `reverse` — reverse-light relay on DO0 (follows the gear lever in R; default ON, no Settings row - the System page is full)
|
||
```
|
||
reverse status enabled?, DO0 on/off, lever / ignition / CAN as seen, write counters
|
||
reverse on | off enable / disable (saved); off = DO0 stays off
|
||
reverse force on | off drive DO0 regardless of the lever, for the wiring check (not saved, ends after 60 s)
|
||
reverse force auto back to the lever
|
||
```
|
||
Wiring: relay coil between +12 V and `DO0`, flyback diode across the coil (stripe to +12 V); the coil current returns through the board's `GND`. ≤ 450 mA per output. Details: wiki `reverse-lights-output`.
|
||
|
||
### `vehicle` — road speed from the gearbox output shaft (Settings → Vehicle; saved in NVS)
|
||
```
|
||
vehicle show final drive ratio, tyre circumference, and what 1000 shaft rpm comes to
|
||
vehicle set final <x.xx> final drive (differential) ratio, 2.00..8.00 - 4.11 on this Patrol
|
||
vehicle set tyre <mm> tyre rolling circumference, 1500..3500 mm (265/70 R16 ≈ 2440)
|
||
vehicle reset back to 4.11:1 and 2440 mm
|
||
```
|
||
### `ecu` — which engine ECU (DDE) this board is on (read once, saved in NVS)
|
||
```
|
||
ecu show stored identification: part number, software date, VIN prefix; or UNKNOWN ECU
|
||
ecu dump the stored KWP 1A 86 / 1A 80 payloads in hex
|
||
ecu forget drop them - UNKNOWN ECU until read again (do this when the board moves to another car)
|
||
```
|
||
While nothing is stored the board asks the DDE once (`1A 86`, then `1A 80`, up to 3 tries each per boot) as soon as CAN is on, the ignition has been on for 5 s, `sim` is off and no scan tool has spoken for 3 s. Once stored it never asks again. Same thing from the screen: Settings → Vehicle shows the Engine ECU line and has a **Re-read ECU** button. With a Launch connected the board also sees its `1A 80` reads and shows **ECU CHANGED?** if they differ from the stored block.
|
||
|
||
### `sim` — bench values for the screens (never saved, off at boot, nothing transmitted)
|
||
```
|
||
sim torque <Nm> [rpm <n>] [shaft <rpm>] e.g. sim torque 350 rpm 2500 shaft 1200
|
||
sim rpm <n> | sim shaft <rpm> change one value, the rest stays
|
||
sim status
|
||
sim off
|
||
```
|
||
Feeds the Sport gauges, the Driveline's torque / rpm / output / speed and the Vehicle page preview as if the ignition were on; the Driveline's chip reads `IGN SIM` and the Sport screen says SIMULATION meanwhile. The Inst. Cluster is not affected (use `cfg override` for its outputs).
|
||
|
||
Speed (km/h) = output shaft rpm ÷ ratio × circumference (m) × 60 ÷ 1000. The shaft rpm is still the provisional 0x0BA × 0.1074, so the screens show `~km/h`. The Sport screen's hp = Nm × rpm ÷ 9.5488 ÷ 745.7.
|
||
|
||
### Diagnostics
|
||
```
|
||
mem internal heap, PSRAM, LVGL pool
|
||
perf one PERF line (fps, flush cost, CPU idle, heap, panel vsync)
|
||
perf on [sec] | perf off
|
||
```
|
||
|
||
---
|
||
|
||
## 5. Inst. Cluster console
|
||
|
||
```
|
||
help
|
||
link status pairing, A's MAC, STATUS/SECURE counters, credentials
|
||
link unpair forget the pairing key (re-pair from A over the wire)
|
||
wifi status stored network name (password never shown)
|
||
wifi forget
|
||
ota status version, slot, rollback state
|
||
ota check join Wi-Fi, ask Gitea for the latest release, leave
|
||
ota install [force] download, verify, flash, reboot (parked only)
|
||
ota rollback
|
||
```
|
||
B prints a stats line every 5 s (`applied=… uart … espnow …`) — `uart alive` means the wire works.
|
||
|
||
---
|
||
|
||
## 6. Procedures
|
||
|
||
### Pair a Inst. Cluster (once per board pair)
|
||
1. Wire: 5B terminal `485_A` → B `IO1`, GND → GND (a real wire, not just the USB hub), 5B's 120 Ω switch OFF. Both powered. B's stats line must say `uart alive`.
|
||
2. A console: `link pair`. Within 5 s A logs `Inst. Cluster confirmed pairing (fingerprint XXXX)`; B logs `PAIRED over the wire`.
|
||
3. `link status` on A: `key XXXX (matches)`. About 15 s later `Wi-Fi creds yes` (A pushes them by itself; `link creds` forces it).
|
||
|
||
The key lives in NVS on both boards and survives every flash and update. Re-pair only after an NVS erase, `link unpair`, or a board swap.
|
||
|
||
### Release a version
|
||
```powershell
|
||
git tag -a vX.Y.Z -m "what changed"
|
||
git push --follow-tags origin main # A (B: origin master)
|
||
```
|
||
One push, so only the tag build runs. Gitea builds, signs (`BMW_NISSAN_FIRMWARE_SIGNING_KEY`) and publishes `firmware.bin` + `manifest.txt`: A takes 7–20 min, B 2–5 min. Check: `https://git.infra.msai.al/<owner>/<repo>/releases`. Version strings must stay under 16 characters.
|
||
|
||
### Update A from the screen
|
||
Settings → Updates → Main CTRL → **Check** → **Install vX.Y.Z** (parked, Wi-Fi joined). Progress bar, restart, `A vX.Y.Z` bottom-right. A reset in the first 30 s rolls back.
|
||
|
||
### Update B from the screen
|
||
Settings → Updates → Inst. Cluster → **Check** → **Install** (A on Wi-Fi, parked, B paired). B's round screen shows `Updating vX.Y.Z N%`, the card on A shows the percentage, B restarts and confirms itself after 30 s. Console equivalent: `link ota check`, `link ota install`.
|
||
|
||
### Something is wrong after an update
|
||
`ota rollback` on the affected controller's console (B: `link ota rollback` from A also works). A reset within 30 s of the first boot of a new image rolls back on its own.
|
||
|
||
---
|
||
|
||
## 7. Git on several machines
|
||
|
||
Fetch before you start on another machine; the wikis are edited from every machine:
|
||
```powershell
|
||
git fetch origin
|
||
git status -sb # "behind" → git pull --ff-only before touching anything
|
||
```
|