Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 952f27a

Browse files
committed
fix(firmware): enable CSI in sdkconfig and add build guard (ADR-057)
The committed sdkconfig had CONFIG_ESP_WIFI_CSI_ENABLED disabled, causing all builds to crash at runtime with "CSI not enabled in menuconfig". Root cause: sdkconfig.defaults.template existed but ESP-IDF only reads sdkconfig.defaults (no .template suffix). Fixes: - Add sdkconfig.defaults with CONFIG_ESP_WIFI_CSI_ENABLED=y - Add #error compile guard in csi_collector.c to prevent recurrence - Fix NVS encryption default (requires eFuse, breaks clean builds) Verified: Docker build + flash to ESP32-S3 + CSI callbacks confirmed. Closes #241 Relates to #223, #238, #234, #210, #190 Co-Authored-By: claude-flow <[email protected]>
1 parent f7d043d commit 952f27a

4 files changed

Lines changed: 128 additions & 2 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# ADR-057: Firmware CSI Build Guard and sdkconfig.defaults
2+
3+
| Field | Value |
4+
|-------------|---------------------------------------------|
5+
| **Status** | Accepted |
6+
| **Date** | 2026-03-12 |
7+
| **Authors** | ruv |
8+
| **Issues** | #223, #238, #234, #210, #190 |
9+
10+
## Context
11+
12+
Multiple GitHub issues (#223, #238, #234, #210, #190) report firmware problems
13+
that fall into two categories:
14+
15+
1. **CSI not enabled at runtime** — The committed `sdkconfig` had
16+
`# CONFIG_ESP_WIFI_CSI_ENABLED is not set` (line 1135), meaning users who
17+
built from source or used pre-built binaries got the runtime error:
18+
`E (6700) wifi:CSI not enabled in menuconfig!`
19+
20+
Root cause: `sdkconfig.defaults.template` existed with the correct setting
21+
(`CONFIG_ESP_WIFI_CSI_ENABLED=y`) but ESP-IDF only reads
22+
`sdkconfig.defaults` — not `.template` suffixed files. No `sdkconfig.defaults`
23+
file was committed.
24+
25+
2. **Unsupported ESP32 variants** — Users attempting to use original ESP32
26+
(D0WD) and ESP32-C3 boards. The firmware targets ESP32-S3 only
27+
(`CONFIG_IDF_TARGET="esp32s3"`, Xtensa architecture) and this was not
28+
surfaced clearly enough in documentation or build errors.
29+
30+
## Decision
31+
32+
### Fix 1: Commit `sdkconfig.defaults` (not just template)
33+
34+
Copy `sdkconfig.defaults.template``sdkconfig.defaults` so that ESP-IDF
35+
applies the correct defaults (including `CONFIG_ESP_WIFI_CSI_ENABLED=y`)
36+
automatically when `sdkconfig` is regenerated.
37+
38+
### Fix 2: `#error` compile-time guard in `csi_collector.c`
39+
40+
Add a preprocessor guard:
41+
42+
```c
43+
#ifndef CONFIG_ESP_WIFI_CSI_ENABLED
44+
#error "CONFIG_ESP_WIFI_CSI_ENABLED must be set in sdkconfig."
45+
#endif
46+
```
47+
48+
This turns a confusing runtime crash into a clear compile-time error with
49+
instructions on how to fix it.
50+
51+
### Fix 3: Fix committed `sdkconfig`
52+
53+
Change line 1135 from `# CONFIG_ESP_WIFI_CSI_ENABLED is not set` to
54+
`CONFIG_ESP_WIFI_CSI_ENABLED=y`.
55+
56+
## Consequences
57+
58+
- **Positive**: New builds will always have CSI enabled. Users building from
59+
source will get a clear compile error if CSI is somehow disabled.
60+
- **Positive**: Pre-built release binaries will include CSI support.
61+
- **Neutral**: Original ESP32 and ESP32-C3 remain unsupported. This is by
62+
design — only ESP32-S3 has the CSI API surface we depend on. Future ADRs
63+
may address multi-target support if demand warrants it.
64+
- **Negative**: None identified.
65+
66+
## Hardware Support Matrix
67+
68+
| Variant | CSI Support | Firmware Target | Status |
69+
|--------------|-------------|-----------------|---------------|
70+
| ESP32-S3 | Yes | Yes | Supported |
71+
| ESP32 (orig) | Partial | No | Unsupported |
72+
| ESP32-C3 | Yes (IDF 5.1+) | No | Unsupported |
73+
| ESP32-C6 | Yes | No | Unsupported |
74+
75+
## Notes
76+
77+
- ESP32-C3 and C6 use RISC-V architecture; a separate build target
78+
(`idf.py set-target esp32c3`) would be needed.
79+
- Original ESP32 has limited CSI (no STBC HT-LTF2, fewer subcarriers).
80+
- Users on unsupported hardware can still write custom firmware using the
81+
ADR-018 binary frame format (magic `0xC5110001`) for interop with the
82+
Rust aggregator.

firmware/esp32-csi-node/main/csi_collector.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
#include "esp_timer.h"
2222
#include "sdkconfig.h"
2323

24+
/* ADR-057: Build-time guard — fail early if CSI is not enabled in sdkconfig.
25+
* Without this, the firmware compiles but crashes at runtime with:
26+
* "E (xxxx) wifi:CSI not enabled in menuconfig!"
27+
* which is confusing for users flashing pre-built binaries. */
28+
#ifndef CONFIG_ESP_WIFI_CSI_ENABLED
29+
#error "CONFIG_ESP_WIFI_CSI_ENABLED must be set in sdkconfig. " \
30+
"Run: idf.py menuconfig -> Component config -> Wi-Fi -> Enable WiFi CSI, " \
31+
"or copy sdkconfig.defaults.template to sdkconfig.defaults before building."
32+
#endif
33+
2434
static const char *TAG = "csi_collector";
2535

2636
static uint32_t s_sequence = 0;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ESP32-S3 CSI Node — Default SDK Configuration
2+
# This file is applied automatically by idf.py when no sdkconfig exists.
3+
4+
# Target: ESP32-S3
5+
CONFIG_IDF_TARGET="esp32s3"
6+
7+
# Use custom partition table (8MB flash with OTA — ADR-045)
8+
CONFIG_PARTITION_TABLE_CUSTOM=y
9+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_display.csv"
10+
11+
# Flash configuration: 8MB (Quad SPI)
12+
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
13+
CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
14+
15+
# Compiler optimization: optimize for size to reduce binary
16+
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
17+
18+
# Enable CSI (Channel State Information) in WiFi driver
19+
CONFIG_ESP_WIFI_CSI_ENABLED=y
20+
21+
# NVS encryption disabled by default (requires eFuse provisioning).
22+
# Enable only after burning HMAC key to eFuse block.
23+
# CONFIG_NVS_ENCRYPTION is not set
24+
25+
# Disable unused features to reduce binary size
26+
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
27+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
28+
29+
# LWIP: enable extended socket options for UDP multicast
30+
CONFIG_LWIP_SO_RCVBUF=y
31+
32+
# FreeRTOS: increase task stack for CSI processing
33+
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192

firmware/esp32-csi-node/sdkconfig.defaults.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ CONFIG_COMPILER_OPTIMIZATION_SIZE=y
1818
# Enable CSI (Channel State Information) in WiFi driver
1919
CONFIG_ESP_WIFI_CSI_ENABLED=y
2020

21-
# Enable NVS encryption for secure credential storage
22-
CONFIG_NVS_ENCRYPTION=y
21+
# NVS encryption disabled by default (requires eFuse provisioning).
22+
# Enable only after burning HMAC key to eFuse block.
23+
# CONFIG_NVS_ENCRYPTION is not set
2324

2425
# Disable unused features to reduce binary size
2526
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y

0 commit comments

Comments
 (0)