From cb30988cf9fca0da7a9f09ee3d7a0d18cccacfa8 Mon Sep 17 00:00:00 2001 From: rUv Date: Wed, 17 Jun 2026 11:24:23 -0400 Subject: [PATCH] =?UTF-8?q?fix(mmwave):=20require=20validated=20MR60=20hea?= =?UTF-8?q?der=20on=20probe=20=E2=80=94=20no=20false=20detect=20on=20empty?= =?UTF-8?q?=20UART=20(#1107)=20(#1119)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit probe_at_baud counted bare 0x01 (SOF) bytes and declared MR60BHA2 on a single one. A floating UART1 with no sensor reads noise full of 0x01s → false 'Detected MR60BHA2 (caps=0x000f)'. Now a candidate must be a full 8-byte header with a valid header checksum (bytes 0..6) AND a known frame type (0x0A__ / 0x0F09), and clear the ≥3 threshold; removed the weak single-hit fallback. Real sensors stream valid frames continuously, so detection of present hardware is unaffected. Co-authored-by: ruv --- firmware/esp32-csi-node/main/mmwave_sensor.c | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/firmware/esp32-csi-node/main/mmwave_sensor.c b/firmware/esp32-csi-node/main/mmwave_sensor.c index 882e50b6..3b10afb5 100644 --- a/firmware/esp32-csi-node/main/mmwave_sensor.c +++ b/firmware/esp32-csi-node/main/mmwave_sensor.c @@ -387,11 +387,21 @@ static mmwave_type_t probe_at_baud(uint32_t baud) if (len <= 0) continue; for (int i = 0; i < len; i++) { - /* MR60BHA2: SOF = 0x01, followed by valid-looking frame_id bytes */ - if (buf[i] == MR60_SOF && baud == MMWAVE_MR60_BAUD) { - mr60_sof_seen++; + /* MR60BHA2: require a *validated* 8-byte header — SOF (0x01) + a valid + * header checksum (over bytes 0..6) + a known frame type (0x0A__ or + * 0x0F09) — NOT a bare 0x01 byte. A floating UART1 with no sensor reads + * noise full of 0x01s, which the old `buf[i] == MR60_SOF` check mistook + * for a real sensor (false "Detected MR60BHA2", #1107). */ + if (buf[i] == MR60_SOF && baud == MMWAVE_MR60_BAUD && i + 7 < len) { + const uint8_t *h = &buf[i]; + if (mr60_calc_checksum(h, 7) == h[7]) { + uint16_t type = ((uint16_t)h[5] << 8) | h[6]; + if ((type >> 8) == 0x0A || type == 0x0F09) { + mr60_sof_seen++; + } + } } - /* LD2410: 4-byte header 0xF4F3F2F1 */ + /* LD2410: 4-byte header 0xF4F3F2F1 (already specific enough). */ if (i + 3 < len && buf[i] == 0xF4 && buf[i+1] == 0xF3 && buf[i+2] == 0xF2 && buf[i+3] == 0xF1 && baud == MMWAVE_LD2410_BAUD) { @@ -403,9 +413,8 @@ static mmwave_type_t probe_at_baud(uint32_t baud) if (ld2410_header_seen >= 2) return MMWAVE_TYPE_LD2410; } - if (mr60_sof_seen > 0) return MMWAVE_TYPE_MR60BHA2; - if (ld2410_header_seen > 0) return MMWAVE_TYPE_LD2410; - + /* No weak single-hit fallback: line noise can produce a stray match, so a real + * sensor must clear the ≥3 (MR60) / ≥2 (LD2410) validated-frame thresholds. */ return MMWAVE_TYPE_NONE; }