CAN raw logger + toggle fix; wiki: first live capture confirms ID map

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>
This commit is contained in:
2026-07-16 12:24:25 +02:00
parent f7a2d1c3bd
commit 87801c593c
19 changed files with 20929 additions and 26 deletions
+3
View File
@@ -11,6 +11,9 @@ build/
*.elf
*.map
# Serial monitor capture logs (transient; raw CAN dumps worth keeping go in wiki/raw/)
logs/
# OS files
.DS_Store
Thumbs.db
+23
View File
@@ -90,6 +90,29 @@ namespace CANDriver {
*/
bool isActive();
/**
* Enable/disable raw frame logging (candump-style capture of EVERY frame).
* When enabled, each received frame is printed to Serial as a compact,
* greppable, re-parseable line prefixed "CANRAW," (see emitRawFrame()).
* Intended for CAN ID discovery: capture a drive, save the serial stream
* to a file, and analyze offline.
* @param enabled true to log every frame
*/
void setRawLogging(bool enabled);
/**
* @return true if raw frame logging is currently enabled
*/
bool isRawLogging();
/**
* Enable/disable verbose per-frame DECODED logging (human-prose ESP_LOG
* lines for known/unknown IDs). Noisy; off by default so it doesn't drown
* the raw capture stream. Independent of setRawLogging().
* @param enabled true to log decoded values per frame
*/
void setVerboseDecode(bool enabled);
/**
* UI event handler for CAN toggle switch
* @param e LVGL event
+10
View File
@@ -98,6 +98,15 @@ void ui_event_Toggle_Wifi_Switch(lv_event_t * e)
}
}
void ui_event_Toggle_CAN_Bus_Switch(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
if(event_code == LV_EVENT_RELEASED) {
onCANBusToggle(e);
}
}
void ui_event_Toggle_Debug_Switch(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
@@ -428,6 +437,7 @@ void ui_Settings_Screen_screen_init(void)
lv_obj_add_event_cb(ui_Toggle_UART_Switch, ui_event_Toggle_UART_Switch, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Toggle_Wifi_Switch, ui_event_Toggle_Wifi_Switch, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Toggle_CAN_Bus_Switch, ui_event_Toggle_CAN_Bus_Switch, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Toggle_Debug_Switch, ui_event_Toggle_Debug_Switch, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Select_SSID_BTN, ui_event_Select_SSID_BTN, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Settings_Screen, ui_event_Settings_Screen, LV_EVENT_ALL, NULL);
+1
View File
@@ -12,6 +12,7 @@ extern "C" {
void onUARTToggle(lv_event_t * e);
void onWifiToggle(lv_event_t * e);
void onCANBusToggle(lv_event_t * e);
void onDebugToggle(lv_event_t * e);
void onSelectSSID(lv_event_t * e);
+16 -2
View File
@@ -31,7 +31,9 @@ board = esp32-s3-wroom-1-n16r8
; Upload & Monitor Settings
; ----------------------------------------------------------------------------
upload_speed = 921600
monitor_speed = 115200
; 921600 for the fallback-UART case; ignored (nominal) when Serial = native USB
; CDC, where throughput is USB Full-Speed (~1 MB/s) and gates nothing.
monitor_speed = 921600
monitor_filters = esp32_exception_decoder
; ----------------------------------------------------------------------------
@@ -57,6 +59,16 @@ build_flags =
; Arduino Core debug level (0=None, 1=Error, 3=Info, 5=Verbose)
-DCORE_DEBUG_LEVEL=3
; USB / Serial routing (deterministic — do not rely on core defaults)
; USB_MODE=1 -> Hardware CDC + JTAG (built-in USB-Serial-JTAG, the
; 303A:1001 port this board enumerates as)
; CDC_ON_BOOT=1 -> `Serial` maps to that native USB CDC, NOT UART0 pins.
; Gives ~1 MB/s throughput so the CANRAW frame dump
; keeps up with a busy bus (UART0 @115200 would drop
; frames), and keeps GPIO43/44 free for the RS485 UART1.
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
; LVGL configuration
-DLV_CONF_INCLUDE_SIMPLE
-DLV_LVGL_H_INCLUDE_SIMPLE
@@ -88,6 +100,8 @@ build_flags =
build_unflags =
-std=gnu++11
extra_scripts =
; Pre-build workaround: put the nested Xtensa toolchain bin on PATH.
; See tools/fix_toolchain_path.py for the full explanation.
extra_scripts = pre:tools/fix_toolchain_path.py
build_type = release
+70 -6
View File
@@ -8,6 +8,7 @@
#include "drivers/can_driver.h"
#include "modules/uart_manager.h"
#include "modules/settings_manager.h"
#include "modules/serial_lock.h"
#include "esp_log.h"
// Import shared data from UARTManager namespace
@@ -33,6 +34,13 @@ static QueueHandle_t g_can_event_queue = NULL;
static can_stats_t g_can_stats = {0};
static bool g_uart_auto_stopped = false; // Track if UART was auto-stopped due to CAN timeout
// Raw frame logging: capture EVERY frame (candump-style) for offline CAN ID
// discovery. Default ON since discovery is the current priority.
static bool g_raw_logging = true;
// Verbose per-frame DECODED prose logging. Default OFF: it's redundant with
// (and would drown) the raw capture stream. Enable only for quick eyeballing.
static bool g_verbose_decode = false;
// ============================================================================
// PRIVATE FUNCTIONS
// ============================================================================
@@ -120,6 +128,44 @@ static bool parseCANMessage(const twai_message_t& message) {
return parsed;
}
/**
* @brief Emit one raw CAN frame as a compact, greppable, re-parseable line.
*
* Format (CSV, one frame per line):
* CANRAW,<ts_ms>,<id_hex>,<extd>,<dlc>,<data_hex>
* where:
* ts_ms = millis() timestamp (relative to boot)
* id_hex = arbitration ID in hex, no 0x prefix (3 digits min for 11-bit)
* extd = 1 if 29-bit extended ID, 0 if 11-bit standard
* dlc = data length code (0..8)
* data_hex = payload bytes, uppercase hex, no separators (e.g. 1122AABB)
*
* The "CANRAW," prefix lets you filter these out of the mixed ESP_LOG serial
* stream: pio device monitor > drive.log then grep CANRAW, drive.log
*
* @param message Received TWAI message
*/
static void emitRawFrame(const twai_message_t& message) {
char buf[72];
int n = snprintf(buf, sizeof(buf), "CANRAW,%lu,%03lX,%u,%u,",
(unsigned long)millis(),
(unsigned long)message.identifier,
(unsigned)(message.extd ? 1 : 0),
(unsigned)message.data_length_code);
for (int i = 0; i < message.data_length_code && n < (int)sizeof(buf) - 4; i++) {
n += snprintf(buf + n, sizeof(buf) - n, "%02X", message.data[i]);
}
// Append the line terminator into the SAME buffer so the whole frame goes
// out in one Serial.write() — no other task can splice into the middle.
buf[n++] = '\r';
buf[n++] = '\n';
// Serialize against all other serial writers so lines never interleave.
SerialLock::lock();
Serial.write((const uint8_t*)buf, n);
SerialLock::unlock();
}
/**
* @brief Handle received CAN message
* @param message TWAI message structure
@@ -128,6 +174,11 @@ static void handleRxMessage(twai_message_t& message) {
g_can_stats.messages_received++;
g_can_stats.last_receive_time = millis();
// Raw capture FIRST, before parse — logs every frame including unknown IDs
if (g_raw_logging) {
emitRawFrame(message);
}
// Auto-restart UART if it was stopped due to CAN timeout
if (g_uart_auto_stopped) {
ESP_LOGI("CANDrv", "✓ CAN messages resumed, auto-restarting UART");
@@ -139,9 +190,8 @@ static void handleRxMessage(twai_message_t& message) {
if (parseCANMessage(message)) {
g_can_stats.messages_parsed++;
// DETAILED LOGGING (TEMPORARY FOR DEBUGGING)
// Log EVERY parsed message with actual values
if (xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
// Per-frame decoded prose — off by default (redundant with raw capture)
if (g_verbose_decode && xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
ESP_LOGI("CANDrv", "✓ RX CAN ID=0x%X → Coolant:%d.%d°C, Oil:%d.%d°C, Gearbox:%d.%d°C, Batt:%d.%02dV, Gear:%d [%d/%d]",
message.identifier,
g_automotive_data.coolant_temp / 10, abs(g_automotive_data.coolant_temp % 10),
@@ -153,8 +203,8 @@ static void handleRxMessage(twai_message_t& message) {
g_can_stats.messages_received);
xSemaphoreGive(g_data_mutex);
}
} else {
// Unknown message ID - log ALL unknown messages for debugging
} else if (g_verbose_decode) {
// Unknown message ID (raw capture already logged it; this is just prose)
ESP_LOGW("CANDrv", "⚠ Unknown CAN ID=0x%X (DLC=%d) [%d total]",
message.identifier,
message.data_length_code,
@@ -190,7 +240,7 @@ static bool initTWAI() {
ESP_LOGE("CANDrv", "Failed to install TWAI driver");
return false;
}
ESP_LOGI("CANDrv", "TWAI driver installed (GPIO%d/GPIO%d, 500Kbps, LISTEN_ONLY)",
ESP_LOGI("CANDrv", "TWAI driver installed (GPIO%d/GPIO%d, 500Kbps, NORMAL/ACK)",
CAN_TX_PIN, CAN_RX_PIN);
// Start TWAI driver
@@ -390,6 +440,20 @@ bool isActive() {
return g_can_active;
}
void setRawLogging(bool enabled) {
g_raw_logging = enabled;
ESP_LOGI("CANDrv", "Raw frame logging %s", enabled ? "ENABLED" : "disabled");
}
bool isRawLogging() {
return g_raw_logging;
}
void setVerboseDecode(bool enabled) {
g_verbose_decode = enabled;
ESP_LOGI("CANDrv", "Verbose decode logging %s", enabled ? "ENABLED" : "disabled");
}
void onCANToggle(lv_event_t *e) {
lv_obj_t *target = lv_event_get_target(e);
if (target == NULL) {
+12 -1
View File
@@ -8,6 +8,7 @@
#include "modules/settings_manager.h" // Settings manager module
#include "modules/ui_state_manager.h" // UI state manager module
#include "modules/meters_manager.h" // Meters display manager module
#include "modules/serial_lock.h" // Global serial write mutex
// ============================================================================
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
@@ -166,9 +167,17 @@ void initializeHomeScreenMeters() {
// ============================================================================
void setup()
{
Serial.begin(115200);
// Baud is ignored under native USB CDC (Serial = HWCDC); kept high so the
// CANRAW dump isn't throttled if Serial ever falls back to UART0.
// NOTE: do NOT add `while(!Serial)` — the board must boot headless in-car
// with no host attached.
Serial.begin(921600);
delay(2000); // Longer delay for serial to stabilize
// Create the global serial write mutex before any task starts, so CAN raw
// frames and other tasks' log lines never interleave on the shared port.
SerialLock::init();
// Use ESP_LOG instead of Serial.println to match library output
ESP_LOGI("MAIN", "=== ESP32-S3-LCD-5B Minimal Setup ===");
ESP_LOGI("MAIN", "Firmware compiled: %s %s", __DATE__, __TIME__);
@@ -229,7 +238,9 @@ void loop()
// Debug: Print heartbeat every 5 seconds
if (millis() - last_print > 5000) {
SerialLock::lock();
ESP_LOGI("LOOP", "Heartbeat - system running");
SerialLock::unlock();
last_print = millis();
}
+33
View File
@@ -0,0 +1,33 @@
/**
* serial_lock.cpp
*
* Implementation of the global serial write mutex. See serial_lock.h.
*/
#include "modules/serial_lock.h"
namespace SerialLock {
static SemaphoreHandle_t g_serial_mutex = NULL;
void init() {
if (g_serial_mutex == NULL) {
g_serial_mutex = xSemaphoreCreateMutex();
}
}
bool lock(TickType_t timeout) {
// Not initialized yet (early boot): don't block, just proceed.
if (g_serial_mutex == NULL) {
return true;
}
return xSemaphoreTake(g_serial_mutex, timeout) == pdTRUE;
}
void unlock() {
if (g_serial_mutex != NULL) {
xSemaphoreGive(g_serial_mutex);
}
}
} // namespace SerialLock
+42
View File
@@ -0,0 +1,42 @@
/**
* serial_lock.h
*
* A single global mutex that serializes writes to the USB-CDC `Serial` port.
*
* Multiple FreeRTOS tasks (CAN raw logger, UART task, main loop heartbeat, ...)
* write to the same serial output. Without coordination their writes interleave
* and splice mid-line, corrupting the CANRAW capture stream. Every frequent
* writer takes this lock around its full line so lines never interleave.
*
* Usage:
* SerialLock::lock();
* Serial.write(...); // or ESP_LOGx(...)
* SerialLock::unlock();
*
* Call SerialLock::init() once early in setup(), before any task starts. Before
* init (or if creation fails) lock()/unlock() are safe no-ops.
*/
#ifndef _SERIAL_LOCK_H
#define _SERIAL_LOCK_H
#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
namespace SerialLock {
/** Create the mutex. Idempotent; call once in setup() before tasks start. */
void init();
/**
* Acquire the serial lock.
* @param timeout ticks to wait (default: wait forever)
* @return true if acquired (also true if the lock isn't initialized yet)
*/
bool lock(TickType_t timeout = portMAX_DELAY);
/** Release the serial lock (no-op if not held / not initialized). */
void unlock();
}
#endif // _SERIAL_LOCK_H
+4
View File
@@ -4,6 +4,7 @@
#include "uart_manager.h"
#include "settings_manager.h"
#include "serial_lock.h"
namespace UARTManager {
@@ -115,6 +116,8 @@ static bool sendUARTPacket() {
// Debug output - first 5 packets, then every 10
if (g_uart_stats.packets_sent <= 5 || g_uart_stats.packets_sent % 10 == 0) {
// Hold the serial lock so this line can't splice into a CANRAW frame
SerialLock::lock();
ESP_LOGI("UARTTask", "✓ TX Packet #%d (Gear:%s, Temps:%d.%d/%d.%d/%d.%d°C, Batt:%d.%02dV, Debug:%s) [%d bytes on GPIO%d]",
packet.data.packet_id,
gear_to_string((gear_position_t)packet.data.gear_position),
@@ -124,6 +127,7 @@ static bool sendUARTPacket() {
packet.data.battery_voltage / 100, packet.data.battery_voltage % 100,
packet.data.debug_enabled ? "ON" : "OFF",
bytes_written, UART_TX_PIN);
SerialLock::unlock();
}
return true;
} else {
+35
View File
@@ -0,0 +1,35 @@
# fix_toolchain_path.py (PlatformIO pre-build extra script)
#
# WORKAROUND for a pioarduino first-install issue on this machine.
#
# The Xtensa toolchain (toolchain-xtensa-esp-elf) extracts its binaries to a
# NESTED folder:
# <pkg>/xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc.exe (and g++, ar, ld, ...)
# but pioarduino's export_paths PATH-injection did not reach the SCons build
# environment, so the compiler was invoked by bare name and the shell reported
# "'xtensa-esp32s3-elf-gcc' is not recognized as an internal or external command".
#
# This script finds the toolchain package dir dynamically and prepends its real
# bin/ folder to the build PATH. It is a no-op if the bin folder isn't nested
# (e.g. after a future clean reinstall that flattens the layout), so it's safe
# to leave in place.
#
# Proper long-term fix (optional): remove ~/.platformio/packages/toolchain-xtensa-esp-elf
# and ~/.espressif, then rebuild so pioarduino re-runs idf_tools install cleanly.
Import("env") # noqa: F821 (injected by PlatformIO/SCons)
from os.path import isdir, join
platform = env.PioPlatform()
toolchain_pkg = platform.get_package_dir("toolchain-xtensa-esp-elf")
if toolchain_pkg:
nested_bin = join(toolchain_pkg, "xtensa-esp-elf", "bin")
if isdir(nested_bin):
env.PrependENVPath("PATH", nested_bin)
print("[fix_toolchain_path] Prepended toolchain bin to PATH: %s" % nested_bin)
else:
print("[fix_toolchain_path] Nested bin not found (layout OK?): %s" % nested_bin)
else:
print("[fix_toolchain_path] toolchain-xtensa-esp-elf package dir not found")
+3 -2
View File
@@ -1,6 +1,6 @@
---
type: index
updated: 2026-07-15
updated: 2026-07-16
---
# Index
@@ -20,7 +20,7 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
## Synthesis
- [[can-id-candidates]] — **the E60/E65 CAN ID map from web research**: 0x1D0/0x1D2/0x0B5/0x3B4 with confidence ratings, layout disputes, sources; fault codes not passively broadcast
- [[can-id-candidates]] — **the E60/E65 CAN ID map from web research, now CONFIRMED live**: 0x1D0/0x1D2/0x0B5/0x3B4 present on the real bus; placeholder IDs verified absent; fault codes not passively broadcast
- [[open-questions]] — the research frontier: bench-verify the candidate IDs, operating temp, transient protection, fault-code design decision
## Sources
@@ -28,3 +28,4 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
- [[esp32-s3-touch-lcd-5b-waveshare-wiki]] — official Waveshare product wiki (ingested 2026-07-15); answered CAN-transceiver and power questions, raised the 0–65 °C operating-temp concern
- [[e60-vfl-can-codes-xlsx]] — community E60 pre-facelift CAN table (ingested 2026-07-15); E60-specific confirmation of 0x1D0/0x3B4, new 0x304 gear-lever candidate
- [[listen-and-send-pid-arduino]] — Arduino ELM327→E46-cluster sketch (ingested 2026-07-15); technique reference for a diagnostic-request fallback, not ID evidence
- [[can-capture-2026-07-15]] — **first live CAN dump off the real swap bus** (captured with the board's own logger); confirms 15 IDs incl. all four signal IDs, resolves the 0x1D2 gear encoding, verifies placeholder IDs absent; raw at `raw/can-capture-2026-07-15-gearshift.csv`
+4
View File
@@ -21,3 +21,7 @@ Deep-research workflow ran (interrupted twice by session task-loss on Windows; ~
## [2026-07-15] update | Donor and target vehicle confirmed by user
User confirmed: donor chassis is **E60/E65 (2003+)**, transmission is a **BMW auto with EGS on the CAN bus**, target vehicle is a **Nissan Patrol**. Created [[nissan-patrol-swap]]; updated [[bmw-m57n-engine]] (E46-era candidate IDs flagged as probably wrong generation) and [[open-questions]] (three questions moved to Answered). Next: web research for E60-generation PT-CAN broadcast IDs.
## [2026-07-16] ingest | First live CAN capture — research map CONFIRMED
First real dump off the swap's bus, taken with the board's **own new raw-frame logger** (`(repo)`; USB-CDC stream, serial mutex, ~486 frame/s, ~1.4% line loss). Raw filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 frames) → [[can-capture-2026-07-15]]. Findings: 15 IDs live incl. **all four researched signal IDs** (0x1D0, 0x1D2, 0x0B5, 0x3B4) + bonus 0x0AA/0x0BA; firmware's placeholder IDs (0x4F/0x55/0x201/0x1001/0x101F) **verified absent**; researched-but-absent: 0x130/0x304/0x192. **0x1D0 b0** drifts 0x55→0x58 (coolant −48, ~37→40 °C); **0x1D0 b1 = 0xFF** (oil temp unpopulated). **0x1D2 gear encoding resolved**: DLC 6, byte0 whole-byte codes (0xE1=P, 0xB4=N, 0x78=D seen live). **0x3B4** at ~5 s rate but payload dormant (0xFF) — engine state unconfirmed. Updated [[can-id-candidates]], [[can-bus-integration]], [[esp32-s3-touch-lcd-5b]], [[open-questions]], index. Also corrected a firmware fact across pages: driver runs **`TWAI_MODE_NORMAL` (ACKs the bus), not LISTEN_ONLY**; TJA1051 is non-isolated → must share vehicle ground. Next: cold-start + confirmed-engine-running capture to lock coolant/battery scaling; use differential (per-position) captures for gear.
+11 -7
View File
@@ -1,7 +1,7 @@
---
type: concept
tags: [can-bus, reverse-engineering]
updated: 2026-07-15
updated: 2026-07-16
---
# CAN Bus Integration
@@ -10,10 +10,14 @@ The core technical challenge of the project: reading real data from the [[bmw-m5
## Current firmware state (repo)
- ESP32-S3 TWAI peripheral, 500 kbps, **LISTEN_ONLY** mode (cannot disturb the bus — good).
- 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 |
@@ -25,14 +29,14 @@ The core technical challenge of the project: reading real data from the [[bmw-m5
> [!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
> 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]]. Fault codes are NOT passively broadcast (diagnostic requests required) — the `fault_codes` field needs a design decision.
> [!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 (candump / Savvy CAN / cheap USB-CAN dongle) with the engine running. File the log into `raw/`.
2. Identify candidate IDs by watching which bytes track known physical behavior (rev the engine, warm it up, shift gears).
3. Cross-check against community DBC files / reverse-engineering wikis for the donor vehicle.
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
+13 -4
View File
@@ -1,13 +1,22 @@
---
type: synthesis
tags: [can-bus, reverse-engineering, e60, research]
updated: 2026-07-15
updated: 2026-07-16
---
# E60/E65 CAN ID Candidates (Research Results)
Findings from the 2026-07-15 deep-research run (95 claims extracted from ~15 sources, 30 adversarially verified against primary repos before the run was interrupted; synthesis done manually from the journal). These are the IDs to program into the firmware **for bench testing against a live capture** — none are `(verified)` until seen on the actual swap's bus.
> [!success] Live capture 2026-07-15 — the map is CONFIRMED on the real bus
> First dump off the actual swap's bus ([[can-capture-2026-07-15]]) validates the research:
> - **All four signal IDs are live**: `0x1D0`, `0x1D2`, `0x0B5`, `0x3B4` (+ bonus `0x0AA`, `0x0BA`). (verified: present)
> - The firmware's placeholder IDs are **absent** — confirmed junk. (verified: absent)
> - `0x1D0` byte0 drifts up `0x55→0x58` = coolant warming (−48 scaling holds). **Oil temp `0x1D0` byte1 = `0xFF`** (not populated here).
> - `0x1D2` **encoding dispute resolved**: DLC 6, byte0 whole-byte gear codes — `0xE1`=P, `0xB4`=N, `0x78`=D seen live.
> - Absent despite being researched: `0x130`, `0x304`, `0x192`.
> - Still needs a **cold-start + confirmed-engine-running** capture to lock scaling on coolant/battery. See the source page for the full table.
## The map (replaces the firmware's placeholder IDs)
| Signal | CAN ID | Bytes | Scaling | Sender | Rate | Confidence |
@@ -29,7 +38,7 @@ Findings from the 2026-07-15 deep-research run (95 claims extracted from ~15 sou
## Field checklist for the live capture session
Setup: 500 kbps, listen-only, board's 120 Ω termination switch **OFF**, tap CAN-H/CAN-L on the PT-CAN. **Log everything raw for the whole session** and save the dump into `wiki/raw/` — even IDs we don't care about yet.
Setup: 500 kbps, board's 120 Ω termination switch **OFF**, common ground with the vehicle, tap CAN-H/CAN-L on the PT-CAN. (Note: the firmware runs `TWAI_MODE_NORMAL` and ACKs the bus — not listen-only — see [[can-bus-integration]].) **Log everything raw for the whole session** and save the dump into `wiki/raw/` — even IDs we don't care about yet.
| Test | Watch | Confirms |
|------|-------|----------|
@@ -73,8 +82,8 @@ Also useful: an E60 forum claim `(unverified)` that arbitration IDs are identica
- No source used an actual **E60 M57N diesel** end-to-end; the closest anchors are the E60 tool32 table (lists DDE1 as sender for 0x1D0/0x3B4), the E60 VFL spreadsheet (real pre-facelift E60, engine variant unknown), and the M57 dieslg8 project (different chassis generation). Engine-side layouts are inferred from petrol DME captures of the same bus generation.
- **Oil temp and gearbox oil temp remain the weakest signals** — absent from both E60-specific sources; only the E9x DBC and E65 docs place oil temp at 0x1D0 byte 1, and only the E9x DBC has gearbox temp (0x0B5 byte 7, offset disputed).
- Firmware's current IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are contradicted by every source — confirmed placeholders. → [[can-bus-integration]]
- Promotion to `(verified)` requires a live capture from the swap's bus: warm the engine and watch 0x1D0 byte 0 climb, shift through P/R/N/D and watch 0x1D2.
- Firmware's current IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are contradicted by every source AND **confirmed absent from the live bus** (verified, 2026-07-15) — definitively placeholders. → [[can-bus-integration]]
- Promotion to `(verified)` requires a live capture from the swap's bus: warm the engine and watch 0x1D0 byte 0 climb, shift through P/R/N/D and watch 0x1D2. **Partially done** 2026-07-15 ([[can-capture-2026-07-15]]): IDs + 0x1D2 gear codes verified; coolant/battery scaling still needs a cold-start capture with confirmed engine state.
## Related
+4 -2
View File
@@ -1,7 +1,7 @@
---
type: entity
tags: [hardware, waveshare, display]
updated: 2026-07-15
updated: 2026-07-16
---
# Waveshare ESP32-S3-Touch-LCD-5B
@@ -28,8 +28,10 @@ Controller A of the [[dual-controller-architecture]] — the main in-cabin displ
## CAN interface (source: waveshare-wiki)
- **Onboard TJA1051T/3/1J transceiver**, CAN 2.0, on a 3.5 mm terminal block — wire CAN-H/L straight in. ✅ resolves the transceiver question
- **Non-isolated** — its ground must be common with the vehicle. Simplest: power the board from vehicle 12 V (the 7–36 V input's negative *is* the CAN reference). Grounding-only + USB power also works, but keep the logging laptop **on battery** to avoid a mains-earth ↔ chassis ground loop.
- **120 Ω termination switch, OFF by default — leave it off** when tapping an existing vehicle bus (the bus is already terminated at both ends).
- Firmware drives it via TWAI on GPIO 15 TX / 16 RX, 500 kbps, LISTEN_ONLY `(repo)`.
- Firmware drives it via TWAI on GPIO 15 TX / 16 RX, 500 kbps, **`TWAI_MODE_NORMAL`** `(repo)` — it **ACKs the bus** (active participant), *not* LISTEN_ONLY as older docs claimed. Deliberate, to stop transmitters retry-flooding. → [[can-bus-integration]]
- **Raw CAN logger** `(repo, 2026-07-15)`: streams every frame as `CANRAW,...` over native USB-CDC (`Serial` remapped to USB-CDC, ~1 MB/s, so it keeps up with the ~486 frame/s bus). First capture: [[can-capture-2026-07-15]].
## Other interfaces
+4 -2
View File
@@ -1,7 +1,7 @@
---
type: synthesis
tags: [meta, todo]
updated: 2026-07-15
updated: 2026-07-16
---
# Open Questions
@@ -10,7 +10,7 @@ The research frontier. Answering any of these should trigger updates across the
## Blocking
1. **What are the real CAN IDs for the E60/E65-generation M57N data we want?** The firmware's current map is placeholder-quality — two IDs aren't even valid 11-bit identifiers. Needs web research (in progress 2026-07-15) + a live bus capture to verify. → [[can-bus-integration]]
1. **What are the real CAN IDs for the E60/E65-generation M57N data we want?** *Largely answered 2026-07-15.* Research produced the map and the **first live capture confirmed it** ([[can-capture-2026-07-15]]): `0x1D0` (coolant), `0x1D2` (gear, encoding resolved), `0x0B5`, `0x3B4` all live; placeholder IDs confirmed absent. **Remaining:** a cold-start + confirmed-engine-running capture to lock coolant/battery *scaling* (first capture's engine state was unconfirmed; battery + oil-temp bytes were dormant/`0xFF`). → [[can-bus-integration]]
## Project context
@@ -30,6 +30,8 @@ The research frontier. Answering any of these should trigger updates across the
- ~~Is the EGS on the bus?~~ → **Yes — BMW auto with EGS wired in**; gearbox temp and gear position have a real source. (verified — user, 2026-07-15)
- ~~Is the target a Nissan Patrol?~~ → **Yes.** (verified — user, 2026-07-15) → [[nissan-patrol-swap]]
- ~~CAN transceiver?~~ → **Onboard TJA1051T/3/1J** on a terminal block; leave the 120 Ω termination switch OFF when tapping the vehicle bus. (source: waveshare-wiki, 2026-07-15) → [[esp32-s3-touch-lcd-5b]]
- ~~Does passive-ish listening actually work on this bus?~~ → **Yes** — first live capture pulled 15 IDs cleanly at ~486 frame/s (verified, 2026-07-15). Note the firmware runs `TWAI_MODE_NORMAL` (ACKs), not LISTEN_ONLY. → [[can-capture-2026-07-15]]
- ~~How to ground the board to the vehicle?~~ → TJA1051 is **non-isolated**; share ground with the vehicle (power from 12 V, or ground-wire + laptop on battery to avoid a ground loop). (verified, 2026-07-15) → [[esp32-s3-touch-lcd-5b]]
- ~~12 V → 5 V power conversion?~~ → **Not needed**: board has a 7–36 V DC wide input. Residual transient concern moved to #6. (source: waveshare-wiki, 2026-07-15)
## Sourcing wishlist
File diff suppressed because it is too large Load Diff
+45
View File
@@ -0,0 +1,45 @@
---
type: source
tags: [can-bus, capture, verified, e60]
updated: 2026-07-16
---
# Live CAN Capture — 2026-07-15 (FIRST REAL BUS DATA)
First capture off the **actual swap's bus**, taken with the ESP32-S3-Touch-LCD-5B itself (new raw-frame logger, `(repo)`). Two dumps: a ~20 s idle capture and a ~40 s gear-shift capture (`P→R→N→D→S/M→P`, ~5 s per position). Raw dump filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 well-formed frames, `CANRAW,<ts_ms>,<id>,<extd>,<dlc>,<hex>` format).
Bus: 500 kbps, ~486 frames/s. Capture was clean (~1.4 % line-splice loss, filtered out).
## Headline: the research map is broadly CONFIRMED
**15 IDs seen live:** `0A8 0A9 0AA 0B5 0BA 1A2 1B6 1D0 1D2 200 332 3B3 3B4 492 498`
- All four researched signal IDs are **present and live**: `0x1D0`, `0x1D2`, `0x0B5`, `0x3B4` — plus bonus candidates `0x0AA` and `0x0BA`. (verified: present on bus)
- The firmware's placeholder IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are **completely absent** — confirmed placeholders. (verified: absent)
- Researched candidates **NOT seen**: `0x130` (terminal status), `0x304` (gear lever), `0x192`. Either not broadcast by the retained modules, or need a different bus state (ignition/engine). Note for follow-up.
## Signal-level findings
| Signal | ID | What the capture shows | Status |
|--------|----|------------------------|--------|
| Coolant temp | `0x1D0` byte0 | Drifts up `0x55→0x56→0x57→0x58` (−48 → ~37→40 °C). Consistent with a warming coolant sensor. | **Partly verified** — ID + byte + upward drift confirmed; scaling still inferred; needs a cold-start ramp to lock in |
| Oil temp | `0x1D0` byte1 | Constant **`0xFF`** the whole capture — reads invalid/unpopulated | ⚠ oil temp NOT present here — the weakest research signal stays unconfirmed |
| Gear lever | `0x1D2` byte0 | Took values **`0xB4`, `0x78`, `0xE1`** — these ARE the documented BMW gear codes (N, D, P). Resting value `0xE1` = **P**. **DLC = 6** → E90 dialect. | **Verified: ID + byte0 + encoding.** Not all positions cleanly walked (R `0xD2` and S/M not captured as distinct plateaus) |
| Battery volt | `0x3B4` | Present at **~5 s rate** (matches E65 prediction) but payload mostly `0xFF` (`FF FF 00 FC FF FF FF FF`); byte3 = `0xFC`, not the predicted 0x00/0x09 engine flag | ID + rate confirmed; **payload dormant** — needs a powered/engine-running capture |
| RPM | `0x0AA` | Present at **~10 ms rate** (matches predicted RPM cadence) | ID + rate consistent; decode unverified (needs a throttle blip) |
## The 0x1D2 encoding dispute — RESOLVED (mostly)
The capture settles it: **DLC = 6** (E90-dialect length, not E65's DLC 5), and byte0 carries **whole-byte gear codes matching the documented table** (`0xE1`=P, `0xB4`=N, `0x78`=D seen live). The two sources were the same scheme in different notation, as suspected in [[can-id-candidates]].
## Open contradiction to resolve
Coolant (`0x1D0` b0) drifting upward *suggests engine running/warm, but the battery message (`0x3B4`) and oil temp (`0x1D0` b1) are dormant/`0xFF`, which suggests it wasn't. Engine state during this capture was **unconfirmed** (question not answered). A clean **cold-start + idle** capture with confirmed engine state is the next step to promote coolant + battery to fully `(verified)`.
## Method note
Gear discovery via a continuous P→R→N→D→S→P sweep was **ambiguous** — timing alignment between the physical shift and the capture window was poor, and slow IDs (`0x1D2` ~4/s) undersample the plateaus. The whole-byte gear-code match is what saved it. **Next time use a differential capture**: hold P (capture ~6 s), hold R (~6 s), diff the steady-state bytes — zero timing ambiguity.
## Related
[[can-id-candidates]] · [[can-bus-integration]] · [[bmw-m57n-engine]] · [[open-questions]]