Files
alro65 65860948b4 sprint-1: firmware ESP32 base -- STANDBY + Modbus + NMEA 2000 + watchdog
End-to-end implementation of Sprint 1 per docs/sprint-1-plan.md.

Builds: pio run -e esp32-dev SUCCESS, RAM 6.7%, Flash 26.5% (347 KB).
Tests: pytest 110/110 green; pio test -e native deferred (needs host
       C++ compiler -- none on this Windows machine).

Firmware (firmware/ar_autopilot_v1/):

- platformio.ini: 4 envs (esp32-dev release, esp32-debug, native unity
  tests, check static analysis). NMEA2000-library@4.22, NMEA2000_esp32@
  1.0, eModbus@1.7.4 pinned.
- main.cpp: boot in STANDBY, FreeRTOS task spawn, returns to scheduler.
- system/: ar_log.h facade, task_config.h (priorities/stacks/cores
  central table), heartbeat (1 Hz LED + uptime).
- modes/: STANDBY-only state machine; non-STANDBY rejected.
- hal/: di_do.cpp (5 DI + 10 DO with debounce + last-state cache),
  rudder_sensor.cpp (100 Hz ADC + 5-sample median filter, Core 1),
  rudder_actuator.cpp (DO1/DO2/DO3 with three safety interlocks:
  power-off, STANDBY mode, limit switch).
- safety/: TWDT @ 2 s panic-on-expire; 50 Hz safety task on Core 1
  enforcing DI1 physical disengage button, DI4 external alarm,
  both-limit-switch interlock.
- protocols/modbus_slave.cpp: eModbus RTU server on UART2 @ 38400 8N1,
  slave ID 1. 17 inputs + 19 discretes + 5 holdings + 4 coils. Reads
  pull live telemetry; writes validate range and route to handlers.
- protocols/nmea2000_consumer.cpp: stack open with CAN TX=GPIO3
  RX=GPIO1, subscribed to PGN 127250 (Heading) + PGN 127251 (Rate of
  Turn). 5 s staleness flag built in for Sprint 6 alarm wiring.
- filters/median.h: templated MedianFilter<T,N> (host testable).

Cross-cutting:

- modbus_registers.yaml: single source of truth for the Modbus register
  map. 45 entries.
- tools/gen_modbus_registers.py: YAML -> C++ header + Python module
  generator with --check for drift detection.
- arautopilot/shared/modbus_register_map.py: generated Python mirror,
  imported by Studio + tools.
- arautopilot/tests/test_modbus_register_map.py: 30 tests covering
  schema, address uniqueness, range, spot-checks, and drift detection
  (fails if YAML edited without regenerating).
- firmware/ar_autopilot_v1/tools/modbus_client_test.py: manual Modbus
  client for poking the slave from a PC with USB-RS485 dongle.
- firmware/ar_autopilot_v1/test/test_median_filter/test_median.cpp:
  8 Unity tests of the median filter (host-side, no Arduino dependency).
- docs/firmware.md: full operator + integrator guide (toolchain, build,
  flash, expected boot log, troubleshooting, Sprint 1 capability matrix).

Architecture note: opted for Arduino-on-ESP32 only instead of the
proposed dual Arduino-as-ESP-IDF-component setup. Rationale documented
in CHANGELOG and docs/firmware.md -- Arduino-on-ESP32 already provides
the FreeRTOS primitives we need; dual framework adds fragility without
benefit at Sprint 1 scope. Reconsider in Sprint 8 (OTA + secure boot).

NOT in Sprint 1 (intentional per brief sec. 12):
  - PID loops (inner/outer)
  - True Course / Track Keeping
  - Full alarm catalogue beyond DI1/DI4
  - Knob driver
  - Studio GUI / dedicated display

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 10:45:56 -04:00

124 lines
4.1 KiB
INI

; =============================================================================
; AR-Autopilot v1 -- firmware build configuration
; =============================================================================
;
; Target hardware: AR-NMEA-IO v1.0 (ESP32-DOWD-V3, dual-core 240 MHz)
; Build system: PlatformIO 6.1+
; Framework: arduino (on ESP32 -- includes FreeRTOS, full Espressif stack)
;
; This file is the single source of truth for the firmware build. Versions of
; the platform, framework packages, and library dependencies are pinned for
; reproducibility.
;
; Tasks (from the project root):
;
; .venv/Scripts/pio.exe run # compile (default env: esp32-dev)
; .venv/Scripts/pio.exe run -e esp32-debug # compile with extra debug flags
; .venv/Scripts/pio.exe run -e native # build host-side Unity tests
; .venv/Scripts/pio.exe test -e native # run host-side Unity tests
; .venv/Scripts/pio.exe check # static analysis (cppcheck)
; .venv/Scripts/pio.exe run -t upload # flash (needs the board plugged in)
;
; =============================================================================
[platformio]
src_dir = src
include_dir = include
test_dir = test
default_envs = esp32-dev
; -----------------------------------------------------------------------------
; Common settings shared by every ESP32 env
; -----------------------------------------------------------------------------
[env]
platform = espressif32@^6.7.0
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, time
build_flags =
-std=gnu++17
-DCORE_DEBUG_LEVEL=3 ; ARDUHAL_LOG_LEVEL_INFO
-DAR_FW_VERSION=\"0.1.0-sprint1\"
-DAR_FW_BUILD_TIMESTAMP=__TIMESTAMP__
-Wall
-Wextra
-Wno-unused-parameter
-Wno-missing-field-initializers
build_unflags =
-std=gnu++11
; Library dependencies pinned for reproducibility.
; These are the Sprint 1 dependencies; later sprints may add more.
lib_deps =
ttlappalainen/NMEA2000-library@^4.22.0
ttlappalainen/NMEA2000_esp32@^1.0.3
https://github.com/eModbus/eModbus.git#v1.7.4.stable
; Files we never want to compile / lint:
; - Documentation
; - Test fixtures (handled by env:native)
lib_ignore =
test
; -----------------------------------------------------------------------------
; Production build for the AR-NMEA-IO board
; -----------------------------------------------------------------------------
[env:esp32-dev]
board = esp32dev
board_build.partitions = default.csv
build_type = release
build_flags =
${env.build_flags}
-Os
-DAR_BUILD_VARIANT=\"release\"
; -----------------------------------------------------------------------------
; Debug build (-O0, extra logging)
; -----------------------------------------------------------------------------
[env:esp32-debug]
board = esp32dev
build_type = debug
build_flags =
${env.build_flags}
-O0
-ggdb
-DAR_BUILD_VARIANT=\"debug\"
-DCORE_DEBUG_LEVEL=5 ; ARDUHAL_LOG_LEVEL_VERBOSE
; -----------------------------------------------------------------------------
; Host-side Unity tests (run on the developer machine, no ESP32 needed)
; -----------------------------------------------------------------------------
; Used for pure-logic tests: ring buffers, median filters, the Modbus
; register map, the PID math, etc. Anything that talks to real hardware
; lives in env:esp32-dev tests and runs only on the board.
;
; NOTE: this env does NOT inherit [env] (which targets ESP32 + Arduino).
[env:native]
platform = native
framework =
test_framework = unity
test_build_src = no
build_flags =
-std=gnu++17
-DAR_HOST_TEST=1
-DUNITY_INCLUDE_DOUBLE
-Wall
-Wextra
build_unflags =
lib_deps =
lib_ignore =
monitor_filters =
; -----------------------------------------------------------------------------
; Static analysis
; -----------------------------------------------------------------------------
[env:check]
platform = espressif32@^6.7.0
framework = arduino
board = esp32dev
check_tool = cppcheck
check_flags =
cppcheck: --enable=warning,style,performance,portability --inline-suppr
check_skip_packages = yes
check_severity = medium, high