Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 72 additions & 50 deletions .github/workflows/firmware-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,55 @@ jobs:
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Firmware version: $VERSION"

- name: Compile firmware (min_spiffs partition for OTA)
# Two binaries from one source: E (LG290P, default) and B1 (LC29HEA,
# -DBUILD_B1). They are NOT interchangeable — GPIO19 is TFT_BL on E but
# PWR_HOLD (self-power latch) on B, and the TFT driver differs — so each
# boat's OTA manifest must point at its own variant (handled below).
- name: Compile E firmware (min_spiffs partition for OTA)
run: |
mkdir -p build
mkdir -p build_e
arduino-cli compile \
--fqbn 'esp32:esp32:esp32:PartitionScheme=min_spiffs,FlashSize=4M,FlashFreq=80,FlashMode=qio,CPUFreq=240,UploadSpeed=921600' \
--output-dir build_e \
--warnings none \
edge-e/firmware/sailframes_edge

- name: Compile B1 firmware (-DBUILD_B1)
run: |
mkdir -p build_b1
arduino-cli compile \
--fqbn 'esp32:esp32:esp32:PartitionScheme=min_spiffs,FlashSize=4M,FlashFreq=80,FlashMode=qio,CPUFreq=240,UploadSpeed=921600' \
--output-dir build \
--build-property 'compiler.cpp.extra_flags=-DBUILD_B1' \
--output-dir build_b1 \
--warnings none \
edge-e/firmware/sailframes_edge

- name: Report binary size
- name: Report + check binary sizes
run: |
SIZE=$(stat -c%s build/sailframes_edge.ino.bin)
MAX=1966080 # 1.9MB OTA partition limit
PCT=$(awk "BEGIN { printf \"%.1f\", ($SIZE / $MAX) * 100 }")
echo "Binary size: $SIZE bytes (${PCT}% of 1.9MB OTA partition)"
if [ "$SIZE" -gt "$MAX" ]; then
echo "::error::Binary exceeds min_spiffs OTA partition (1.9MB)"
exit 1
fi
for VAR in E:build_e B1:build_b1; do
NAME=${VAR%%:*}; DIR=${VAR##*:}
SIZE=$(stat -c%s "$DIR/sailframes_edge.ino.bin")
PCT=$(awk "BEGIN { printf \"%.1f\", ($SIZE / $MAX) * 100 }")
echo "$NAME binary: $SIZE bytes (${PCT}% of 1.9MB OTA partition)"
if [ "$SIZE" -gt "$MAX" ]; then
echo "::error::$NAME binary exceeds min_spiffs OTA partition (1.9MB)"
exit 1
fi
done

- name: Rename and hash artifacts
run: |
V="${{ steps.version.outputs.version }}"
cp build/sailframes_edge.ino.bin "build/sailframes_edge_${V}.bin"
cp build/sailframes_edge.ino.partitions.bin "build/sailframes_edge_${V}.partitions.bin" 2>/dev/null || true
cp build/sailframes_edge.ino.bootloader.bin "build/sailframes_edge_${V}.bootloader.bin" 2>/dev/null || true
mkdir -p build
cp build_e/sailframes_edge.ino.bin "build/sailframes_edge_${V}.bin"
cp build_b1/sailframes_edge.ino.bin "build/sailframes_edge_b1_${V}.bin"
# bootloader + partitions (E variant — reference for a full USB flash)
cp build_e/sailframes_edge.ino.partitions.bin "build/sailframes_edge_${V}.partitions.bin" 2>/dev/null || true
cp build_e/sailframes_edge.ino.bootloader.bin "build/sailframes_edge_${V}.bootloader.bin" 2>/dev/null || true
cd build
sha256sum "sailframes_edge_${V}.bin" > "sailframes_edge_${V}.bin.sha256"
sha256sum "sailframes_edge_${V}.bin" > "sailframes_edge_${V}.bin.sha256"
sha256sum "sailframes_edge_b1_${V}.bin" > "sailframes_edge_b1_${V}.bin.sha256"
ls -la

- name: Upload build artifacts
Expand All @@ -104,6 +125,8 @@ jobs:
path: |
build/sailframes_edge_${{ steps.version.outputs.version }}.bin
build/sailframes_edge_${{ steps.version.outputs.version }}.bin.sha256
build/sailframes_edge_b1_${{ steps.version.outputs.version }}.bin
build/sailframes_edge_b1_${{ steps.version.outputs.version }}.bin.sha256
build/sailframes_edge_${{ steps.version.outputs.version }}.partitions.bin
build/sailframes_edge_${{ steps.version.outputs.version }}.bootloader.bin
retention-days: 90
Expand All @@ -116,14 +139,16 @@ jobs:
files: |
build/sailframes_edge_${{ steps.version.outputs.version }}.bin
build/sailframes_edge_${{ steps.version.outputs.version }}.bin.sha256
build/sailframes_edge_b1_${{ steps.version.outputs.version }}.bin
build/sailframes_edge_b1_${{ steps.version.outputs.version }}.bin.sha256
build/sailframes_edge_${{ steps.version.outputs.version }}.partitions.bin
build/sailframes_edge_${{ steps.version.outputs.version }}.bootloader.bin

# OTA manifest publish — only on green main builds (not PRs).
# Firmware is fleet-identical, but each device GETs from a path
# that includes its boat_id (E1..E6). We upload the .bin once at a
# canonical key and fan out the manifest to all six boat prefixes,
# all pointing back at the canonical .bin URL.
# Each device GETs firmware/<boat_id>/latest.json. The E and B1 binaries
# are DIFFERENT and NOT interchangeable (GPIO19 = backlight on E but the
# PWR_HOLD self-power latch on B), so each fleet's manifest points at its
# own binary: E1..E6 -> E build, B-fleet -> B1 build.
- name: Configure AWS credentials (firmware CI user)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -139,36 +164,33 @@ jobs:
V="${{ steps.version.outputs.version }}"
BUCKET="sailframes-fleet-data-prod"
REGION="us-east-1"
BIN="build/sailframes_edge_${V}.bin"
KEY_BIN="firmware/sailframes_edge_${V}.bin"

SIZE=$(stat -c%s "$BIN")
SHA=$(sha256sum "$BIN" | awk '{print $1}')
URL="http://${BUCKET}.s3.${REGION}.amazonaws.com/${KEY_BIN}"

echo "Uploading $BIN -> s3://${BUCKET}/${KEY_BIN}"
aws s3 cp "$BIN" "s3://${BUCKET}/${KEY_BIN}" \
--content-type application/octet-stream \
--cache-control "max-age=31536000,immutable"

MANIFEST=$(mktemp)
cat > "$MANIFEST" <<EOF
{
"version": "${V}",
"url": "${URL}",
"size": ${SIZE},
"sha256": "${SHA}",
"git_sha": "${GITHUB_SHA}",
"built_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF

echo "Manifest:"
cat "$MANIFEST"
# publish_variant <local-bin> <s3-key> <boat-id>...
# uploads the binary once at an immutable key, then fans a manifest
# pointing at it to each named boat's firmware/<boat>/latest.json.
publish_variant() {
local BIN_LOCAL="$1"; local KEY="$2"; shift 2
local SIZE SHA URL MANIFEST B
SIZE=$(stat -c%s "$BIN_LOCAL")
SHA=$(sha256sum "$BIN_LOCAL" | awk '{print $1}')
URL="http://${BUCKET}.s3.${REGION}.amazonaws.com/${KEY}"
echo "Uploading $BIN_LOCAL -> s3://${BUCKET}/${KEY}"
aws s3 cp "$BIN_LOCAL" "s3://${BUCKET}/${KEY}" \
--content-type application/octet-stream \
--cache-control "max-age=31536000,immutable"
MANIFEST=$(mktemp)
printf '{\n "version": "%s",\n "url": "%s",\n "size": %s,\n "sha256": "%s",\n "git_sha": "%s",\n "built_at": "%s"\n}\n' \
"$V" "$URL" "$SIZE" "$SHA" "$GITHUB_SHA" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$MANIFEST"
echo "Manifest for $*:"; cat "$MANIFEST"
for B in "$@"; do
aws s3 cp "$MANIFEST" "s3://${BUCKET}/firmware/${B}/latest.json" \
--content-type application/json \
--cache-control "max-age=60"
echo " -> firmware/${B}/latest.json"
done
}

for B in E1 E2 E3 E4 E5 E6; do
aws s3 cp "$MANIFEST" "s3://${BUCKET}/firmware/${B}/latest.json" \
--content-type application/json \
--cache-control "max-age=60"
echo " -> http://${BUCKET}.s3.${REGION}.amazonaws.com/firmware/${B}/latest.json"
done
# E fleet -> E binary. B fleet -> B1 binary. Add new B units (B3, B4,
# ...) to the B list as they're provisioned with a boat_id.
publish_variant "build/sailframes_edge_${V}.bin" "firmware/sailframes_edge_${V}.bin" E1 E2 E3 E4 E5 E6
publish_variant "build/sailframes_edge_b1_${V}.bin" "firmware/sailframes_edge_b1_${V}.bin" B1 B2
25 changes: 19 additions & 6 deletions edge-b/firmware/b1_bringup/b1_bringup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
#define GNSS_PPS 39 // input-only
// Battery + power latch
#define PIN_VBAT 34 // ADC1_6, 100K/100K divider on VBAT
#define PIN_LATCH 19 // LATCH_Q_RB (read-only — latch set => board ON)
// v0.13 Qi-power: GPIO19 = PWR_HOLD. OUTPUT, drives /LATCH_Q via R28(0R).
// HIGH = boost latched on (survives lift-off pad); LOW/hi-Z = off (R_PD pulls
// LATCH_Q low). Must be driven HIGH as the FIRST GPIO op in setup(). On the pad
// the MCU also lives on the D7/Qi rail, so the latch only matters once lifted.
#define PIN_PWR_HOLD 19
// Status LEDs (active LOW, 220R)
#define LED_RED 33 // D4
#define LED_WHITE 32 // D5
Expand Down Expand Up @@ -94,10 +98,12 @@ static void testBattery() {
}

static void testLatch() {
pinMode(PIN_LATCH, INPUT);
int q = digitalRead(PIN_LATCH);
Serial.printf("[LATCH] LATCH_Q_RB (GPIO19) = %d -> latch %s (we're running, so should read HIGH)\n",
q, q ? "SET / board ON" : "CLEAR (?)");
// v0.13: GPIO19 is PWR_HOLD (OUTPUT). DO NOT pinMode(INPUT) — that tri-states
// it, R_PD pulls /LATCH_Q low, and the board powers ITSELF off the moment it's
// off-pad. digitalRead() on an OUTPUT returns the latched output register.
int q = digitalRead(PIN_PWR_HOLD);
Serial.printf("[LATCH] PWR_HOLD (GPIO19) driven = %d -> boost latch %s (held by firmware)\n",
q, q ? "ON / will survive lift-off pad" : "OFF (?) — board would die on lift");
}

// ---------------- LEDs ----------------
Expand Down Expand Up @@ -252,6 +258,13 @@ static void help() {
}

void setup() {
// v0.13 Qi-power: latch our own power ON before anything slow. On the pad we
// boot via the D7/Qi rail; this drives /LATCH_Q (R28 0R) so the MT3608 boost
// stays enabled and V5_SW survives being lifted off the pad. WITHOUT this the
// board dies the instant Qi power is removed (see B1_V013_QI_POWER.md §6).
pinMode(PIN_PWR_HOLD, OUTPUT);
digitalWrite(PIN_PWR_HOLD, HIGH);

Serial.begin(115200);
delay(400);
analogReadResolution(12);
Expand Down Expand Up @@ -279,7 +292,7 @@ void loop() {
else if (cmd == "m") {
Serial.println(F("[MON] battery + latch every 1s; send any line to stop"));
while (!Serial.available()) {
Serial.printf(" BAT %.2fV LATCH %d heap %u\n", readBattV(), digitalRead(PIN_LATCH), ESP.getFreeHeap());
Serial.printf(" BAT %.2fV PWR_HOLD %d heap %u\n", readBattV(), digitalRead(PIN_PWR_HOLD), ESP.getFreeHeap());
delay(1000);
}
Serial.readStringUntil('\n');
Expand Down
45 changes: 36 additions & 9 deletions edge-b/hardware/B1_V013_QI_POWER.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# B1 v0.13 — Qi-pad on/off (magnet + button both removed)

**Status: schematic + PCB COMPLETE on branch `b1/v013-qi-power` — DRC-clean and
netlist-verified (J5 microSD fix + antenna keepout landed in the same pass). Firmware is
spec-only (§6) — not yet written. Before fab: write the firmware, finish Option-1 antenna
notch/overhang + LiPo (§7 — keepout done, overhang TBD), regenerate fab outputs, and
ideally validate the antenna fix on an E1 bench unit first.**
**Status: VALIDATED ON HARDWARE (2026-06-29) — survives multi-lift off the pad on battery
at full radio load (FW 2026.06.29.01). The latch is proven good at the J17 `LATCH_DBG`
header: LATCH_Q=3.269 V (R28 is a true 0 Ω jumper), MOSFET_GATE=12.6 mV (AO3401A load switch
hard on). NOTE: an early "dies on lift" scare was a LOOSE BATTERY JST connector, not the
power stage — reseat/verify the battery connector on every fresh board. Battery gauge
calibrated for B1: GPIO34 divider ratio 2.09 (E1 stays 2.25); multimeter 4.096 V read as
4.41 V at 2.25. v0.13 boards arrived 2026-06-28 — the self-power latch
VALIDATED: a board boots on the pad and survives lift-off once PWR_HOLD is driven HIGH.
FIRMWARE IMPLEMENTED in `sailframes_edge.ino` (FW 2026.06.28.01, all under `#ifdef BUILD_B1`;
E build verified byte-identical except the version string). Two deltas from the original §6
spec, both deliberate (see §6): (1) "parked" is a non-blocking loop state, never a halt —
a spin would trip the Core-1 loop watchdog into a restart that re-latches power ON;
(2) the lift-and-replace gesture was DROPPED (a coil-alignment nudge would false-trigger it)
— deliberate off is the `poweroff` serial/telnet command, plus the 30-min idle-on-pad
store-and-forget trigger.**

This replaces the magnetic hall latch with **the Qi charging pad as the power switch** —
no magnet, no button, **zero enclosure penetration** (best possible IP68). Place B1 on
Expand Down Expand Up @@ -117,10 +127,27 @@ enough.)
trust DRC alone (the v0.12 microSD + U_HALL bugs were DRC-clean).
6. Regenerate fab outputs (gerbers/BOM/CPL) only after DRC + the J5 + antenna fixes (§7).

## 6. Firmware (spec — not yet written; B-platform gated)

In `sailframes_edge.ino`, under `hardware_platform == B`. Set GPIO15 = `INPUT` (no pull)
right after boot (see §3 divider note).
## 6. Firmware (IMPLEMENTED — FW 2026.06.28.01, gated `#ifdef BUILD_B1`)

In `sailframes_edge.ino`, gated at **compile time** by `#ifdef BUILD_B1` (NOT runtime
`g_hw`): GPIO19 is physically `TFT_BL` on E (User_Setup.h), so an E binary must never
touch it. Implemented as: `setup()` drives PWR_HOLD HIGH + GPIO15 `INPUT` as the first GPIO
op; `b1PowerTick()` (per loop) evaluates the triggers; `b1EnterParked()` releases the latch;
`b1ParkedLoop()` is the non-blocking parked state; `drawB1ChargingScreen()` is the on-pad UI;
`power`/`poweroff` serial commands. Set GPIO15 = `INPUT` (no pull) right after boot (see §3
divider note).

> **Two deliberate deltas from the original spec below** (kept the spec text for context):
> - **Parked = non-blocking loop state, never a halt.** `b1EnterParked()` sets `g_b1Parked`,
> drops PWR_HOLD, and `loop()` early-returns each iteration *after* `g_loopIter++`/wdt-feed.
> A `while(true)` halt would freeze `g_loopIter`, the Core-1 loop watchdog (gotcha #22)
> would `esp_restart()`, and `setup()` would re-latch PWR_HOLD HIGH ~90 s later → the unit
> powers itself back ON. Off-pad the latch drop is instant death anyway; on-pad it dies
> when lifted.
> - **No lift-and-replace gesture (was trigger 2).** Qi coil alignment means users routinely
> nudge a board on the pad — a lift+replace within 3 s = normal handling, not a deliberate
> act. Deliberate off is now the **`poweroff`** serial/telnet command; store-and-forget is
> the **30-min idle-on-pad** trigger (3).

**Core rule: `PWR_HOLD` stays HIGH the whole time the MCU is running, EXCEPT for three
explicit power-off triggers.** This is the fix for the otherwise-fatal conflict below.
Expand Down
Loading
Loading