87801c593c
Firmware — make the board a working CAN sniffer and fix real bugs: - can_driver: add raw candump-style logger (CANRAW,<ts>,<id>,<extd>,<dlc>,<hex>), capturing every frame incl. unknown IDs for offline decoding. Single atomic write per frame. - serial_lock: new global serial mutex so concurrent task writes (CAN logger, UART 5Hz log, heartbeat) no longer splice mid-line. Corruption 3.2% -> 1.4%. - Fix CAN toggle: the switch had no event handler registered, so it never started CAN and reverted on screen change. Wire up onCANBusToggle. - platformio: route Serial to native USB-CDC (USB_MODE=1, CDC_ON_BOOT=1) so the ~486 frame/s stream isn't throttled by the 115200 UART ceiling; bump monitor baud to 921600. - tools/fix_toolchain_path.py: pre-build workaround for pioarduino nesting the Xtensa toolchain bin under a subdir that never reaches PATH. - Correct misleading "LISTEN_ONLY" log string (driver runs TWAI_MODE_NORMAL). Wiki — ingest the first live capture off the real swap bus: - raw/can-capture-2026-07-15-gearshift.csv (20,596 frames) + sources page. - Research map CONFIRMED: 0x1D0/0x1D2/0x0B5/0x3B4 all live; placeholder IDs (0x4F/0x55/0x201/0x1001/0x101F) verified absent; 0x130/0x304/0x192 absent. - 0x1D0 b0 coolant drifts up (37->40C, -48 holds); 0x1D0 b1 oil temp = 0xFF. - 0x1D2 gear encoding resolved: DLC 6, byte0 gear codes (E1=P, B4=N, 78=D live). - Corrected LISTEN_ONLY -> NORMAL/ACK across pages; documented non-isolated TJA1051 grounding requirement. Updated index + log. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
4.2 KiB
Markdown
49 lines
4.2 KiB
Markdown
---
|
||
type: concept
|
||
tags: [can-bus, reverse-engineering]
|
||
updated: 2026-07-16
|
||
---
|
||
|
||
# CAN Bus Integration
|
||
|
||
The core technical challenge of the project: reading real data from the [[bmw-m57n-engine]]'s CAN bus and mapping it into the display's data structure.
|
||
|
||
## Current firmware state (repo)
|
||
|
||
- ESP32-S3 TWAI peripheral, 500 kbps.
|
||
- Falls back to dummy simulated data when CAN is off or failing.
|
||
- **Raw frame logger (repo, added 2026-07-15):** every received frame is streamed over USB-CDC as `CANRAW,<ts_ms>,<id>,<extd>,<dlc>,<hex>`, serialized by a mutex so lines don't interleave. This is how [[can-capture-2026-07-15]] was taken — the board is now its own CAN sniffer. Logs are tethered-only (no onboard SD recording yet; the board has a microSD slot for a future "black box").
|
||
- Configured message map:
|
||
|
||
> [!warning] The firmware is NOT in LISTEN_ONLY mode — it ACKs the bus
|
||
> Despite older comments/docs saying "LISTEN_ONLY", the TWAI driver is installed in **`TWAI_MODE_NORMAL`** `(repo)` — a deliberate choice so it sends ACK bits and stops transmitters from flooding retries. Consequences: (1) the board is an **active bus participant**, not a passive sniffer — correct on a live multi-ECU bus, but do NOT power it in ACK mode on a bench with a single other node and no termination. (2) The onboard **TJA1051T/3 transceiver is non-isolated**, so its ground MUST be common with the vehicle (simplest: power the board from vehicle 12 V, whose negative *is* the reference). A flaky ground on an actively-ACKing node causes intermittent bus errors that look like data problems. → [[esp32-s3-touch-lcd-5b]]
|
||
|
||
| ID | Byte(s) | Mapped to |
|
||
|--------|---------|-----------|
|
||
| 0x4F | 0 | Coolant temp |
|
||
| 0x55 | 7 | Oil temp |
|
||
| 0x201 | 3 | Gearbox oil temp |
|
||
| 0x1001 | 0, 1 | Gear position / gear number |
|
||
| 0x101F | 0–1 | Battery voltage (16-bit BE) |
|
||
|
||
> [!warning] These IDs are almost certainly placeholders, not real BMW IDs.
|
||
> Two red flags: (1) `0x1001` and `0x101F` exceed `0x7FF`, the maximum for standard 11-bit CAN identifiers — BMW E-series PT-CAN of the M57N era uses 11-bit frames `(unverified)`, so these would never match. (2) None of the five IDs appear in community BMW reverse-engineering documentation. The map needs to be rebuilt from real bus captures or a trustworthy source before any of the displayed data can be believed.
|
||
|
||
> [!info] Research done 2026-07-15, then CONFIRMED live
|
||
> Web research produced a replacement candidate map — **0x1D0** (coolant + oil temp), **0x1D2** (gear), **0x0B5** (gearbox temp), **0x3B4** (battery voltage) — with confidence ratings and two layout disputes to settle on the bench. Full table and sources: [[can-id-candidates]]. The first live capture ([[can-capture-2026-07-15]]) confirmed all four IDs are present and resolved the 0x1D2 gear encoding. Fault codes are NOT passively broadcast (diagnostic requests required) — the `fault_codes` field needs a design decision.
|
||
|
||
## Verification plan
|
||
|
||
1. ~~Get a raw capture of the actual bus. File the log into `raw/`.~~ ✅ **Done** 2026-07-15 with the board's own logger → `raw/can-capture-2026-07-15-gearshift.csv`, summarized in [[can-capture-2026-07-15]]. **Still needed: a cold-start + confirmed-engine-running capture** to lock coolant/battery scaling (the first capture's engine state was unconfirmed and the battery/oil-temp bytes were dormant).
|
||
2. Identify candidate IDs by watching which bytes track known physical behavior (rev the engine, warm it up, shift gears). *In progress:* gear (0x1D2) done; coolant drift seen; RPM/battery pending. Use a **differential capture** for gear (hold each position, diff steady states) rather than a continuous sweep.
|
||
3. Cross-check against community DBC files / reverse-engineering wikis for the donor vehicle. ✅ done → [[can-id-candidates]].
|
||
4. Update `automotive_data.h` `(repo)` and mark each mapping `(verified)` here only after it matches reality on the live bus.
|
||
|
||
## Signal-source caveat
|
||
|
||
Coolant/oil temp come from the DDE, but **gearbox temp and gear position come from the EGS module** — they only exist on the bus if the swap retained the automatic transmission and its ECU. `(unverified)` → [[open-questions]]
|
||
|
||
## Related
|
||
|
||
[[bmw-m57n-engine]] · [[esp32-s3-touch-lcd-5b]] · [[open-questions]]
|