Skip to content

V2 firmware: pin map and XBee over UART - #117

Merged
thePunderWoman merged 1 commit into
mainfrom
firmware-v2
Nov 5, 2026
Merged

thePunderWoman merged 1 commit into
mainfrom
firmware-v2

Conversation

@thePunderWoman

Copy link
Copy Markdown
Member

Firmware for the V2 board (ESP32-S3-MINI-1U), so it's ready when the boards arrive. Build it with pio run -e esp32s3_v2. pio run still builds V1.

Pin map

include/pin_assignment.h now has V2's map, copied from PCB/v2.x/snips/GPIO_table.md, beside the unchanged V1 map. The board is picked at build time with -D SNIPS_BOARD_V2.

  • Same names as V1 for every function V1 also has, so the rest of the firmware needs no changes. V2 has one bumper.
  • XBee pins: UART TX on IO35 (the XBee's DIN), RX on IO36 (DOUT), CTS on IO34, RTS on IO39, ON/SLEEP on IO41, RESET on IO42 (left released; the pull-up is on the carrier), SLEEP_RQ on IO1.
  • PWR_HOLD: on RXD0 (IO44), the same GPIO number as V1's latch. Serial is native USB, so UART0 is never started on it.
  • IMU: V2 uses its own mounting table (−90°) from Send IMU tilt and rotation rates in the uplink #116.

XBee transport

Piece What it is
XbeeLink one frame in/out; the only thing each board implements
XbeeSpi V1, now just the SPI read and write
XbeeUart V2, Serial1 at 115200, API mode (AP=1)
XbeeApi AT commands, transmit and receive, moved out of the SPI adapter. Pure and now covered by tests. The transmit buffer grew from 32 to 48 bytes, since the 17-byte uplink made a 31-byte frame.
XbeeFrameReader pure, assembles frames from UART bytes
XbeeUartSetup pure, gets the module into API mode at 115200 from whatever state it's in

Setup: a factory XBee 3 is in transparent mode (AP=0) at 9600. XbeeUartSetup tries, in order:

  1. API mode at 115200 (already set up)
  2. API mode at 9600: raise the baud with BD7, WR, AC
  3. transparent mode at 9600 or 115200: +++ command mode, then ATAP1, ATBD7, ATWR, ATCN

It saves the result with WR, so the multi-second command-mode path only runs on a module's first boot.

No carrier: a fitted XBee drives CTS low (default D7=1). With no carrier, CTS is pulled up and reads high, so the link is skipped in about 20 ms. Every XBee call then fails cleanly, which the firmware already treats as "no XBee". CTS, DOUT and ON/SLEEP get pull-ups, as GPIO_table.md asks. A carrier XBee with CTS turned off (D7=0) would also read as absent.

No hardware flow control: traffic is a ~31-byte frame each way every 50 ms, well within 115200 baud and the XBee's buffers. Using flow control would let a missing or sleeping module block every write. Writes are dropped, not blocked, if the UART buffer is ever full.

For you to decide: coverage exclusion

xbee_uart.cpp joins xbee_spi.cpp in the coverage exclusion lists in platformio.ini and ci.yml. It talks to Serial1 and can't compile natively. I kept it thin: the setup sequence, frame assembly and API logic are pure and tested, and moving the API logic out of xbee_spi.cpp actually brings code that used to be excluded under coverage. Your notes make exclusion-list changes a deliberate human call, so please confirm you're OK with it.

CI and docs

  • CI builds both boards.
  • The README and PCB/v2.x/snips/GPIO_table.md list the V2 build command.

Testing

  • pio test -e native: 474 tests pass. New: test_xbee_api (AT replies, other frames and IDs, error status, timeout, truncation, transmit and receive) and test_xbee_uart (frame reader with noise, a 0x7E inside a frame, bad checksum and length, reset; setup from each starting state, no module, and a failed write).
  • Line coverage is 98.8%.
  • pio run -e esp32s3 and pio run -e esp32s3_v2: both build. The V2 binary contains the UART carrier code and the V1 binary doesn't.
  • Not yet tested on hardware: there are no V2 boards yet. Bring-up checks: CTS goes low with the carrier fitted, first-boot setup of a factory XBee, uplink and downlink traffic, SLEEP_RQ, and the IMU signs.

🤖 Generated with Claude Code

Add a V2 build (pio run -e esp32s3_v2, -D SNIPS_BOARD_V2) for the
ESP32-S3-MINI-1U board, with its own pin map and the XBee on the
optional UART carrier.

- pin_assignment.h: V2 map from PCB/v2.x/snips/GPIO_table.md beside the
  unchanged V1 map. IMU uses V2's mounting table.
- XBee transport split: XbeeLink (frame in/out) with XbeeSpi (V1) and
  XbeeUart (V2) as thin adapters, and the AT/transmit/receive logic
  moved out of the SPI adapter into the pure, tested XbeeApi.
- XbeeFrameReader assembles API frames from the UART byte stream.
- XbeeUartSetup gets the carrier's XBee to API mode (AP=1) at 115200
  from whatever state it's in (factory transparent 9600, API 9600, or
  transparent 115200), saving the change with WR.
- No carrier: CTS (pulled up) reads high, so the link is skipped and
  every XBee call fails cleanly. No hardware flow control, so a missing
  or sleeping module can't block writes.
- CI builds both boards. xbee_uart.cpp joins xbee_spi.cpp in the
  coverage exclusion list as a Serial1 adapter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thePunderWoman
thePunderWoman merged commit 66d686c into main Nov 5, 2026
4 checks passed
@thePunderWoman
thePunderWoman deleted the firmware-v2 branch November 5, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant