6 Commits

Author SHA1 Message Date
4e19882d32 Harden firmware for dual-core concurrency and input validation
Address safety review findings for the dual-interface (WiFi + USB serial)
architecture running on the ESP32-S3's two Xtensa LX7 cores:

- Protect sweep state with std::atomic (acquire/release ordering)
- Add Attenuator::getSnapshot() for consistent multi-field reads
- Add advanceStep()/persistCurrent() to eliminate TOCTOU races
- Switch to StaticSemaphore_t (compile-time mutex, can't fail)
- Accumulate web server POST bodies before parsing (chunked TCP fix)
- Backport USB serial input validation to web server handlers
- Auto-stop sweep on manual set (prevents silent overwrite)
- Validate WiFi TX power against known-good levels
- Add OTA password authentication support
- Check NVS write return values, log failures
- Reset USB serial buffer on reconnect (stale overflow fix)
- Rename sweep.h to app.h (declares more than sweep functions)
2026-02-18 18:43:08 -07:00
fee8d9c1f9 Add USB CDC serial command interface for RF test bench control
Line-based JSON protocol over the ESP32-S3 native USB OTG port,
providing deterministic sub-millisecond attenuator control without
WiFi interference. Runs alongside the existing REST API.

Commands: identify, status, config, set, sweep, sweep_stop
Protocol: usb-serial-json-v1 (one JSON object per \n-terminated line)

Also addresses pre-existing reliability issues found during review:
- Thread safety: FreeRTOS mutex in Attenuator class (web server
  callbacks run on async_tcp task, not loop())
- NVS flash wear: skip persist during sweep, save on stop
- WiFi credentials: moved to gitignored platformio_local.ini
- Shared header: sweep.h replaces duplicated extern declarations
2026-02-18 13:46:52 -07:00
a425b4c324 Add OLED display support, standardize Serial0 for UART output
- Add SSD1306 128x64 OLED display with attenuation bar, dB readout,
  step counter, sweep indicator, and WiFi RSSI
- Switch all debug output to Serial0 (UART0 via CH343) for consistent
  serial comms when USB CDC is not used
- Remove unused USB.h includes from all source files
- Add development notes to CLAUDE.md (no stty, serial config docs)
2026-02-08 14:10:44 -07:00
db54d05bed Makefile: use esptool directly, add LittleFS and erase targets
PlatformIO's built-in upload breaks on the S2 Mini (1200bps USB
touch reset disconnects the native USB port). All flash targets
now call esptool directly with the correct S2 partition offsets:
bootloader at 0x1000, firmware at 0x10000, LittleFS at 0x290000.

Also adds USB.begin() before Serial.begin() in main.cpp — required
for ESP32-S2 native USB-CDC to initialize properly.
2026-02-02 23:32:07 -07:00
fb835c9d5d Fix ESP32-S2 build: USB.h, WDT API, remove duplicate flags
- Add #include <USB.h> to all .cpp files (required for HWCDCSerial)
- Use ESP-IDF v5.x esp_task_wdt_config_t struct instead of removed API
- Remove duplicate ARDUINO_USB_MODE/CDC flags from platformio.ini
  (board definition already provides these)
2026-02-02 21:27:24 -07:00
613611d37a Add ESP32-S2 firmware for HMC472A attenuator control
PlatformIO/Arduino firmware for WEMOS/LOLIN S2 Mini:
- 6-bit GPIO control (GPIOs 1-6) with glitch-free register writes
- REST API: /status, /set, /config, /sweep endpoints
- Web UI with PCB green theme, slider, presets, pin visualization
- NVS persistence of attenuation setting across power cycles
- Sweep mode for automated attenuation stepping
- mDNS (attenuator.local), OTA updates, watchdog
2026-02-02 21:24:29 -07:00