Skip to content

Bound self-test completion and apply confirmed board requirements - #147

Merged
inez9 merged 1 commit into
mainfrom
pranay/self-test-confirmed-requirements
Nov 5, 2026
Merged

inez9 merged 1 commit into
mainfrom
pranay/self-test-confirmed-requirements

Conversation

@pranayD21

Copy link
Copy Markdown
Collaborator

Inez answered the self-test integration questions in #137. A stalled or retrying device previously had no overall scan deadline, and the caller had no completion flag independent of pass/fail. The coordinator now completes the inventory scan by a configurable deadline (29 seconds by default), marks unfinished devices as timed out, and exposes completion so the state machine can proceed to Idle even after failures.

  • Cap each probe callback by the remaining session budget; include optional/unstarted devices and reset the deadline on a new session.
  • Use mode 3 for the MS5611, matching the confirmed shared SPI3 configuration.
  • Require bounded SX1262 TxDone for radio-send success. Add timeout/unimplemented outcomes while preserving existing enum values.
  • Update the component map and integration requirements from Inez's response, including the confirmed H3LIS331DL, UART-only GNSS, SD NAND and post-ORing battery measurement.

Validation: both CTest suites pass with ASan/UBSan and in Release mode (17 coordinator test groups plus device protocol tests). The C++11 radio header passes warnings-as-errors syntax validation. Formatting and diff whitespace checks pass.

The STM32 target still cannot be built from this checkout: generated C is stale relative to Inez's updated .ioc, and target dependencies/build files are missing. This PR does not activate the task on hardware. Report storage/transmission and the actual Idle transition still need integration; the probe deadline alone is not a full boot deadline. Packet layout, report allocation, battery-source polarity and Arm policy remain tracked in #137.

Based on the current rewritten inez/flight_computer branch. The older documentation-only #143 predates that rewrite and now has an inflated diff; use this PR for the current confirmed requirements.

@inez9
inez9 force-pushed the inez/flight_computer branch from f8e110d to 0889ed1 Compare November 3, 2026 10:32
Base automatically changed from inez/flight_computer to main November 3, 2026 19:57
@inez9
inez9 force-pushed the pranay/self-test-confirmed-requirements branch from 4fe1c5b to 4cee224 Compare November 5, 2026 05:58
@inez9
inez9 merged commit b3e896c into main Nov 5, 2026
56 checks passed
@inez9
inez9 deleted the pranay/self-test-confirmed-requirements branch November 5, 2026 06:16
inez9 added a commit that referenced this pull request Nov 5, 2026
Brings in #148 (final fake radio, -Werror, CI job), #145 and #147 (the
radio.h contract: ErrTimeout, NotImplemented, radio_send Ok only after
TxDone). Conflicts:
- platformio.ini, test/test_radio_seam/*: main's versions (the merged
  #148 fake); this branch had an earlier copy of the same files.
- README.md: main's test counts and "Self-test integration" section,
  plus this branch's "Radio link status" section.
All 71 native tests pass with -Werror.
inez9 added a commit that referenced this pull request Nov 5, 2026
radio.h says a packet is 1 to 255 bytes, but the fake took len 0 (and a
null pointer) and answered Ok; memcpy from nullptr is also undefined
behaviour. The fake now asserts bytes != nullptr && len > 0, so a caller
that sends nothing stops the test run instead of passing. No new
RadioStatus value, so #147's contract is unchanged.

Checked with a small separate program: radio_send(nullptr, 0) aborts
(exit 134), a 1-byte send still answers Ok. 80/80 pass.
inez9 added a commit that referenced this pull request Nov 5, 2026
…150)

* Add fake radio and tests for the radio.h contract

A pretend radio that keeps packets in memory, plus 7 tests for what radio.h promises, so code that uses the radio can be tested on a laptop with no hardware.

* Add frame format and CRC-16 for the radio link

Encode and decode for heartbeat, self-test, ARM and UN_ARM frames: version, type, sequence number, length, payload and CRC-16. 16 host tests, including golden frames and a check that every single-bit flip is rejected.

* Add ARM safety gate: key check, two-frame confirm, replay rejection

ARM needs the right key and its inverse, the right target id, a newer sequence number, and a second ARM (seq+1) within 2 s. Any rejected ARM cancels a pending one. UN_ARM is always honored. 21 host tests, including wraparound of the sequence number and the millisecond counter.

* Add Link::poll: radio_receive -> decode_frame -> ARM gate

One call per main-loop pass drains at most one packet. Corrupt or malformed packets are counted and dropped before they reach the ARM gate. 8 host tests using the fake radio, including 200 random noise packets that must never arm.

* Add SX1262 receive path over an SpiBus interface

GetIrqStatus, GetRxBufferStatus, ReadBuffer, ClearIrqStatus, in that order, waiting for BUSY before each. Packets the chip flags as damaged, zero-length packets and packets too big for the caller are dropped and the flags cleared. 12 host tests against a pretend chip. Not yet run on real hardware: init, probe, pins and the real SpiBus are still to do.

* Document radio link status and what is still missing

* SX1262: report a missing radio instead of "no data" (review S1)

Sx1262::receive never looked at the status byte, so a missing chip or a
stuck MISO line (all 0x00 or all 0xFF) came back as NoData forever: 0x00
read as "no IRQ flags", 0xFF as "header + CRC error" and was cleared.
A dead radio looked like a quiet one.

Every "get" reply now has its status byte (reply byte 1) checked against
datasheet Rev 1.2, Table 13-76, p.95: chip mode (bits 6:4) must be 2..6,
and command status (bits 3:1) must not be 3 timeout, 4 processing error
or 5 failure to execute. Otherwise receive() returns ErrNotFound. 0x00
and 0xFF decode as modes 0 and 7.

Fake chip: its status byte was 0x2A, which decodes as STBY_RC + "failure
to execute"; now 0x54 (RX, data available). Adds set_status() and
set_stuck(level). Tests: stuck 0x00, stuck 0xFF, a failed command, and a
bad status in the second reply. Mutation-checked: accepting status 5,
or accepting chip mode 7, each turns one of them red. 75/75 pass.

* SX1262: add start_rx_continuous and state the RX requirement (review S2)

In single RX the chip returns to standby after one packet, and nothing in
the receive path put it back into RX. Sx1262::start_rx_continuous() sends
SetRx (0x82, datasheet Rev 1.2 p.62) with timeout 0xFFFFFF, continuous RX
(p.70). The class comment now says it must be called after start-up and
after every transmission, which leaves the chip in standby.

Fake chip records the bytes of the last command. Tests: the exact four
bytes go out after a BUSY check; nothing is sent if BUSY never clears.
Mutation-checked: timeout 0x000000 (single RX) turns the test red.
77/77 pass.

* SX1262: count packets the radio rejected (review S3)

Packets that fail the radio's own LoRa header or CRC check are discarded
and reported as NoData, so a bad antenna or too much range looked like
silence. Sx1262::crc_errors() counts them for telemetry. The header
notes it relies on LoRa CRC being enabled at start-up (review S4).

Test: one CRC error and one header error count 2, a good packet adds
nothing. Mutation-checked: removing the increment turns it red. 78/78.

* Link: count radio errors apart from bad frames (review L1)

ErrNotFound from the radio (chip not answering) went into
frames_dropped, the same counter as a bad CRC, so a dead radio and a
noisy channel looked the same. Link::radio_errors() now counts every
receive failure except ErrTooLong; ErrTooLong (a packet arrived but was
unusable) stays in frames_dropped.

Fake radio: fail_next_receive(status) makes the next radio_receive()
return that status once. Test: ErrNotFound and ErrTimeout count as 2
radio errors and 0 dropped frames. Mutation-checked: counting them as
dropped frames turns it red. 79/79 pass.

* Radio: keep packet buffers off the task stack (review L2)

Link::poll held a 255-byte packet buffer and a 254-byte Frame, and
Sx1262::receive two 258-byte ReadBuffer arrays: about 1.1 KB of stack per
poll, over twice the 512-byte default FreeRTOS task stack. They are now
members of Link and Sx1262 (one of each per radio task). ReadBuffer's
dummy bytes are still zeros.

Measured with arm-none-eabi-g++ -O2 -fstack-usage (Cortex-M7):
  Link::poll        536 -> 32 bytes
  Sx1262::receive   568 -> 48 bytes
79/79 native tests pass.

* ARM gate: pin the ground-station reboot behaviour (review A1, A2, A3)

If the ground station reboots and its sequence counter restarts, every
ARM is RejectStale until the rocket reboots. This fails safe, but on
launch day it looks like "ARM doesn't work". How to fix it (the ground
keeps its counter, or ARM carries a session number) is a protocol
decision, so it goes under "Decisions for the lead" in the README. No
behaviour changes here.

- test_ground_reboot_rejects_arm_until_rocket_reboots pins today's
  behaviour, so the chosen fix has to change this test on purpose:
  seq 100/101 arm, seq 1 and 2 are stale, UN_ARM still disarms.
- arm_gate.h: rule 3 says the ground counter must survive restarts; UN_ARM
  ignores the target id on purpose (A2); whether arming is allowed now is
  the state machine's decision, not the gate's (A3).
80/80 pass.

* Fake radio: refuse empty sends loudly (review #148 F2)

radio.h says a packet is 1 to 255 bytes, but the fake took len 0 (and a
null pointer) and answered Ok; memcpy from nullptr is also undefined
behaviour. The fake now asserts bytes != nullptr && len > 0, so a caller
that sends nothing stops the test run instead of passing. No new
RadioStatus value, so #147's contract is unchanged.

Checked with a small separate program: radio_send(nullptr, 0) aborts
(exit 134), a 1-byte send still answers Ok. 80/80 pass.

* Radio: start-up requirements and citation revision in comments (review S4-S6, L3)

Comments and README only, no code change:
- README "Not done yet": start-up must turn LoRa CRC on and call
  start_rx_continuous() after start-up and after every send; measured
  stack for Link::poll / Sx1262::receive and that both objects should be
  allocated once, statically.
- link.h: poll() drains one packet; the SX1262 holds one at a time.
- sx1262.h: the page citations are correct for datasheet Rev 1.2; the
  revision is now named (verified against DS.SX1261-2 Rev 1.2, June 2019:
  opcodes pp.62-64, IRQ table 13-29 p.80).
80/80 pass.

---------

Co-authored-by: inez9 <145737083+inez9@users.noreply.github.com>
inez9 added a commit that referenced this pull request Nov 6, 2026
)

* firmware: STM32 flight computer builds and uploads from PlatformIO

Move the CubeMX project (firmware.ioc, .mxproject, Core/, self-test host
tests) into firmware/Flight_Computer so the .ioc and the Core/ it generates
live together, and regenerate it with CubeMX 6.18 (Toolchain = CMake,
FW_H7 V1.13.0). The generated code now matches the .ioc: 8-bit SPI with
the right modes/prescalers, UART9 at 38400, 387.5-cycle ADC sampling,
chip-selects high and pyro enables low at boot, altimeter arm optos off.

PlatformIO:
- boards/star_fc_h723ve.json: STM32H723VET6, 512 KB flash. PlatformIO has
  no VET6 board and nucleo_h723zg is a 1 MB ZG part.
- [env:flight]: no framework, compiles CubeMX's own files, pins GCC 14.2
  (the platform's GCC 7.2 cannot link CubeMX's READONLY linker script),
  uploads over ST-Link. Default env, so VS Code's Upload button and
  `pio run -d firmware/Flight_Computer -e flight -t upload` target the board.
- scripts/fpu_link_flags.py passes the hard-float flags to the linker.

Docs:
- STM32-UPLOAD-REQUIREMENTS.md: tools, ST-Link wiring, upload steps (CLI and
  VS Code), schematic cross-check of every MCU pin, and the rules for the
  CubeMX project. AGENTS.md/CLAUDE.md point agents at it.
- DEVICE_CHECKS.md: U3 is the H3LIS100DLTR (confirmed on the assembled
  board); the rev 1 schematic, BOM and #137 still say H3LIS331DLTR. Cites
  DocID027504 Rev 2. Keeps #147's requirements.

format.sh skips ST's Drivers/ and Middlewares/ and the new generated system
files, and now skips .pio/ at any depth. CI points at the moved self-test.

Checked: flight build links (40 KB of 512 KB flash, hard-float ABI, vectors
at 0x08000000); self-test host tests pass under ASan/UBSan; 14 radio tests
pass; clang-format clean. Not yet run on hardware.

* firmware: board RAM is DTCM, f_cpu is 64 MHz; record SW_ST polarity

Review fixes for #165:
- star_fc_h723ve.json: maximum_ram_size 128 KB (the linker script puts
  .data/.bss/heap/stack in DTCMRAM, not the 320 KB RAM_D1), f_cpu 64 MHz
  (SYSCLK is HSI until HSE + PLL are configured). PlatformIO now reports
  RAM 32.9% of 128 KB instead of 13% of 320 KB.
- STM32-UPLOAD-REQUIREMENTS.md: drop the stale "no build target" status and
  the dead #build-path-open-decision link; add the DTCM/DMA rule (DMA1/2,
  BDMA and SDMMC IDMA can't reach DTCM) and the f_cpu/clock rule.
- DEVICE_CHECKS.md: SW_ST from the rev 1 schematic p.12: PE10 HIGH = battery,
  LOW = USB (TPS2121 IN1 = VBAT, ST pulled up by R65).

* firmware: RADIO_DIO1 (PB2) without pull-up

DIO1 is the SX1262's active-high IRQ and PB2 is a rising-edge EXTI. Nothing
on the board pulls it (schematic p.7), so the internal pull-up held the line
high while the radio sat in reset and could hide the first rising edge, the
one that wakes the MCU for an Arm. Now GPIO_NOPULL; the SX1262 drives DIO1
push-pull once it is out of reset. Regenerated with CubeMX 6.18; the only
code change is the pull setting in MX_GPIO_Init.
inez9 added a commit that referenced this pull request Nov 6, 2026
* Add fake radio and tests for the radio.h contract

A pretend radio that keeps packets in memory, plus 7 tests for what radio.h promises, so code that uses the radio can be tested on a laptop with no hardware.

* Add frame format and CRC-16 for the radio link

Encode and decode for heartbeat, self-test, ARM and UN_ARM frames: version, type, sequence number, length, payload and CRC-16. 16 host tests, including golden frames and a check that every single-bit flip is rejected.

* Add ARM safety gate: key check, two-frame confirm, replay rejection

ARM needs the right key and its inverse, the right target id, a newer sequence number, and a second ARM (seq+1) within 2 s. Any rejected ARM cancels a pending one. UN_ARM is always honored. 21 host tests, including wraparound of the sequence number and the millisecond counter.

* Add Link::poll: radio_receive -> decode_frame -> ARM gate

One call per main-loop pass drains at most one packet. Corrupt or malformed packets are counted and dropped before they reach the ARM gate. 8 host tests using the fake radio, including 200 random noise packets that must never arm.

* Add SX1262 receive path over an SpiBus interface

GetIrqStatus, GetRxBufferStatus, ReadBuffer, ClearIrqStatus, in that order, waiting for BUSY before each. Packets the chip flags as damaged, zero-length packets and packets too big for the caller are dropped and the flags cleared. 12 host tests against a pretend chip. Not yet run on real hardware: init, probe, pins and the real SpiBus are still to do.

* Document radio link status and what is still missing

* firmware: STM32 flight computer builds and uploads from PlatformIO

Move the CubeMX project (firmware.ioc, .mxproject, Core/, self-test host
tests) into firmware/Flight_Computer so the .ioc and the Core/ it generates
live together, and regenerate it with CubeMX 6.18 (Toolchain = CMake,
FW_H7 V1.13.0). The generated code now matches the .ioc: 8-bit SPI with
the right modes/prescalers, UART9 at 38400, 387.5-cycle ADC sampling,
chip-selects high and pyro enables low at boot, altimeter arm optos off.

PlatformIO:
- boards/star_fc_h723ve.json: STM32H723VET6, 512 KB flash. PlatformIO has
  no VET6 board and nucleo_h723zg is a 1 MB ZG part.
- [env:flight]: no framework, compiles CubeMX's own files, pins GCC 14.2
  (the platform's GCC 7.2 cannot link CubeMX's READONLY linker script),
  uploads over ST-Link. Default env, so VS Code's Upload button and
  `pio run -d firmware/Flight_Computer -e flight -t upload` target the board.
- scripts/fpu_link_flags.py passes the hard-float flags to the linker.

Docs:
- STM32-UPLOAD-REQUIREMENTS.md: tools, ST-Link wiring, upload steps (CLI and
  VS Code), schematic cross-check of every MCU pin, and the rules for the
  CubeMX project. AGENTS.md/CLAUDE.md point agents at it.
- DEVICE_CHECKS.md: U3 is the H3LIS100DLTR (confirmed on the assembled
  board); the rev 1 schematic, BOM and #137 still say H3LIS331DLTR. Cites
  DocID027504 Rev 2. Keeps #147's requirements.

format.sh skips ST's Drivers/ and Middlewares/ and the new generated system
files, and now skips .pio/ at any depth. CI points at the moved self-test.

Checked: flight build links (40 KB of 512 KB flash, hard-float ABI, vectors
at 0x08000000); self-test host tests pass under ASan/UBSan; 14 radio tests
pass; clang-format clean. Not yet run on hardware.

* firmware: board RAM is DTCM, f_cpu is 64 MHz; record SW_ST polarity

Review fixes for #165:
- star_fc_h723ve.json: maximum_ram_size 128 KB (the linker script puts
  .data/.bss/heap/stack in DTCMRAM, not the 320 KB RAM_D1), f_cpu 64 MHz
  (SYSCLK is HSI until HSE + PLL are configured). PlatformIO now reports
  RAM 32.9% of 128 KB instead of 13% of 320 KB.
- STM32-UPLOAD-REQUIREMENTS.md: drop the stale "no build target" status and
  the dead #build-path-open-decision link; add the DTCM/DMA rule (DMA1/2,
  BDMA and SDMMC IDMA can't reach DTCM) and the f_cpu/clock rule.
- DEVICE_CHECKS.md: SW_ST from the rev 1 schematic p.12: PE10 HIGH = battery,
  LOW = USB (TPS2121 IN1 = VBAT, ST pulled up by R65).

* firmware: RADIO_DIO1 (PB2) without pull-up

DIO1 is the SX1262's active-high IRQ and PB2 is a rising-edge EXTI. Nothing
on the board pulls it (schematic p.7), so the internal pull-up held the line
high while the radio sat in reset and could hide the first rising edge, the
one that wakes the MCU for an Arm. Now GPIO_NOPULL; the SX1262 drives DIO1
push-pull once it is out of reset. Regenerated with CubeMX 6.18; the only
code change is the pull setting in MX_GPIO_Init.

* firmware: boot no longer halts on an eMMC that isn't ready

MX_SDMMC1_MMC_Init() ran HAL_MMC_Init() during boot, which talks to the
eMMC while EMMC_RST (PA8) still holds it in reset. The init fails, and
Error_Handler() disables interrupts and spins, so nothing after it ran.
A dead or unpopulated eMMC would brick the board the same way.

- .ioc (Project Manager, Advanced): MX_SDMMC1_MMC_Init is generated but
  not called from main(), and is public (main.h). Regenerated with
  CubeMX 6.18; no other generated change.
- board.c/board.h: board_soft_init() runs a CubeMX init with
  Error_Handler() made non-fatal and reports whether it failed. The board
  layer will call the eMMC init after releasing its reset.
- Error_Handler (USER CODE): returns inside board_soft_init(); otherwise
  turns LED2 on before halting, so a fatal init error is visible.

* firmware: SPI bus layer for the flight computer

board_spi.c/.h is the one place that turns "talk to chip X" into
chip-select + HAL_SPI_TransmitReceive on the right bus:

- One FreeRTOS mutex per SPI peripheral (priority inheritance). SPI3 is
  shared by the IMU, high-g accelerometer and barometer.
- Every call takes an absolute deadline: the lock wait, the SX1262 BUSY
  wait and each transfer. Chip-select and the lock are released on every
  path, including errors and timeouts.
- board_spi_frame / board_spi_transfer for drivers; board_spi_idle_clocks
  (CS high, 0xFF) for the SD-card wake-up sequence.
- board_spi_self_test_exchange plugs into self_test_devices_t.exchange.
  It refuses (NOT_CONFIGURED) when the bus's mode differs from what the
  check asks for or its clock is above the chip's limit, instead of
  talking to the chip wrongly. Mode and clock are read back from the HAL
  handle and the RCC, so they follow the .ioc.

The device table is empty; each chip is routed in its own commit.

* firmware: IMU (ISM330DHCX) on SPI3

- board_spi: route BOARD_SPI_IMU to SPI3 with chip-select IMU_CS (PD7).
- board_bringup.c/.h (new): power/reset sequencing per chip and a probe
  for every self-test device ID. A device's check is enabled only after
  its startup steps are done. The IMU is on the always-on 3V3 rail; wait
  20 ms after reset for its ~10 ms boot, then enable it.
- The self-test's WHO_AM_I read (8F 00, expect 0x6B, mode 3, <= 10 MHz)
  now runs through the real bus: SPI3 is mode 3 at ~8.06 MHz.

* firmware: high-g accelerometer (H3LIS100DL) on SPI3

- board_spi: route BOARD_SPI_HIGH_G to SPI3 with chip-select ACCEL_CS
  (PD6), sharing the bus lock with the IMU and barometer.
- board_bringup: enable the high-g check after the IMU's 20 ms. The
  H3LIS100DL loads its trimming from internal flash at power-up
  (DocID027504 p.27) and specifies no separate boot time; it powers up in
  power-down (CTRL_REG1 = 0x07), which still answers WHO_AM_I.
- The self-test's identity read (8F 00, expect 0x32, mode 3, <= 10 MHz)
  matches SPI3's mode 3 at ~8.06 MHz.

* firmware: barometer (MS5611) on SPI3, with its power-on reset

- board_spi: route BOARD_SPI_BARO to SPI3 with chip-select BARO_CS (PD5).
  Add board_spi_select/deselect/shift for sequences that hold CS across a
  wait.
- board_bringup: send the MS5611 reset command (0x1E) once after power-on,
  as the datasheet requires before the PROM is valid (p.10). Figure 5 keeps
  CSB low through the 2.8 ms PROM reload, so CS is held low across
  osDelay(4) (>= 3 ms on a 1 kHz tick), under the SPI3 lock.
- The barometer check (PROM words + CRC4, mode 3, <= 20 MHz) is enabled
  only if the reset went out. SPI has no acknowledge, so a missing chip
  still passes this step; the self-test then rejects its blank PROM.

* firmware: Ethernet (W5500) on SPI2, out of reset

- board_spi: route BOARD_SPI_ETH to SPI2 with chip-select ETH_CS (PE14).
  SPI2 is mode 0 at ~16.1 MHz; the W5500 takes mode 0/3 up to 80 MHz.
- board_bringup: release ETH_RST (PE13), which MX_GPIO_Init holds low.
  W5500 v1.0.2 p.61: RSTn low >= 500 us (it has been low since boot), PLL
  lock <= 1 ms after RSTn rises; wait osDelay(3) (>= 2 ms), then enable
  the VERSIONR check (expect 0x04). No cable, PHY link or IP traffic.

* firmware: LoRa radio (SX1262) on SPI1, out of reset

- board_spi: route BOARD_SPI_RADIO to SPI1 with chip-select RADIO_CS
  (PC4) and BUSY (PC5). Every radio frame waits for BUSY low, bounded by
  the caller's deadline. SPI1 is mode 0 at ~8.06 MHz (SX1262: CPOL=0,
  CPHA=0, <= 16 MHz).
- board_bringup: release RADIO_NRST (PB0), which MX_GPIO_Init holds low
  (NRESET low typ. 100 us, DS 8.1 p.50), then wait up to 50 ms for BUSY
  to fall (STARTUP -> STDBY_RC, 8.2.2 / 9.1).
- The GetStatus/GetDeviceErrors check is enabled even if BUSY never falls:
  it then reports TIMEOUT, the truthful result for a radio that didn't
  start, rather than NOT_CONFIGURED. Nothing transmits; RF_SW stays low.

* firmware: GNSS (MAX-M10S) on UART9

- gnss_frame.c/.h (portable): byte-at-a-time validator for NMEA
  ($...*HH, XOR) and UBX (B5 62 ..., 8-bit Fletcher) frames, with length
  limits and a rejected-frame count.
- test_gnss_frame.c: vectors computed outside the code (the published GGA
  example *47; TXT and UBX-ACK checksums from Python). Covers valid frames,
  lower-case hex, wrong checksum, a flipped body byte, each corrupted UBX
  byte, noise and cut-off sentences, overlong lines, control bytes and the
  UBX length cap. Mutation-checked: accepting any NMEA checksum, a wrong
  Fletcher CK_B and allowing control bytes each turn the test red.
  Registered in the existing CMake project, so the CI job runs it.
- board_bringup: power the GPS (REG_3V6_EN PE11 -> 3V6 buck -> 3V3A LDO),
  wait 10 ms; GPS_RST is already released. The probe listens on UART9 for
  up to 1.5 s and passes on one valid frame (no fix required, #137).
  Baud is still open, so attempts 1/3 listen at 38400 and attempt 2 at
  9600; PASS reports the baud that worked. A miss reports TIMEOUT, flagged
  if GPS_ANT_STATUS (PD10) shows an antenna short. Nothing is sent to the
  module.

* firmware: SD NAND (ZDSD01GLGEAG) on SPI4, SD SPI mode

- sd_spi.c/.h (portable): CRC7, 6-byte command frames, R1/R7 checks and
  a CID check. 16 x 0xFF (a floating MISO) happens to satisfy CID CRC7,
  so uniform 0xFF/0x00 contents are rejected explicitly.
- test_sd_spi.c: CMD0 ...95 and CMD8 ...87 are the published constants;
  the other frames and the CID vector come from an independent Python
  CRC7. Mutation-checked: dropping the uniform-contents rule, a wrong CRC7
  polynomial and ignoring the R7 pattern each turn it red.
- board_spi: route BOARD_SPI_NAND to SPI4 with chip-select NAND_CS (PE4).
- board_bringup: read-only SD init at 250 kHz under the SPI4 lock:
  >= 74 wake clocks, CMD0 (expect idle), CMD8 (R7 echo 0x1AA), CMD55 +
  ACMD41 HCS until ready (<= 1 s), CMD58 (OCR), CMD10 (CID, after the
  0xFE data token). Nothing is written. FAIL/TIMEOUT report
  (stage << 8 | R1); PASS reports the CID manufacturer ID and the CCS bit.

* firmware: eMMC (THGBMTG5D1LBAIL) on SDMMC1

- .ioc: SDMMC1 ClockDiv 0 -> 3. With the 129 MHz SDMMC kernel clock,
  ClockDiv 0 ran transfers at 129 MHz; eMMC default speed is <= 26 MHz.
  129 / (2 x 3) = 21.5 MHz. Regenerated with CubeMX 6.18; the only code
  change is hmmc1.Init.ClockDiv (CubeMX wrote CRLF; normalized to LF).
- board_bringup: release EMMC_RST (PA8), held low by MX_GPIO_Init, and
  wait 2 ms. The probe runs CubeMX's MX_SDMMC1_MMC_Init() through
  board_soft_init(), so a missing or dead eMMC is a FAIL with the HAL
  error code instead of a halted board. HAL_MMC_Init completes the full
  identification and the CMD6 switch to 4-bit (a bus-width setting, no
  stored data). Then the CID is read and the card must be in TRANSFER;
  PASS reports the CID manufacturer ID (Kioxia/Toshiba: 0x11). Retries
  DeInit first. HAL command timeouts, not budget_ms, bound the init.

* firmware: ADC1 analog inputs (battery, currents, pyro continuity)

- board_adc.c/.h: offset + linearity calibration once at bring-up
  (HAL_ADCEx_Calibration_Start, before any conversion), then one-channel
  conversions with MX_ADC1_Init's settings (16-bit, 387.5-cycle sampling
  for the TLV9004 buffers), only the channel changing. Covers all seven
  analog pins the .ioc already puts in analog mode: VBAT PA0 (INP16),
  EXT_SENSE_1 PA1 (INP17), PYRO_1/2_CONT PA2/PA3 (INP14/15), EXT_SENSE_2
  PA4 (INP18), ALT_CURR PC0 (INP10), CURR PC1 (INP11).
  board_adc_snapshot() reads them all for the bring-up report.
- board_bringup_read_battery: self_test_port_t.read_battery returning raw
  PA0 counts stamped with now_ms. Volts (x 0.3125, VREF+ 3V3) and the
  warn/fail thresholds stay with the battery adapter (#137, #162).
Read-only: nothing here drives a pyro output.

* firmware: run the self-test over every chip at boot

- bringup_task.c/.h: a FreeRTOS task (6 KB stack, started from main.c's
  RTOS_THREADS user block) that runs board_bringup_power_up() and then
  Pranay's self-test coordinator with board_bringup_probe and
  board_bringup_read_battery, then takes an ADC snapshot.
  - Config: 3 attempts per device, 2 s per call (GNSS listens 1.5 s, SD
    init up to 1 s; the coordinator needs callback <= tick / 3, tick 6 s),
    default 29 s session so it always finishes (#137). Checked on the host
    against self_test.c: this config is accepted and completes; a
    callback budget of 2001 ms is rejected, so the check can fail.
  - Required (LED2): IMU, high-g, baro, radio, eMMC, per Inez's #137
    proposal. Warn-only: GNSS, Ethernet, SD NAND. Not an arming policy.
  - publish_status is NULL: radio transmit is not written yet.
- Results without a console: LED1 fast blink while running, then 1 Hz;
  LED2 on if a required check failed. g_bringup_report (global) holds the
  live coordinator status and the ADC snapshot for the debugger.
- STM32-UPLOAD-REQUIREMENTS.md: "First power-up" table of LED meanings
  and how to read g_bringup_report.

Nothing enables a pyro output or transmits.

* SX1262: report a missing radio instead of "no data" (review S1)

Sx1262::receive never looked at the status byte, so a missing chip or a
stuck MISO line (all 0x00 or all 0xFF) came back as NoData forever: 0x00
read as "no IRQ flags", 0xFF as "header + CRC error" and was cleared.
A dead radio looked like a quiet one.

Every "get" reply now has its status byte (reply byte 1) checked against
datasheet Rev 1.2, Table 13-76, p.95: chip mode (bits 6:4) must be 2..6,
and command status (bits 3:1) must not be 3 timeout, 4 processing error
or 5 failure to execute. Otherwise receive() returns ErrNotFound. 0x00
and 0xFF decode as modes 0 and 7.

Fake chip: its status byte was 0x2A, which decodes as STBY_RC + "failure
to execute"; now 0x54 (RX, data available). Adds set_status() and
set_stuck(level). Tests: stuck 0x00, stuck 0xFF, a failed command, and a
bad status in the second reply. Mutation-checked: accepting status 5,
or accepting chip mode 7, each turns one of them red. 75/75 pass.

* SX1262: add start_rx_continuous and state the RX requirement (review S2)

In single RX the chip returns to standby after one packet, and nothing in
the receive path put it back into RX. Sx1262::start_rx_continuous() sends
SetRx (0x82, datasheet Rev 1.2 p.62) with timeout 0xFFFFFF, continuous RX
(p.70). The class comment now says it must be called after start-up and
after every transmission, which leaves the chip in standby.

Fake chip records the bytes of the last command. Tests: the exact four
bytes go out after a BUSY check; nothing is sent if BUSY never clears.
Mutation-checked: timeout 0x000000 (single RX) turns the test red.
77/77 pass.

* SX1262: count packets the radio rejected (review S3)

Packets that fail the radio's own LoRa header or CRC check are discarded
and reported as NoData, so a bad antenna or too much range looked like
silence. Sx1262::crc_errors() counts them for telemetry. The header
notes it relies on LoRa CRC being enabled at start-up (review S4).

Test: one CRC error and one header error count 2, a good packet adds
nothing. Mutation-checked: removing the increment turns it red. 78/78.

* Link: count radio errors apart from bad frames (review L1)

ErrNotFound from the radio (chip not answering) went into
frames_dropped, the same counter as a bad CRC, so a dead radio and a
noisy channel looked the same. Link::radio_errors() now counts every
receive failure except ErrTooLong; ErrTooLong (a packet arrived but was
unusable) stays in frames_dropped.

Fake radio: fail_next_receive(status) makes the next radio_receive()
return that status once. Test: ErrNotFound and ErrTimeout count as 2
radio errors and 0 dropped frames. Mutation-checked: counting them as
dropped frames turns it red. 79/79 pass.

* Radio: keep packet buffers off the task stack (review L2)

Link::poll held a 255-byte packet buffer and a 254-byte Frame, and
Sx1262::receive two 258-byte ReadBuffer arrays: about 1.1 KB of stack per
poll, over twice the 512-byte default FreeRTOS task stack. They are now
members of Link and Sx1262 (one of each per radio task). ReadBuffer's
dummy bytes are still zeros.

Measured with arm-none-eabi-g++ -O2 -fstack-usage (Cortex-M7):
  Link::poll        536 -> 32 bytes
  Sx1262::receive   568 -> 48 bytes
79/79 native tests pass.

* ARM gate: pin the ground-station reboot behaviour (review A1, A2, A3)

If the ground station reboots and its sequence counter restarts, every
ARM is RejectStale until the rocket reboots. This fails safe, but on
launch day it looks like "ARM doesn't work". How to fix it (the ground
keeps its counter, or ARM carries a session number) is a protocol
decision, so it goes under "Decisions for the lead" in the README. No
behaviour changes here.

- test_ground_reboot_rejects_arm_until_rocket_reboots pins today's
  behaviour, so the chosen fix has to change this test on purpose:
  seq 100/101 arm, seq 1 and 2 are stale, UN_ARM still disarms.
- arm_gate.h: rule 3 says the ground counter must survive restarts; UN_ARM
  ignores the target id on purpose (A2); whether arming is allowed now is
  the state machine's decision, not the gate's (A3).
80/80 pass.

* Fake radio: refuse empty sends loudly (review #148 F2)

radio.h says a packet is 1 to 255 bytes, but the fake took len 0 (and a
null pointer) and answered Ok; memcpy from nullptr is also undefined
behaviour. The fake now asserts bytes != nullptr && len > 0, so a caller
that sends nothing stops the test run instead of passing. No new
RadioStatus value, so #147's contract is unchanged.

Checked with a small separate program: radio_send(nullptr, 0) aborts
(exit 134), a 1-byte send still answers Ok. 80/80 pass.

* Radio: start-up requirements and citation revision in comments (review S4-S6, L3)

Comments and README only, no code change:
- README "Not done yet": start-up must turn LoRa CRC on and call
  start_rx_continuous() after start-up and after every send; measured
  stack for Link::poll / Sx1262::receive and that both objects should be
  allocated once, statically.
- link.h: poll() drains one packet; the SX1262 holds one at a time.
- sx1262.h: the page citations are correct for datasheet Rev 1.2; the
  revision is now named (verified against DS.SX1261-2 Rev 1.2, June 2019:
  opcodes pp.62-64, IRQ table 13-29 p.80).
80/80 pass.

* firmware: initialize the eMMC once per power-up

The bring-up probe re-ran DeInit + MX_SDMMC1_MMC_Init on every self-test
retry (up to 3 attempts). THGBMTG5D1LBAIL rev 1.0 p.28: "avoid any
excessive iteration of resets and initialization sequences (Device
identification mode) ... which may result in read disturb failure",
e.g. repeated CMD0 - CMD1.

The probe now identifies the card on its first attempt only and reports
that cached result on retries. hmmc1 stays READY for the eMMC log adapter
(emmc_stm32.c on inez/emmc), which takes over every transfer after
bring-up. Found while coordinating with that work.

* firmware: eMMC flight log, recording from ARMED

Adds the flight computer's eMMC (U9, KIOXIA THGBMTG5D1LBAIL, 4 GB) flight
log, following the Flight_computer.drawio state machine. At this stage
recording starts at ARMED, not LAUNCHED, because launch detection does not
exist yet. Self-test and Idle never read or write the card.

- flight_state: the diagram's transition table and which states record.
  A stand-in for the real state machine (#162).
- emmc_log: append-only raw-block log, no filesystem. Every 512 B block
  carries an epoch, its own position, its session and a CRC32, so a power
  cut can only lose the chunk in flight. The end is found at mount by
  binary search. Sensor tasks never wait on the card: records go into
  16 KB RAM chunks; one writer task does all I/O; when full, records are
  dropped, counted and reported.
- emmc_card: CID/EXT_CSD checks against the datasheet.
- emmc_port: the seam, so the log runs on a laptop against a RAM disk.
- emmc_stm32: SDMMC1 + IDMA adapter. NOT YET COMPILED (the build comes
  with #165); its DMA buffers need a RAM_D1 linker section first.
- tests/emmc: 3 host suites, new CI job stm32-emmc-host. Five deliberate
  breaks of the code were each caught by the matching test.
- EMMC-ARCHITECTURE.md: design, datasheet facts, integration status.

Datasheet: https://datasheet.lcsc.com/datasheet/pdf/ea386c834ed06c7e4629df6606f52741.pdf
Refs #137

* firmware: CubeMX for interrupt-driven, RTOS-safe chip communication

.ioc (regenerated with CubeMX 6.18; generated diff checked line by line):
- NVIC on for EXTI0 (IMU_INT1 PD0), EXTI2 (RADIO_DIO1 PB2), EXTI3
  (ACCEL_INT_1 PD3), EXTI15_10 (ETH_INT PE15), UART9, SDMMC1, TIM2. All at
  priority 5 = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, so their ISRs
  may wake tasks (CubeMX clamps "uses FreeRTOS functions" IRQs to >= 5).
- ETH_INT on the falling edge: W5500 INTn is active low (W5500 v1.0.2,
  p.10, pin 36); it was rising.
- SPI1-4 Master Receiver Auto-Suspend: when a task is preempted mid
  transfer the master stops the clock instead of overrunning its RX FIFO
  (RM0468 Rev 3, MASRX, p.2201).
- TIM2 prescaler 63: a free-running 32-bit 1 MHz timebase at today's
  64 MHz timer clock; CH4 still captures GPS TIMEPULSE on the same clock.
- UART9 hardware FIFO on, RX interrupt at half full.
- The watchdog is NOT enabled yet; it comes with the task that feeds it.

Linker: a .dma_buffers (NOLOAD) section in RAM_D1. .data/.bss/stack are
in DTCM, which only the core and MDMA can reach (RM0468 Table 2 p.106,
Section 2.1.2 p.108), not the SDMMC IDMA or DMA1/2. board.h
BOARD_DMA_BUFFER places a buffer there (checked: a test buffer linked at
0x24000000). CubeMX leaves an existing linker script alone (checked).

scripts/cubemx_generate.sh regenerates without the GUI and restores each
file's line endings as git has them (CubeMX's CLI writes CRLF).

* eMMC: put the adapter's DMA buffers in RAM_D1

As agreed with the eMMC log work: chunks (64 KB), scratch and ext_csd
(512 B each) now use BOARD_DMA_BUFFER, i.e. the .dma_buffers NOLOAD
section in AXI SRAM, instead of plain aligned(32) .bss, which this
linker script places in DTCM where the SDMMC IDMA cannot reach (start()
would have refused with EMMC_ERR_PARAM). Checked in the object file: all
three are in .dma_buffers, 32-byte aligned. First compile of
emmc_stm32.c for the STM32: no errors or warnings.

* firmware: microsecond timebase and interrupt routing to tasks

- board_time: TIM2 as a free-running 32-bit 1 MHz counter (wraps every
  ~71.6 min) for every sample timestamp; CH4 captures the GPS TIMEPULSE
  (PB11) on the same counter. board_time_start() computes TIM2's real
  kernel clock from RCC (RM0468 Rev 3, RCC_CFGR.TIMPRE rule, p.371) and
  returns false if prescaler + clock tree don't give exactly 1 MHz, so a
  later HSE/PLL change can't silently skew timestamps. Started first in
  bring-up; the result is kept in board_bringup_t.time_ok.
- board_exti: HAL_GPIO_EXTI_Callback stamps each edge with board_time_us()
  and sets the owning task's thread flags (osThreadFlagsSet, ISR-safe).
  Routes: IMU_INT1 PD0 and ACCEL_INT_1 PD3 (sensors), RADIO_DIO1 PB2
  (radio), ETH_INT PE15 (ethernet). No bus traffic in any ISR.

* firmware: IMU driver (ISM330DHCX), portable and host-tested

drivers/ holds chip drivers that see only dev_bus_t (one chip-select
frame + a delay), so the same code runs on board_spi and on a scripted
fake in host tests. The board build compiles drivers/*.c.

dev_ism330dhcx (DS13012 Rev 7):
- WHO_AM_I 0x6B (p.48) before any write; SW_RESET in CTRL3_C, polled
  until it self-clears, bounded at 10 ms (p.51)
- CTRL3_C 0x44 BDU + IF_INC (p.51), CTRL4_C 0x04 I2C_disable (p.52),
  CTRL1_XL 0x74 833 Hz +-16 g (p.49), CTRL2_G 0x71 833 Hz +-4000 dps
  (p.50), COUNTER_BDR_REG1 0x80 pulsed data-ready (p.46), INT1_CTRL 0x01
  accel DRDY on INT1 (p.47); every register read back and verified
- one 14-byte burst from OUT_TEMP_L (20h): temp, gyro, accel (p.64-66)
- scale 0.488 mg/LSB, 140 mdps/LSB (p.10); 256 LSB/degC, 0 at 25 degC
  (p.13, Table 4 note 4)

tests/drivers: fake_regs (register-file fake: auto-increment, MS bit,
self-clearing bits, stuck bits, bus failure) and 8 IMU tests: exact
config bytes in order, wrong ID refused before any write, dead bus
(0xFF), reset timeout, read-back mismatch, bus error, burst decode,
bad arguments. Mutation-checked: +-2 g instead of +-16 g, and skipping
the read-back check, each turn a test red. ASan/UBSan clean.

* firmware: high-g accelerometer driver (H3LIS100DL)

dev_h3lis100dl (DocID027504 Rev 2; the board carries the H3LIS100DLTR,
not the H3LIS331DLTR on the rev 1 schematic):
- SPI first byte: RW bit 7, MS (auto-increment) bit 6, 6-bit address
  (p.20); WHO_AM_I 0x32 before any write (p.25). The H3LIS331DL also
  answers 0x32, so identity alone can't tell them apart.
- CTRL_REG4 0x00 4-wire SPI, CTRL_REG3 0x02 INT1 = data ready, active
  high, push-pull (p.28, Table 27), CTRL_REG1 0x37 normal mode 400 Hz
  X/Y/Z (p.25-26, Tables 19-20), written last; each read back.
- one 5-byte MS burst from 29h: X, Y, Z at 29h/2Bh/2Dh, 8-bit two's
  complement (p.30), 780 mg/digit, fixed +-100 g (p.9).
- The DRDY line is a level, so the sensor task must also read on a
  timeout (noted in the header).

6 tests: exact config, wrong ID refused before any write, read-back
mismatch, bus error, X/Y/Z from the right registers (reserved bytes
skipped), MS-bit guard. Mutation-checked: dropping the MS bit and
100 Hz instead of 400 Hz each turn a test red.

* firmware: barometer driver (MS5611) with datasheet compensation

dev_ms5611 (MS5611-01BA03 datasheet 06/2017, AN520):
- PROM read 0xA0..0xAE (p.10 Figure 4), AN520 CRC4; blank (all 0 / all
  1) PROM rejected before the CRC, since a dead bus can match by chance
- D1 0x48 / D2 0x58 at OSR 4096, read with 0x00 >= 10 ms later (9.04 ms
  max, p.3); an ADC result of 0 means read too early -> DEV_ERR_DATA
- first-order (p.8) and second-order (p.9, below 20 degC and below
  -15 degC) compensation in 64-bit integers with C division, exactly as
  the datasheet; temperature in 0.01 degC, pressure in Pa
- the power-on reset with CSB held low stays in board_bringup

test_ms5611 (command-driven fake chip): PROM + CRC (vector computed with
AN520 in Python), flipped bit / all 0 / all 1 rejected, D1/D2 commands
and early-read 0, the datasheet worked example (TEMP 2007, P 100009),
and two second-order vectors (11.75 degC; -30.22 degC very-low branch)
from an independent Python model using C truncating division.
Mutation-checked: no second order, >> instead of / (floor vs truncate),
and skipping the CRC each turn a test red.

* firmware: sensors task: IMU, high-g and baro on interrupts under RTOS

app/ holds the application. Each task is a portable core (no HAL, no RTOS;
time and events passed in) plus a thin RTOS loop, so flight_test can run
the same code on a laptop.

- app/records.h: record types 0x10+ (IMU, high-g, baro, ...) and packed
  little-endian payloads with pinned sizes; every one starts with t_us.
- app/sensors_core: SPI3 state machine. IMU read on its data-ready edge,
  stamped with the edge time from board_exti; high-g likewise, and read
  on a 2-period timeout when no edge comes (its DRDY is a level, so a
  missed read would otherwise silence it; counted as missed_drdy); baro
  D1 -> 10 ms -> D2 -> 10 ms -> compensate, ~50 Hz. A sensor whose init
  fails, or that fails 3 reads in a row, is re-initialized every second.
- app/sensors_task: Realtime priority, routes IMU_INT1/ACCEL_INT_1 to its
  thread flags, sleeps until an edge or the core's next deadline, appends
  each record to the eMMC log (emmc_log_append, non-blocking).
- app/app: app_start() brings up the eMMC log (emmc_stm32_init + its
  writer task) and the sensors task; bringup_task calls it after the
  self-test, so every chip is out of reset first.
- Core/board_devbus: dev_bus_t over board_spi (one locked CS frame,
  5 ms deadline; delay = osDelay(ms + 1), which is >= ms).
- tests/fakes: fake_regs moved here, fake_baro shared (was private to
  test_ms5611). tests/app/test_sensors_core: virtual clock with a 37 us
  task wake latency: rates (833 / 400 / ~50 Hz), values, edge-time
  stamps, high-g timeout reads, IMU failure -> dropped -> recovered,
  wrong chip keeps retrying, dead baro bus, deadlines, 32-bit clock
  wrap. Mutation-checked: no high-g timeout read, IMU stamped at read
  time, failed IMU never retried each turn it red.

Firmware: RAM_D1 now holds the eMMC log's 65 KB of DMA buffers.

* firmware: move chip drivers from drivers/ to chips/

macOS file systems are case-insensitive, so drivers/ and CubeMX's
Drivers/ (ST HAL + CMSIS) were the same folder on a Mac: the drivers
were committed under Drivers/, inside the vendored code. On Linux (CI,
teammates) platformio.ini's ../drivers would not have existed, and
format.sh skipped them as vendored (Flight_Computer/Drivers is in its
skip list).

chips/ cannot collide with anything CubeMX generates. tests/drivers ->
tests/chips; platformio.ini, both test CMakeLists and dev_bus.h updated.
No code change. Checked: nothing of ours left under Drivers/ in git;
firmware builds; chips (3) and app (1) host suites pass under
ASan/UBSan; format.sh now checks all 7 chip files (dev_bus.h needed
reformatting, done).

* firmware: UBX protocol for the MAX-M10S (VALSET, NAV-PVT)

chips/ubx (u-blox M10 SPG 5.10 Interface Description, UBX-21035062 R02):
- ubx_frame: B5 62 class id len payload + 8-bit Fletcher
- ubx_valset: UBX-CFG-VALSET (0x06 0x8A, 3.10.5.1 p.55), version 0,
  RAM layer only (re-sent every power-up, nothing burnt to flash)
- ubx_parse_nav_pvt: UBX-NAV-PVT (0x01 0x07, 92 bytes, 3.15.11 p.95)
- keys: CFG-UART1-BAUDRATE 0x40520001 (p.153), CFG-UART1OUTPROT-NMEA
  0x10740002 (p.154), CFG-MSGOUT-UBX_NAV_PVT_UART1 0x20910007 (p.136),
  CFG-RATE-MEAS 0x30210001 (p.147), CFG-NAVSPG-DYNMODEL 0x20110021 with
  AIR4 = 8 "airborne <4g" (Table 23, p.141), the highest model there is

Core/gnss_frame: keeps the class, id, length and first 100 payload bytes
of each UBX frame, so one byte-at-a-time parser serves the self-test
probe and the GNSS task.

Datasheet facts for the GNSS task (MAX-M10S data sheet UBX-20035208 R02):
the default UART is 9600 baud (5.3, p.13), not the 38400 assumed in
#137; 10 Hz NAV-PVT (~1000 B/s) does not fit at 9600, so the task will
raise the module to 115200. PVT up to 10 Hz (p.4).

test_ubx: VALSET frames and a NAV-PVT frame encoded independently in
Python, decoded through gnss_frame + ubx_parse_nav_pvt. Mutation-checked:
writing all layers (incl. flash) and reading velD from the wrong offset
each turn it red.

* firmware: GPS task: MAX-M10S on interrupt-driven UART9, 10 Hz NAV-PVT

board_uart9 (Core): HAL ReceiveToIdle interrupts (UART FIFO at half
full, from the .ioc) into a 1 KB single-producer/single-consumer ring;
each burst sets the GNSS task's thread flag. No DMA, so no DTCM issue.
Blocking 100 ms-bounded transmit for the short UBX config frames;
set_baud re-inits UART9 and re-arms receive.

gnss_core (app, portable):
- DETECT: listen 1.5 s each at 9600 (the module's default, data sheet
  UBX-20035208 p.13), 38400, 115200 for one valid NMEA/UBX frame
- CONFIG: VALSET CFG-UART1-BAUDRATE 115200 if lower (10 Hz PVT is
  ~1000 B/s, more than 9600 baud carries), then NMEA off, NAV-PVT on
  UART1, CFG-RATE-MEAS 100 ms, dynamic model AIR4; waits for ACK-ACK of
  CFG-VALSET, 3 tries of 500 ms; a NAK restarts detection
- RUN: every NAV-PVT -> REC_GNSS (rec_gnss_t, 49 bytes) stamped with its
  arrival and the latest TIMEPULSE edge (TIM2 CH4); 2 s without a fix
  -> back to DETECT, so a power-cycled module (RAM config lost) is
  reconfigured
gnss_task: Normal priority, woken by received bytes or the core's next
deadline. Started from app_start after the sensors task.
records.h: record_sink_t shared by the task cores (sensors_sink_t is now
an alias).

AIR4 is the highest dynamic model the M10 has (Table 23, p.141); a boost
above 4 g can lose the fix, which the 2 s watchdog then recovers.

Tests:
- fake_gnss: a simulated MAX-M10S that parses VALSET itself, sizing each
  value from the key ID (bits 30..28, Interface Description p.124), only
  hears the board at a matching baud, and sends garbage at a wrong one
- test_gnss_core: cold start at 9600, warm module at 115200, NAK,
  silence + power cycle, PPS stamping. Mutation-checked: skipping the
  baud change, treating NAK as ACK, ignoring silence each turn it red
The end-to-end [gps] check lives on inez/flight/flight_test.

* firmware: task-core comments name the host tests, not a tool on another branch

* firmware: link newlib-nano in the PlatformIO build, as CubeMX does

CubeMX's cmake/gcc-arm-none-eabi.cmake links with --specs=nano.specs;
env:flight did not, so the two builds of one project used different C
libraries. With the full newlib, one vsnprintf (the boot report) cost
~29 KB of flash; with nano the image is 69.7 KB instead of 98.2 KB.
Nano's printf has no float support; no firmware code prints floats.

* firmware: start-up self-test reports battery voltage and a verdict

The self-test already checked every chip at boot (IMU/high-g WHO_AM_I,
baro PROM CRC, W5500 version, SX1262 status, GPS frame, SD NAND CID,
eMMC CID) and read raw PA0 counts. Missing was the battery adapter and a
report a person can read.

app/battery: counts -> mV -> health.
- Schematic rev 1 p.2: VDD -> R1 22k / R3 10k (x 0.3125) -> TLV9004
  follower -> PA0; VREF+ = VDDA = 3V3 through FB1. p.12: 3V3 from the
  TPS562201, 0.768 V x (1 + 33.2k/10k) = 3.318 V (~ +/-2 %).
  mV = counts x 10624 / 65535, the same as Aaron's idle module (#162).
- p.12: VDD is the TPS2121's output (IN1 battery, IN2 USB; battery wins
  above ~3.5 V). SW_ST (PE10) HIGH = battery, LOW = USB (TPS2121 p.21).
  On USB the reading is USB_5V and is never judged as the pack.
- OK >= 7.0 V, WARN < 7.0 V, FAIL < 6.6 V (proposals, the same as #162),
  FAIL > 8.8 V (above a full 2S pack + 2 %: wrong pack or divider).
board_bringup_read_battery now averages 16 conversions within its
budget; board_bringup_on_usb reads SW_ST.

app/boot_report: verdict (READY / WARN / FAIL), result_bits (bit =
device id passed: the SelfTest radio frame's field, src/frame.h) and a
text report, one line per chip plus the battery and the verdict. The
GPS line shows the baud it was heard at. FAIL = a required chip
(IMU, high-g, baro, radio, eMMC) failed or the battery is FAIL/unread;
WARN = an optional chip (GPS, Ethernet, SD NAND) failed or the battery
is low. Required vs optional is #137's proposal, not an arming policy.

bringup_task: builds the report into g_bringup_report.report after the
checks (battery sampled before anything transmits). LED2: off READY,
blinking WARN, solid FAIL. In the debugger:
printf "%s", g_bringup_report.report.text

test_boot_report: conversion against counts computed independently in
Python (incl. #162's 40712 -> 6600, 51818 -> 8400), every threshold edge,
USB, ADC failure, each verdict, the exact text. Mutation-checked:
ignoring SW_ST, dropping the WARN band and counting optional failures as
required each turn it red.

* firmware: build with debug info so gdb can read the board over ST-Link

env:flight compiled without -g, so the ELF had no symbol types and gdb
answered "'g_bringup_report' has unknown type": the self-test report
could not be read over SWD, by a person or by flight_test --board.
-g3 adds debug sections to the .elf only; the flashed image is the same
size (69,656 bytes) and the same code.

---------

Co-authored-by: R-Leano <ryanleanoj@gmail.com>
inez9 added a commit that referenced this pull request Nov 6, 2026
* Add fake radio and tests for the radio.h contract

A pretend radio that keeps packets in memory, plus 7 tests for what radio.h promises, so code that uses the radio can be tested on a laptop with no hardware.

* Add frame format and CRC-16 for the radio link

Encode and decode for heartbeat, self-test, ARM and UN_ARM frames: version, type, sequence number, length, payload and CRC-16. 16 host tests, including golden frames and a check that every single-bit flip is rejected.

* Add ARM safety gate: key check, two-frame confirm, replay rejection

ARM needs the right key and its inverse, the right target id, a newer sequence number, and a second ARM (seq+1) within 2 s. Any rejected ARM cancels a pending one. UN_ARM is always honored. 21 host tests, including wraparound of the sequence number and the millisecond counter.

* Add Link::poll: radio_receive -> decode_frame -> ARM gate

One call per main-loop pass drains at most one packet. Corrupt or malformed packets are counted and dropped before they reach the ARM gate. 8 host tests using the fake radio, including 200 random noise packets that must never arm.

* Add SX1262 receive path over an SpiBus interface

GetIrqStatus, GetRxBufferStatus, ReadBuffer, ClearIrqStatus, in that order, waiting for BUSY before each. Packets the chip flags as damaged, zero-length packets and packets too big for the caller are dropped and the flags cleared. 12 host tests against a pretend chip. Not yet run on real hardware: init, probe, pins and the real SpiBus are still to do.

* Document radio link status and what is still missing

* firmware: STM32 flight computer builds and uploads from PlatformIO

Move the CubeMX project (firmware.ioc, .mxproject, Core/, self-test host
tests) into firmware/Flight_Computer so the .ioc and the Core/ it generates
live together, and regenerate it with CubeMX 6.18 (Toolchain = CMake,
FW_H7 V1.13.0). The generated code now matches the .ioc: 8-bit SPI with
the right modes/prescalers, UART9 at 38400, 387.5-cycle ADC sampling,
chip-selects high and pyro enables low at boot, altimeter arm optos off.

PlatformIO:
- boards/star_fc_h723ve.json: STM32H723VET6, 512 KB flash. PlatformIO has
  no VET6 board and nucleo_h723zg is a 1 MB ZG part.
- [env:flight]: no framework, compiles CubeMX's own files, pins GCC 14.2
  (the platform's GCC 7.2 cannot link CubeMX's READONLY linker script),
  uploads over ST-Link. Default env, so VS Code's Upload button and
  `pio run -d firmware/Flight_Computer -e flight -t upload` target the board.
- scripts/fpu_link_flags.py passes the hard-float flags to the linker.

Docs:
- STM32-UPLOAD-REQUIREMENTS.md: tools, ST-Link wiring, upload steps (CLI and
  VS Code), schematic cross-check of every MCU pin, and the rules for the
  CubeMX project. AGENTS.md/CLAUDE.md point agents at it.
- DEVICE_CHECKS.md: U3 is the H3LIS100DLTR (confirmed on the assembled
  board); the rev 1 schematic, BOM and #137 still say H3LIS331DLTR. Cites
  DocID027504 Rev 2. Keeps #147's requirements.

format.sh skips ST's Drivers/ and Middlewares/ and the new generated system
files, and now skips .pio/ at any depth. CI points at the moved self-test.

Checked: flight build links (40 KB of 512 KB flash, hard-float ABI, vectors
at 0x08000000); self-test host tests pass under ASan/UBSan; 14 radio tests
pass; clang-format clean. Not yet run on hardware.

* firmware: board RAM is DTCM, f_cpu is 64 MHz; record SW_ST polarity

Review fixes for #165:
- star_fc_h723ve.json: maximum_ram_size 128 KB (the linker script puts
  .data/.bss/heap/stack in DTCMRAM, not the 320 KB RAM_D1), f_cpu 64 MHz
  (SYSCLK is HSI until HSE + PLL are configured). PlatformIO now reports
  RAM 32.9% of 128 KB instead of 13% of 320 KB.
- STM32-UPLOAD-REQUIREMENTS.md: drop the stale "no build target" status and
  the dead #build-path-open-decision link; add the DTCM/DMA rule (DMA1/2,
  BDMA and SDMMC IDMA can't reach DTCM) and the f_cpu/clock rule.
- DEVICE_CHECKS.md: SW_ST from the rev 1 schematic p.12: PE10 HIGH = battery,
  LOW = USB (TPS2121 IN1 = VBAT, ST pulled up by R65).

* firmware: RADIO_DIO1 (PB2) without pull-up

DIO1 is the SX1262's active-high IRQ and PB2 is a rising-edge EXTI. Nothing
on the board pulls it (schematic p.7), so the internal pull-up held the line
high while the radio sat in reset and could hide the first rising edge, the
one that wakes the MCU for an Arm. Now GPIO_NOPULL; the SX1262 drives DIO1
push-pull once it is out of reset. Regenerated with CubeMX 6.18; the only
code change is the pull setting in MX_GPIO_Init.

* firmware: boot no longer halts on an eMMC that isn't ready

MX_SDMMC1_MMC_Init() ran HAL_MMC_Init() during boot, which talks to the
eMMC while EMMC_RST (PA8) still holds it in reset. The init fails, and
Error_Handler() disables interrupts and spins, so nothing after it ran.
A dead or unpopulated eMMC would brick the board the same way.

- .ioc (Project Manager, Advanced): MX_SDMMC1_MMC_Init is generated but
  not called from main(), and is public (main.h). Regenerated with
  CubeMX 6.18; no other generated change.
- board.c/board.h: board_soft_init() runs a CubeMX init with
  Error_Handler() made non-fatal and reports whether it failed. The board
  layer will call the eMMC init after releasing its reset.
- Error_Handler (USER CODE): returns inside board_soft_init(); otherwise
  turns LED2 on before halting, so a fatal init error is visible.

* firmware: SPI bus layer for the flight computer

board_spi.c/.h is the one place that turns "talk to chip X" into
chip-select + HAL_SPI_TransmitReceive on the right bus:

- One FreeRTOS mutex per SPI peripheral (priority inheritance). SPI3 is
  shared by the IMU, high-g accelerometer and barometer.
- Every call takes an absolute deadline: the lock wait, the SX1262 BUSY
  wait and each transfer. Chip-select and the lock are released on every
  path, including errors and timeouts.
- board_spi_frame / board_spi_transfer for drivers; board_spi_idle_clocks
  (CS high, 0xFF) for the SD-card wake-up sequence.
- board_spi_self_test_exchange plugs into self_test_devices_t.exchange.
  It refuses (NOT_CONFIGURED) when the bus's mode differs from what the
  check asks for or its clock is above the chip's limit, instead of
  talking to the chip wrongly. Mode and clock are read back from the HAL
  handle and the RCC, so they follow the .ioc.

The device table is empty; each chip is routed in its own commit.

* firmware: IMU (ISM330DHCX) on SPI3

- board_spi: route BOARD_SPI_IMU to SPI3 with chip-select IMU_CS (PD7).
- board_bringup.c/.h (new): power/reset sequencing per chip and a probe
  for every self-test device ID. A device's check is enabled only after
  its startup steps are done. The IMU is on the always-on 3V3 rail; wait
  20 ms after reset for its ~10 ms boot, then enable it.
- The self-test's WHO_AM_I read (8F 00, expect 0x6B, mode 3, <= 10 MHz)
  now runs through the real bus: SPI3 is mode 3 at ~8.06 MHz.

* firmware: high-g accelerometer (H3LIS100DL) on SPI3

- board_spi: route BOARD_SPI_HIGH_G to SPI3 with chip-select ACCEL_CS
  (PD6), sharing the bus lock with the IMU and barometer.
- board_bringup: enable the high-g check after the IMU's 20 ms. The
  H3LIS100DL loads its trimming from internal flash at power-up
  (DocID027504 p.27) and specifies no separate boot time; it powers up in
  power-down (CTRL_REG1 = 0x07), which still answers WHO_AM_I.
- The self-test's identity read (8F 00, expect 0x32, mode 3, <= 10 MHz)
  matches SPI3's mode 3 at ~8.06 MHz.

* firmware: barometer (MS5611) on SPI3, with its power-on reset

- board_spi: route BOARD_SPI_BARO to SPI3 with chip-select BARO_CS (PD5).
  Add board_spi_select/deselect/shift for sequences that hold CS across a
  wait.
- board_bringup: send the MS5611 reset command (0x1E) once after power-on,
  as the datasheet requires before the PROM is valid (p.10). Figure 5 keeps
  CSB low through the 2.8 ms PROM reload, so CS is held low across
  osDelay(4) (>= 3 ms on a 1 kHz tick), under the SPI3 lock.
- The barometer check (PROM words + CRC4, mode 3, <= 20 MHz) is enabled
  only if the reset went out. SPI has no acknowledge, so a missing chip
  still passes this step; the self-test then rejects its blank PROM.

* firmware: Ethernet (W5500) on SPI2, out of reset

- board_spi: route BOARD_SPI_ETH to SPI2 with chip-select ETH_CS (PE14).
  SPI2 is mode 0 at ~16.1 MHz; the W5500 takes mode 0/3 up to 80 MHz.
- board_bringup: release ETH_RST (PE13), which MX_GPIO_Init holds low.
  W5500 v1.0.2 p.61: RSTn low >= 500 us (it has been low since boot), PLL
  lock <= 1 ms after RSTn rises; wait osDelay(3) (>= 2 ms), then enable
  the VERSIONR check (expect 0x04). No cable, PHY link or IP traffic.

* firmware: LoRa radio (SX1262) on SPI1, out of reset

- board_spi: route BOARD_SPI_RADIO to SPI1 with chip-select RADIO_CS
  (PC4) and BUSY (PC5). Every radio frame waits for BUSY low, bounded by
  the caller's deadline. SPI1 is mode 0 at ~8.06 MHz (SX1262: CPOL=0,
  CPHA=0, <= 16 MHz).
- board_bringup: release RADIO_NRST (PB0), which MX_GPIO_Init holds low
  (NRESET low typ. 100 us, DS 8.1 p.50), then wait up to 50 ms for BUSY
  to fall (STARTUP -> STDBY_RC, 8.2.2 / 9.1).
- The GetStatus/GetDeviceErrors check is enabled even if BUSY never falls:
  it then reports TIMEOUT, the truthful result for a radio that didn't
  start, rather than NOT_CONFIGURED. Nothing transmits; RF_SW stays low.

* firmware: GNSS (MAX-M10S) on UART9

- gnss_frame.c/.h (portable): byte-at-a-time validator for NMEA
  ($...*HH, XOR) and UBX (B5 62 ..., 8-bit Fletcher) frames, with length
  limits and a rejected-frame count.
- test_gnss_frame.c: vectors computed outside the code (the published GGA
  example *47; TXT and UBX-ACK checksums from Python). Covers valid frames,
  lower-case hex, wrong checksum, a flipped body byte, each corrupted UBX
  byte, noise and cut-off sentences, overlong lines, control bytes and the
  UBX length cap. Mutation-checked: accepting any NMEA checksum, a wrong
  Fletcher CK_B and allowing control bytes each turn the test red.
  Registered in the existing CMake project, so the CI job runs it.
- board_bringup: power the GPS (REG_3V6_EN PE11 -> 3V6 buck -> 3V3A LDO),
  wait 10 ms; GPS_RST is already released. The probe listens on UART9 for
  up to 1.5 s and passes on one valid frame (no fix required, #137).
  Baud is still open, so attempts 1/3 listen at 38400 and attempt 2 at
  9600; PASS reports the baud that worked. A miss reports TIMEOUT, flagged
  if GPS_ANT_STATUS (PD10) shows an antenna short. Nothing is sent to the
  module.

* firmware: SD NAND (ZDSD01GLGEAG) on SPI4, SD SPI mode

- sd_spi.c/.h (portable): CRC7, 6-byte command frames, R1/R7 checks and
  a CID check. 16 x 0xFF (a floating MISO) happens to satisfy CID CRC7,
  so uniform 0xFF/0x00 contents are rejected explicitly.
- test_sd_spi.c: CMD0 ...95 and CMD8 ...87 are the published constants;
  the other frames and the CID vector come from an independent Python
  CRC7. Mutation-checked: dropping the uniform-contents rule, a wrong CRC7
  polynomial and ignoring the R7 pattern each turn it red.
- board_spi: route BOARD_SPI_NAND to SPI4 with chip-select NAND_CS (PE4).
- board_bringup: read-only SD init at 250 kHz under the SPI4 lock:
  >= 74 wake clocks, CMD0 (expect idle), CMD8 (R7 echo 0x1AA), CMD55 +
  ACMD41 HCS until ready (<= 1 s), CMD58 (OCR), CMD10 (CID, after the
  0xFE data token). Nothing is written. FAIL/TIMEOUT report
  (stage << 8 | R1); PASS reports the CID manufacturer ID and the CCS bit.

* firmware: eMMC (THGBMTG5D1LBAIL) on SDMMC1

- .ioc: SDMMC1 ClockDiv 0 -> 3. With the 129 MHz SDMMC kernel clock,
  ClockDiv 0 ran transfers at 129 MHz; eMMC default speed is <= 26 MHz.
  129 / (2 x 3) = 21.5 MHz. Regenerated with CubeMX 6.18; the only code
  change is hmmc1.Init.ClockDiv (CubeMX wrote CRLF; normalized to LF).
- board_bringup: release EMMC_RST (PA8), held low by MX_GPIO_Init, and
  wait 2 ms. The probe runs CubeMX's MX_SDMMC1_MMC_Init() through
  board_soft_init(), so a missing or dead eMMC is a FAIL with the HAL
  error code instead of a halted board. HAL_MMC_Init completes the full
  identification and the CMD6 switch to 4-bit (a bus-width setting, no
  stored data). Then the CID is read and the card must be in TRANSFER;
  PASS reports the CID manufacturer ID (Kioxia/Toshiba: 0x11). Retries
  DeInit first. HAL command timeouts, not budget_ms, bound the init.

* firmware: ADC1 analog inputs (battery, currents, pyro continuity)

- board_adc.c/.h: offset + linearity calibration once at bring-up
  (HAL_ADCEx_Calibration_Start, before any conversion), then one-channel
  conversions with MX_ADC1_Init's settings (16-bit, 387.5-cycle sampling
  for the TLV9004 buffers), only the channel changing. Covers all seven
  analog pins the .ioc already puts in analog mode: VBAT PA0 (INP16),
  EXT_SENSE_1 PA1 (INP17), PYRO_1/2_CONT PA2/PA3 (INP14/15), EXT_SENSE_2
  PA4 (INP18), ALT_CURR PC0 (INP10), CURR PC1 (INP11).
  board_adc_snapshot() reads them all for the bring-up report.
- board_bringup_read_battery: self_test_port_t.read_battery returning raw
  PA0 counts stamped with now_ms. Volts (x 0.3125, VREF+ 3V3) and the
  warn/fail thresholds stay with the battery adapter (#137, #162).
Read-only: nothing here drives a pyro output.

* firmware: run the self-test over every chip at boot

- bringup_task.c/.h: a FreeRTOS task (6 KB stack, started from main.c's
  RTOS_THREADS user block) that runs board_bringup_power_up() and then
  Pranay's self-test coordinator with board_bringup_probe and
  board_bringup_read_battery, then takes an ADC snapshot.
  - Config: 3 attempts per device, 2 s per call (GNSS listens 1.5 s, SD
    init up to 1 s; the coordinator needs callback <= tick / 3, tick 6 s),
    default 29 s session so it always finishes (#137). Checked on the host
    against self_test.c: this config is accepted and completes; a
    callback budget of 2001 ms is rejected, so the check can fail.
  - Required (LED2): IMU, high-g, baro, radio, eMMC, per Inez's #137
    proposal. Warn-only: GNSS, Ethernet, SD NAND. Not an arming policy.
  - publish_status is NULL: radio transmit is not written yet.
- Results without a console: LED1 fast blink while running, then 1 Hz;
  LED2 on if a required check failed. g_bringup_report (global) holds the
  live coordinator status and the ADC snapshot for the debugger.
- STM32-UPLOAD-REQUIREMENTS.md: "First power-up" table of LED meanings
  and how to read g_bringup_report.

Nothing enables a pyro output or transmits.

* SX1262: report a missing radio instead of "no data" (review S1)

Sx1262::receive never looked at the status byte, so a missing chip or a
stuck MISO line (all 0x00 or all 0xFF) came back as NoData forever: 0x00
read as "no IRQ flags", 0xFF as "header + CRC error" and was cleared.
A dead radio looked like a quiet one.

Every "get" reply now has its status byte (reply byte 1) checked against
datasheet Rev 1.2, Table 13-76, p.95: chip mode (bits 6:4) must be 2..6,
and command status (bits 3:1) must not be 3 timeout, 4 processing error
or 5 failure to execute. Otherwise receive() returns ErrNotFound. 0x00
and 0xFF decode as modes 0 and 7.

Fake chip: its status byte was 0x2A, which decodes as STBY_RC + "failure
to execute"; now 0x54 (RX, data available). Adds set_status() and
set_stuck(level). Tests: stuck 0x00, stuck 0xFF, a failed command, and a
bad status in the second reply. Mutation-checked: accepting status 5,
or accepting chip mode 7, each turns one of them red. 75/75 pass.

* SX1262: add start_rx_continuous and state the RX requirement (review S2)

In single RX the chip returns to standby after one packet, and nothing in
the receive path put it back into RX. Sx1262::start_rx_continuous() sends
SetRx (0x82, datasheet Rev 1.2 p.62) with timeout 0xFFFFFF, continuous RX
(p.70). The class comment now says it must be called after start-up and
after every transmission, which leaves the chip in standby.

Fake chip records the bytes of the last command. Tests: the exact four
bytes go out after a BUSY check; nothing is sent if BUSY never clears.
Mutation-checked: timeout 0x000000 (single RX) turns the test red.
77/77 pass.

* SX1262: count packets the radio rejected (review S3)

Packets that fail the radio's own LoRa header or CRC check are discarded
and reported as NoData, so a bad antenna or too much range looked like
silence. Sx1262::crc_errors() counts them for telemetry. The header
notes it relies on LoRa CRC being enabled at start-up (review S4).

Test: one CRC error and one header error count 2, a good packet adds
nothing. Mutation-checked: removing the increment turns it red. 78/78.

* Link: count radio errors apart from bad frames (review L1)

ErrNotFound from the radio (chip not answering) went into
frames_dropped, the same counter as a bad CRC, so a dead radio and a
noisy channel looked the same. Link::radio_errors() now counts every
receive failure except ErrTooLong; ErrTooLong (a packet arrived but was
unusable) stays in frames_dropped.

Fake radio: fail_next_receive(status) makes the next radio_receive()
return that status once. Test: ErrNotFound and ErrTimeout count as 2
radio errors and 0 dropped frames. Mutation-checked: counting them as
dropped frames turns it red. 79/79 pass.

* Radio: keep packet buffers off the task stack (review L2)

Link::poll held a 255-byte packet buffer and a 254-byte Frame, and
Sx1262::receive two 258-byte ReadBuffer arrays: about 1.1 KB of stack per
poll, over twice the 512-byte default FreeRTOS task stack. They are now
members of Link and Sx1262 (one of each per radio task). ReadBuffer's
dummy bytes are still zeros.

Measured with arm-none-eabi-g++ -O2 -fstack-usage (Cortex-M7):
  Link::poll        536 -> 32 bytes
  Sx1262::receive   568 -> 48 bytes
79/79 native tests pass.

* ARM gate: pin the ground-station reboot behaviour (review A1, A2, A3)

If the ground station reboots and its sequence counter restarts, every
ARM is RejectStale until the rocket reboots. This fails safe, but on
launch day it looks like "ARM doesn't work". How to fix it (the ground
keeps its counter, or ARM carries a session number) is a protocol
decision, so it goes under "Decisions for the lead" in the README. No
behaviour changes here.

- test_ground_reboot_rejects_arm_until_rocket_reboots pins today's
  behaviour, so the chosen fix has to change this test on purpose:
  seq 100/101 arm, seq 1 and 2 are stale, UN_ARM still disarms.
- arm_gate.h: rule 3 says the ground counter must survive restarts; UN_ARM
  ignores the target id on purpose (A2); whether arming is allowed now is
  the state machine's decision, not the gate's (A3).
80/80 pass.

* Fake radio: refuse empty sends loudly (review #148 F2)

radio.h says a packet is 1 to 255 bytes, but the fake took len 0 (and a
null pointer) and answered Ok; memcpy from nullptr is also undefined
behaviour. The fake now asserts bytes != nullptr && len > 0, so a caller
that sends nothing stops the test run instead of passing. No new
RadioStatus value, so #147's contract is unchanged.

Checked with a small separate program: radio_send(nullptr, 0) aborts
(exit 134), a 1-byte send still answers Ok. 80/80 pass.

* Radio: start-up requirements and citation revision in comments (review S4-S6, L3)

Comments and README only, no code change:
- README "Not done yet": start-up must turn LoRa CRC on and call
  start_rx_continuous() after start-up and after every send; measured
  stack for Link::poll / Sx1262::receive and that both objects should be
  allocated once, statically.
- link.h: poll() drains one packet; the SX1262 holds one at a time.
- sx1262.h: the page citations are correct for datasheet Rev 1.2; the
  revision is now named (verified against DS.SX1261-2 Rev 1.2, June 2019:
  opcodes pp.62-64, IRQ table 13-29 p.80).
80/80 pass.

* firmware: initialize the eMMC once per power-up

The bring-up probe re-ran DeInit + MX_SDMMC1_MMC_Init on every self-test
retry (up to 3 attempts). THGBMTG5D1LBAIL rev 1.0 p.28: "avoid any
excessive iteration of resets and initialization sequences (Device
identification mode) ... which may result in read disturb failure",
e.g. repeated CMD0 - CMD1.

The probe now identifies the card on its first attempt only and reports
that cached result on retries. hmmc1 stays READY for the eMMC log adapter
(emmc_stm32.c on inez/emmc), which takes over every transfer after
bring-up. Found while coordinating with that work.

* firmware: eMMC flight log, recording from ARMED

Adds the flight computer's eMMC (U9, KIOXIA THGBMTG5D1LBAIL, 4 GB) flight
log, following the Flight_computer.drawio state machine. At this stage
recording starts at ARMED, not LAUNCHED, because launch detection does not
exist yet. Self-test and Idle never read or write the card.

- flight_state: the diagram's transition table and which states record.
  A stand-in for the real state machine (#162).
- emmc_log: append-only raw-block log, no filesystem. Every 512 B block
  carries an epoch, its own position, its session and a CRC32, so a power
  cut can only lose the chunk in flight. The end is found at mount by
  binary search. Sensor tasks never wait on the card: records go into
  16 KB RAM chunks; one writer task does all I/O; when full, records are
  dropped, counted and reported.
- emmc_card: CID/EXT_CSD checks against the datasheet.
- emmc_port: the seam, so the log runs on a laptop against a RAM disk.
- emmc_stm32: SDMMC1 + IDMA adapter. NOT YET COMPILED (the build comes
  with #165); its DMA buffers need a RAM_D1 linker section first.
- tests/emmc: 3 host suites, new CI job stm32-emmc-host. Five deliberate
  breaks of the code were each caught by the matching test.
- EMMC-ARCHITECTURE.md: design, datasheet facts, integration status.

Datasheet: https://datasheet.lcsc.com/datasheet/pdf/ea386c834ed06c7e4629df6606f52741.pdf
Refs #137

* firmware: CubeMX for interrupt-driven, RTOS-safe chip communication

.ioc (regenerated with CubeMX 6.18; generated diff checked line by line):
- NVIC on for EXTI0 (IMU_INT1 PD0), EXTI2 (RADIO_DIO1 PB2), EXTI3
  (ACCEL_INT_1 PD3), EXTI15_10 (ETH_INT PE15), UART9, SDMMC1, TIM2. All at
  priority 5 = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, so their ISRs
  may wake tasks (CubeMX clamps "uses FreeRTOS functions" IRQs to >= 5).
- ETH_INT on the falling edge: W5500 INTn is active low (W5500 v1.0.2,
  p.10, pin 36); it was rising.
- SPI1-4 Master Receiver Auto-Suspend: when a task is preempted mid
  transfer the master stops the clock instead of overrunning its RX FIFO
  (RM0468 Rev 3, MASRX, p.2201).
- TIM2 prescaler 63: a free-running 32-bit 1 MHz timebase at today's
  64 MHz timer clock; CH4 still captures GPS TIMEPULSE on the same clock.
- UART9 hardware FIFO on, RX interrupt at half full.
- The watchdog is NOT enabled yet; it comes with the task that feeds it.

Linker: a .dma_buffers (NOLOAD) section in RAM_D1. .data/.bss/stack are
in DTCM, which only the core and MDMA can reach (RM0468 Table 2 p.106,
Section 2.1.2 p.108), not the SDMMC IDMA or DMA1/2. board.h
BOARD_DMA_BUFFER places a buffer there (checked: a test buffer linked at
0x24000000). CubeMX leaves an existing linker script alone (checked).

scripts/cubemx_generate.sh regenerates without the GUI and restores each
file's line endings as git has them (CubeMX's CLI writes CRLF).

* eMMC: put the adapter's DMA buffers in RAM_D1

As agreed with the eMMC log work: chunks (64 KB), scratch and ext_csd
(512 B each) now use BOARD_DMA_BUFFER, i.e. the .dma_buffers NOLOAD
section in AXI SRAM, instead of plain aligned(32) .bss, which this
linker script places in DTCM where the SDMMC IDMA cannot reach (start()
would have refused with EMMC_ERR_PARAM). Checked in the object file: all
three are in .dma_buffers, 32-byte aligned. First compile of
emmc_stm32.c for the STM32: no errors or warnings.

* firmware: microsecond timebase and interrupt routing to tasks

- board_time: TIM2 as a free-running 32-bit 1 MHz counter (wraps every
  ~71.6 min) for every sample timestamp; CH4 captures the GPS TIMEPULSE
  (PB11) on the same counter. board_time_start() computes TIM2's real
  kernel clock from RCC (RM0468 Rev 3, RCC_CFGR.TIMPRE rule, p.371) and
  returns false if prescaler + clock tree don't give exactly 1 MHz, so a
  later HSE/PLL change can't silently skew timestamps. Started first in
  bring-up; the result is kept in board_bringup_t.time_ok.
- board_exti: HAL_GPIO_EXTI_Callback stamps each edge with board_time_us()
  and sets the owning task's thread flags (osThreadFlagsSet, ISR-safe).
  Routes: IMU_INT1 PD0 and ACCEL_INT_1 PD3 (sensors), RADIO_DIO1 PB2
  (radio), ETH_INT PE15 (ethernet). No bus traffic in any ISR.

* firmware: IMU driver (ISM330DHCX), portable and host-tested

drivers/ holds chip drivers that see only dev_bus_t (one chip-select
frame + a delay), so the same code runs on board_spi and on a scripted
fake in host tests. The board build compiles drivers/*.c.

dev_ism330dhcx (DS13012 Rev 7):
- WHO_AM_I 0x6B (p.48) before any write; SW_RESET in CTRL3_C, polled
  until it self-clears, bounded at 10 ms (p.51)
- CTRL3_C 0x44 BDU + IF_INC (p.51), CTRL4_C 0x04 I2C_disable (p.52),
  CTRL1_XL 0x74 833 Hz +-16 g (p.49), CTRL2_G 0x71 833 Hz +-4000 dps
  (p.50), COUNTER_BDR_REG1 0x80 pulsed data-ready (p.46), INT1_CTRL 0x01
  accel DRDY on INT1 (p.47); every register read back and verified
- one 14-byte burst from OUT_TEMP_L (20h): temp, gyro, accel (p.64-66)
- scale 0.488 mg/LSB, 140 mdps/LSB (p.10); 256 LSB/degC, 0 at 25 degC
  (p.13, Table 4 note 4)

tests/drivers: fake_regs (register-file fake: auto-increment, MS bit,
self-clearing bits, stuck bits, bus failure) and 8 IMU tests: exact
config bytes in order, wrong ID refused before any write, dead bus
(0xFF), reset timeout, read-back mismatch, bus error, burst decode,
bad arguments. Mutation-checked: +-2 g instead of +-16 g, and skipping
the read-back check, each turn a test red. ASan/UBSan clean.

* firmware: high-g accelerometer driver (H3LIS100DL)

dev_h3lis100dl (DocID027504 Rev 2; the board carries the H3LIS100DLTR,
not the H3LIS331DLTR on the rev 1 schematic):
- SPI first byte: RW bit 7, MS (auto-increment) bit 6, 6-bit address
  (p.20); WHO_AM_I 0x32 before any write (p.25). The H3LIS331DL also
  answers 0x32, so identity alone can't tell them apart.
- CTRL_REG4 0x00 4-wire SPI, CTRL_REG3 0x02 INT1 = data ready, active
  high, push-pull (p.28, Table 27), CTRL_REG1 0x37 normal mode 400 Hz
  X/Y/Z (p.25-26, Tables 19-20), written last; each read back.
- one 5-byte MS burst from 29h: X, Y, Z at 29h/2Bh/2Dh, 8-bit two's
  complement (p.30), 780 mg/digit, fixed +-100 g (p.9).
- The DRDY line is a level, so the sensor task must also read on a
  timeout (noted in the header).

6 tests: exact config, wrong ID refused before any write, read-back
mismatch, bus error, X/Y/Z from the right registers (reserved bytes
skipped), MS-bit guard. Mutation-checked: dropping the MS bit and
100 Hz instead of 400 Hz each turn a test red.

* firmware: barometer driver (MS5611) with datasheet compensation

dev_ms5611 (MS5611-01BA03 datasheet 06/2017, AN520):
- PROM read 0xA0..0xAE (p.10 Figure 4), AN520 CRC4; blank (all 0 / all
  1) PROM rejected before the CRC, since a dead bus can match by chance
- D1 0x48 / D2 0x58 at OSR 4096, read with 0x00 >= 10 ms later (9.04 ms
  max, p.3); an ADC result of 0 means read too early -> DEV_ERR_DATA
- first-order (p.8) and second-order (p.9, below 20 degC and below
  -15 degC) compensation in 64-bit integers with C division, exactly as
  the datasheet; temperature in 0.01 degC, pressure in Pa
- the power-on reset with CSB held low stays in board_bringup

test_ms5611 (command-driven fake chip): PROM + CRC (vector computed with
AN520 in Python), flipped bit / all 0 / all 1 rejected, D1/D2 commands
and early-read 0, the datasheet worked example (TEMP 2007, P 100009),
and two second-order vectors (11.75 degC; -30.22 degC very-low branch)
from an independent Python model using C truncating division.
Mutation-checked: no second order, >> instead of / (floor vs truncate),
and skipping the CRC each turn a test red.

* firmware: sensors task: IMU, high-g and baro on interrupts under RTOS

app/ holds the application. Each task is a portable core (no HAL, no RTOS;
time and events passed in) plus a thin RTOS loop, so flight_test can run
the same code on a laptop.

- app/records.h: record types 0x10+ (IMU, high-g, baro, ...) and packed
  little-endian payloads with pinned sizes; every one starts with t_us.
- app/sensors_core: SPI3 state machine. IMU read on its data-ready edge,
  stamped with the edge time from board_exti; high-g likewise, and read
  on a 2-period timeout when no edge comes (its DRDY is a level, so a
  missed read would otherwise silence it; counted as missed_drdy); baro
  D1 -> 10 ms -> D2 -> 10 ms -> compensate, ~50 Hz. A sensor whose init
  fails, or that fails 3 reads in a row, is re-initialized every second.
- app/sensors_task: Realtime priority, routes IMU_INT1/ACCEL_INT_1 to its
  thread flags, sleeps until an edge or the core's next deadline, appends
  each record to the eMMC log (emmc_log_append, non-blocking).
- app/app: app_start() brings up the eMMC log (emmc_stm32_init + its
  writer task) and the sensors task; bringup_task calls it after the
  self-test, so every chip is out of reset first.
- Core/board_devbus: dev_bus_t over board_spi (one locked CS frame,
  5 ms deadline; delay = osDelay(ms + 1), which is >= ms).
- tests/fakes: fake_regs moved here, fake_baro shared (was private to
  test_ms5611). tests/app/test_sensors_core: virtual clock with a 37 us
  task wake latency: rates (833 / 400 / ~50 Hz), values, edge-time
  stamps, high-g timeout reads, IMU failure -> dropped -> recovered,
  wrong chip keeps retrying, dead baro bus, deadlines, 32-bit clock
  wrap. Mutation-checked: no high-g timeout read, IMU stamped at read
  time, failed IMU never retried each turn it red.

Firmware: RAM_D1 now holds the eMMC log's 65 KB of DMA buffers.

* firmware: move chip drivers from drivers/ to chips/

macOS file systems are case-insensitive, so drivers/ and CubeMX's
Drivers/ (ST HAL + CMSIS) were the same folder on a Mac: the drivers
were committed under Drivers/, inside the vendored code. On Linux (CI,
teammates) platformio.ini's ../drivers would not have existed, and
format.sh skipped them as vendored (Flight_Computer/Drivers is in its
skip list).

chips/ cannot collide with anything CubeMX generates. tests/drivers ->
tests/chips; platformio.ini, both test CMakeLists and dev_bus.h updated.
No code change. Checked: nothing of ours left under Drivers/ in git;
firmware builds; chips (3) and app (1) host suites pass under
ASan/UBSan; format.sh now checks all 7 chip files (dev_bus.h needed
reformatting, done).

* firmware: UBX protocol for the MAX-M10S (VALSET, NAV-PVT)

chips/ubx (u-blox M10 SPG 5.10 Interface Description, UBX-21035062 R02):
- ubx_frame: B5 62 class id len payload + 8-bit Fletcher
- ubx_valset: UBX-CFG-VALSET (0x06 0x8A, 3.10.5.1 p.55), version 0,
  RAM layer only (re-sent every power-up, nothing burnt to flash)
- ubx_parse_nav_pvt: UBX-NAV-PVT (0x01 0x07, 92 bytes, 3.15.11 p.95)
- keys: CFG-UART1-BAUDRATE 0x40520001 (p.153), CFG-UART1OUTPROT-NMEA
  0x10740002 (p.154), CFG-MSGOUT-UBX_NAV_PVT_UART1 0x20910007 (p.136),
  CFG-RATE-MEAS 0x30210001 (p.147), CFG-NAVSPG-DYNMODEL 0x20110021 with
  AIR4 = 8 "airborne <4g" (Table 23, p.141), the highest model there is

Core/gnss_frame: keeps the class, id, length and first 100 payload bytes
of each UBX frame, so one byte-at-a-time parser serves the self-test
probe and the GNSS task.

Datasheet facts for the GNSS task (MAX-M10S data sheet UBX-20035208 R02):
the default UART is 9600 baud (5.3, p.13), not the 38400 assumed in
#137; 10 Hz NAV-PVT (~1000 B/s) does not fit at 9600, so the task will
raise the module to 115200. PVT up to 10 Hz (p.4).

test_ubx: VALSET frames and a NAV-PVT frame encoded independently in
Python, decoded through gnss_frame + ubx_parse_nav_pvt. Mutation-checked:
writing all layers (incl. flash) and reading velD from the wrong offset
each turn it red.

* firmware: GPS task: MAX-M10S on interrupt-driven UART9, 10 Hz NAV-PVT

board_uart9 (Core): HAL ReceiveToIdle interrupts (UART FIFO at half
full, from the .ioc) into a 1 KB single-producer/single-consumer ring;
each burst sets the GNSS task's thread flag. No DMA, so no DTCM issue.
Blocking 100 ms-bounded transmit for the short UBX config frames;
set_baud re-inits UART9 and re-arms receive.

gnss_core (app, portable):
- DETECT: listen 1.5 s each at 9600 (the module's default, data sheet
  UBX-20035208 p.13), 38400, 115200 for one valid NMEA/UBX frame
- CONFIG: VALSET CFG-UART1-BAUDRATE 115200 if lower (10 Hz PVT is
  ~1000 B/s, more than 9600 baud carries), then NMEA off, NAV-PVT on
  UART1, CFG-RATE-MEAS 100 ms, dynamic model AIR4; waits for ACK-ACK of
  CFG-VALSET, 3 tries of 500 ms; a NAK restarts detection
- RUN: every NAV-PVT -> REC_GNSS (rec_gnss_t, 49 bytes) stamped with its
  arrival and the latest TIMEPULSE edge (TIM2 CH4); 2 s without a fix
  -> back to DETECT, so a power-cycled module (RAM config lost) is
  reconfigured
gnss_task: Normal priority, woken by received bytes or the core's next
deadline. Started from app_start after the sensors task.
records.h: record_sink_t shared by the task cores (sensors_sink_t is now
an alias).

AIR4 is the highest dynamic model the M10 has (Table 23, p.141); a boost
above 4 g can lose the fix, which the 2 s watchdog then recovers.

Tests:
- fake_gnss: a simulated MAX-M10S that parses VALSET itself, sizing each
  value from the key ID (bits 30..28, Interface Description p.124), only
  hears the board at a matching baud, and sends garbage at a wrong one
- test_gnss_core: cold start at 9600, warm module at 115200, NAK,
  silence + power cycle, PPS stamping. Mutation-checked: skipping the
  baud change, treating NAK as ACK, ignoring silence each turn it red
The end-to-end [gps] check lives on inez/flight/flight_test.

* firmware: flight_test, the flight computer's end-to-end gate

./flight_test (also scripts/flight_test.sh), modeled on daq-server's
test_integration.sh: named, numbered checks printed as they run with
pass/fail and time, then a Results block; --only=ids|numbers, --list,
-v, --board. Exit 0 only if every selected check passed.

  1 build & static  build with no new warnings; size (flash < 50 %,
                    DTCM < 70 %, RAM_D1 holds the eMMC buffers); format;
                    every .dma_buffers symbol inside RAM_D1
  2 unit suites     radio (pio native), self_test, emmc, chips, app,
                    all under ASan/UBSan
  3 end to end      tests/e2e/flight_e2e.c: a scripted 20 s flight (pad,
                    boost, coast, descent) through the REAL chip drivers,
                    sensors_core and emmc_log, on fake chips and a fake
                    card, virtual clock with RTOS-like wake latency. The
                    card is read back with an independent decoder (own
                    CRC-32): sensor_rates, sample_values (every sample =
                    the profile; baro vectors from the datasheet, not the
                    code), timestamps, conservation (25,666 records, byte
                    for byte), emmc_roundtrip, emmc_stall,
                    fault_imu_silent
  4 canary          the e2e built with one corrupted card byte must FAIL
                    conservation + emmc_roundtrip
  5 --board         flash over ST-Link, wait for the on-board self-test,
                    read g_bringup_report over SWD (PlatformIO's OpenOCD +
                    arm-none-eabi-gdb, batch), one check per chip

Checked: 17/17 pass in ~14 s; a broken driver makes it exit 1 with the
failing line; formatting identical under clang-format 19 (CI) and 23.
CI: the Flight_Computer job installs clang-format 19 (same pin as
daq-server-ci) and runs ./flight_test -v. AGENTS.md, the must-read doc
and the root CLAUDE.md row say to run it before every commit.

Found by emmc_stall: a 0.5 s card outage sends the eMMC log to FAULT
after 3 attempts and it stops recording for the rest of the flight
(reported to the eMMC log owner; not changed here).

* firmware: task-core comments name the host tests, not a tool on another branch

* flight_test: [gps] end to end; emmc_stall checks sealed chunks

[gps]: a simulated MAX-M10S (tests/fakes/fake_gnss) rides along the 20 s
flight through the real ubx, gnss_frame and gnss_core: cold start at
9600 baud, switch to 115200, VALSET acknowledged, then 10 Hz NAV-PVT.
197 fixes, each equal to the GPS truth, stamped with the latest PPS edge,
and on the eMMC card ([conservation] counts them). A latitude off by
1e-7 deg turns it red.

[emmc_stall] used a fixed 2.9 s cutoff for "pre-stall data intact". The
GPS records moved the eMMC chunk boundary, so the 16 KB chunk still open
when the card stalled began at 2.857 s, and the log (which latches FAULT
during a stall) dropped it. The check passed before only because the
boundary landed after 2.9 s. It now tracks where each chunk begins and
requires every record in a chunk sealed before the stall to be on the
card; the open chunk's loss (184 records) is printed until the eMMC log
retries instead of latching FAULT. Mutation-checked: a cutoff at the
stall itself and a broken chunk tracker each turn it red.

flight_test: 18/18.

* firmware: link newlib-nano in the PlatformIO build, as CubeMX does

CubeMX's cmake/gcc-arm-none-eabi.cmake links with --specs=nano.specs;
env:flight did not, so the two builds of one project used different C
libraries. With the full newlib, one vsnprintf (the boot report) cost
~29 KB of flash; with nano the image is 69.7 KB instead of 98.2 KB.
Nano's printf has no float support; no firmware code prints floats.

* firmware: start-up self-test reports battery voltage and a verdict

The self-test already checked every chip at boot (IMU/high-g WHO_AM_I,
baro PROM CRC, W5500 version, SX1262 status, GPS frame, SD NAND CID,
eMMC CID) and read raw PA0 counts. Missing was the battery adapter and a
report a person can read.

app/battery: counts -> mV -> health.
- Schematic rev 1 p.2: VDD -> R1 22k / R3 10k (x 0.3125) -> TLV9004
  follower -> PA0; VREF+ = VDDA = 3V3 through FB1. p.12: 3V3 from the
  TPS562201, 0.768 V x (1 + 33.2k/10k) = 3.318 V (~ +/-2 %).
  mV = counts x 10624 / 65535, the same as Aaron's idle module (#162).
- p.12: VDD is the TPS2121's output (IN1 battery, IN2 USB; battery wins
  above ~3.5 V). SW_ST (PE10) HIGH = battery, LOW = USB (TPS2121 p.21).
  On USB the reading is USB_5V and is never judged as the pack.
- OK >= 7.0 V, WARN < 7.0 V, FAIL < 6.6 V (proposals, the same as #162),
  FAIL > 8.8 V (above a full 2S pack + 2 %: wrong pack or divider).
board_bringup_read_battery now averages 16 conversions within its
budget; board_bringup_on_usb reads SW_ST.

app/boot_report: verdict (READY / WARN / FAIL), result_bits (bit =
device id passed: the SelfTest radio frame's field, src/frame.h) and a
text report, one line per chip plus the battery and the verdict. The
GPS line shows the baud it was heard at. FAIL = a required chip
(IMU, high-g, baro, radio, eMMC) failed or the battery is FAIL/unread;
WARN = an optional chip (GPS, Ethernet, SD NAND) failed or the battery
is low. Required vs optional is #137's proposal, not an arming policy.

bringup_task: builds the report into g_bringup_report.report after the
checks (battery sampled before anything transmits). LED2: off READY,
blinking WARN, solid FAIL. In the debugger:
printf "%s", g_bringup_report.report.text

test_boot_report: conversion against counts computed independently in
Python (incl. #162's 40712 -> 6600, 51818 -> 8400), every threshold edge,
USB, ADC failure, each verdict, the exact text. Mutation-checked:
ignoring SW_ST, dropping the WARN band and counting optional failures as
required each turn it red.

* flight_test --board: battery, verdict, and the board's own report

The gdb script now also reads g_bringup_report.report: battery state and
mV, the verdict, and the text report. New checks:
- board_battery: the battery adapter's reading through SW_ST + PA0 is
  >= 7.0 V on battery, or the board is on USB (not judged)
- board_verdict: the board's own verdict is READY (LED2 off)
After stage 5 the board's report is printed as the board wrote it: one
line per chip, the battery voltage and the verdict.

The shell parsers were exercised against every battery state (OK, USB,
WARN, FAIL, unread) and verdict (READY, WARN, FAIL).

* firmware: build with debug info so gdb can read the board over ST-Link

env:flight compiled without -g, so the ELF had no symbol types and gdb
answered "'g_bringup_report' has unknown type": the self-test report
could not be read over SWD, by a person or by flight_test --board.
-g3 adds debug sections to the .elf only; the flashed image is the same
size (69,656 bytes) and the same code.

* firmware: MS5611 CRC4 builds under GCC -Werror (CI)

Flight_Computer Tests failed on ubuntu-latest, where cc is GCC: in the
CRC4 loop one arm of ?: was int ((remainder << 1)) and the other
unsigned int ((remainder << 1) ^ 0x3000U), which GCC's -Wsign-compare
(-Wextra) rejects; Apple clang does not warn, so ./flight_test passed on
a Mac. Both arms are now uint16_t. Same CRC: AN520 keeps bits above 15
but only bits 15..12 are read and higher bits never shift back down.
Checked with GCC 14 -Wall -Wextra -Wpedantic -Werror and clang-format 19
(CI's version); test_ms5611 still matches the datasheet PROM's CRC, and
a wrong polynomial turns it red. ./flight_test 18/18.

---------

Co-authored-by: R-Leano <ryanleanoj@gmail.com>
inez9 added a commit that referenced this pull request Nov 8, 2026
* Add fake radio and tests for the radio.h contract

A pretend radio that keeps packets in memory, plus 7 tests for what radio.h promises, so code that uses the radio can be tested on a laptop with no hardware.

* Add frame format and CRC-16 for the radio link

Encode and decode for heartbeat, self-test, ARM and UN_ARM frames: version, type, sequence number, length, payload and CRC-16. 16 host tests, including golden frames and a check that every single-bit flip is rejected.

* Add ARM safety gate: key check, two-frame confirm, replay rejection

ARM needs the right key and its inverse, the right target id, a newer sequence number, and a second ARM (seq+1) within 2 s. Any rejected ARM cancels a pending one. UN_ARM is always honored. 21 host tests, including wraparound of the sequence number and the millisecond counter.

* Add Link::poll: radio_receive -> decode_frame -> ARM gate

One call per main-loop pass drains at most one packet. Corrupt or malformed packets are counted and dropped before they reach the ARM gate. 8 host tests using the fake radio, including 200 random noise packets that must never arm.

* Add SX1262 receive path over an SpiBus interface

GetIrqStatus, GetRxBufferStatus, ReadBuffer, ClearIrqStatus, in that order, waiting for BUSY before each. Packets the chip flags as damaged, zero-length packets and packets too big for the caller are dropped and the flags cleared. 12 host tests against a pretend chip. Not yet run on real hardware: init, probe, pins and the real SpiBus are still to do.

* Document radio link status and what is still missing

* firmware: STM32 flight computer builds and uploads from PlatformIO

Move the CubeMX project (firmware.ioc, .mxproject, Core/, self-test host
tests) into firmware/Flight_Computer so the .ioc and the Core/ it generates
live together, and regenerate it with CubeMX 6.18 (Toolchain = CMake,
FW_H7 V1.13.0). The generated code now matches the .ioc: 8-bit SPI with
the right modes/prescalers, UART9 at 38400, 387.5-cycle ADC sampling,
chip-selects high and pyro enables low at boot, altimeter arm optos off.

PlatformIO:
- boards/star_fc_h723ve.json: STM32H723VET6, 512 KB flash. PlatformIO has
  no VET6 board and nucleo_h723zg is a 1 MB ZG part.
- [env:flight]: no framework, compiles CubeMX's own files, pins GCC 14.2
  (the platform's GCC 7.2 cannot link CubeMX's READONLY linker script),
  uploads over ST-Link. Default env, so VS Code's Upload button and
  `pio run -d firmware/Flight_Computer -e flight -t upload` target the board.
- scripts/fpu_link_flags.py passes the hard-float flags to the linker.

Docs:
- STM32-UPLOAD-REQUIREMENTS.md: tools, ST-Link wiring, upload steps (CLI and
  VS Code), schematic cross-check of every MCU pin, and the rules for the
  CubeMX project. AGENTS.md/CLAUDE.md point agents at it.
- DEVICE_CHECKS.md: U3 is the H3LIS100DLTR (confirmed on the assembled
  board); the rev 1 schematic, BOM and #137 still say H3LIS331DLTR. Cites
  DocID027504 Rev 2. Keeps #147's requirements.

format.sh skips ST's Drivers/ and Middlewares/ and the new generated system
files, and now skips .pio/ at any depth. CI points at the moved self-test.

Checked: flight build links (40 KB of 512 KB flash, hard-float ABI, vectors
at 0x08000000); self-test host tests pass under ASan/UBSan; 14 radio tests
pass; clang-format clean. Not yet run on hardware.

* firmware: board RAM is DTCM, f_cpu is 64 MHz; record SW_ST polarity

Review fixes for #165:
- star_fc_h723ve.json: maximum_ram_size 128 KB (the linker script puts
  .data/.bss/heap/stack in DTCMRAM, not the 320 KB RAM_D1), f_cpu 64 MHz
  (SYSCLK is HSI until HSE + PLL are configured). PlatformIO now reports
  RAM 32.9% of 128 KB instead of 13% of 320 KB.
- STM32-UPLOAD-REQUIREMENTS.md: drop the stale "no build target" status and
  the dead #build-path-open-decision link; add the DTCM/DMA rule (DMA1/2,
  BDMA and SDMMC IDMA can't reach DTCM) and the f_cpu/clock rule.
- DEVICE_CHECKS.md: SW_ST from the rev 1 schematic p.12: PE10 HIGH = battery,
  LOW = USB (TPS2121 IN1 = VBAT, ST pulled up by R65).

* firmware: RADIO_DIO1 (PB2) without pull-up

DIO1 is the SX1262's active-high IRQ and PB2 is a rising-edge EXTI. Nothing
on the board pulls it (schematic p.7), so the internal pull-up held the line
high while the radio sat in reset and could hide the first rising edge, the
one that wakes the MCU for an Arm. Now GPIO_NOPULL; the SX1262 drives DIO1
push-pull once it is out of reset. Regenerated with CubeMX 6.18; the only
code change is the pull setting in MX_GPIO_Init.

* firmware: boot no longer halts on an eMMC that isn't ready

MX_SDMMC1_MMC_Init() ran HAL_MMC_Init() during boot, which talks to the
eMMC while EMMC_RST (PA8) still holds it in reset. The init fails, and
Error_Handler() disables interrupts and spins, so nothing after it ran.
A dead or unpopulated eMMC would brick the board the same way.

- .ioc (Project Manager, Advanced): MX_SDMMC1_MMC_Init is generated but
  not called from main(), and is public (main.h). Regenerated with
  CubeMX 6.18; no other generated change.
- board.c/board.h: board_soft_init() runs a CubeMX init with
  Error_Handler() made non-fatal and reports whether it failed. The board
  layer will call the eMMC init after releasing its reset.
- Error_Handler (USER CODE): returns inside board_soft_init(); otherwise
  turns LED2 on before halting, so a fatal init error is visible.

* firmware: SPI bus layer for the flight computer

board_spi.c/.h is the one place that turns "talk to chip X" into
chip-select + HAL_SPI_TransmitReceive on the right bus:

- One FreeRTOS mutex per SPI peripheral (priority inheritance). SPI3 is
  shared by the IMU, high-g accelerometer and barometer.
- Every call takes an absolute deadline: the lock wait, the SX1262 BUSY
  wait and each transfer. Chip-select and the lock are released on every
  path, including errors and timeouts.
- board_spi_frame / board_spi_transfer for drivers; board_spi_idle_clocks
  (CS high, 0xFF) for the SD-card wake-up sequence.
- board_spi_self_test_exchange plugs into self_test_devices_t.exchange.
  It refuses (NOT_CONFIGURED) when the bus's mode differs from what the
  check asks for or its clock is above the chip's limit, instead of
  talking to the chip wrongly. Mode and clock are read back from the HAL
  handle and the RCC, so they follow the .ioc.

The device table is empty; each chip is routed in its own commit.

* firmware: IMU (ISM330DHCX) on SPI3

- board_spi: route BOARD_SPI_IMU to SPI3 with chip-select IMU_CS (PD7).
- board_bringup.c/.h (new): power/reset sequencing per chip and a probe
  for every self-test device ID. A device's check is enabled only after
  its startup steps are done. The IMU is on the always-on 3V3 rail; wait
  20 ms after reset for its ~10 ms boot, then enable it.
- The self-test's WHO_AM_I read (8F 00, expect 0x6B, mode 3, <= 10 MHz)
  now runs through the real bus: SPI3 is mode 3 at ~8.06 MHz.

* firmware: high-g accelerometer (H3LIS100DL) on SPI3

- board_spi: route BOARD_SPI_HIGH_G to SPI3 with chip-select ACCEL_CS
  (PD6), sharing the bus lock with the IMU and barometer.
- board_bringup: enable the high-g check after the IMU's 20 ms. The
  H3LIS100DL loads its trimming from internal flash at power-up
  (DocID027504 p.27) and specifies no separate boot time; it powers up in
  power-down (CTRL_REG1 = 0x07), which still answers WHO_AM_I.
- The self-test's identity read (8F 00, expect 0x32, mode 3, <= 10 MHz)
  matches SPI3's mode 3 at ~8.06 MHz.

* firmware: barometer (MS5611) on SPI3, with its power-on reset

- board_spi: route BOARD_SPI_BARO to SPI3 with chip-select BARO_CS (PD5).
  Add board_spi_select/deselect/shift for sequences that hold CS across a
  wait.
- board_bringup: send the MS5611 reset command (0x1E) once after power-on,
  as the datasheet requires before the PROM is valid (p.10). Figure 5 keeps
  CSB low through the 2.8 ms PROM reload, so CS is held low across
  osDelay(4) (>= 3 ms on a 1 kHz tick), under the SPI3 lock.
- The barometer check (PROM words + CRC4, mode 3, <= 20 MHz) is enabled
  only if the reset went out. SPI has no acknowledge, so a missing chip
  still passes this step; the self-test then rejects its blank PROM.

* firmware: Ethernet (W5500) on SPI2, out of reset

- board_spi: route BOARD_SPI_ETH to SPI2 with chip-select ETH_CS (PE14).
  SPI2 is mode 0 at ~16.1 MHz; the W5500 takes mode 0/3 up to 80 MHz.
- board_bringup: release ETH_RST (PE13), which MX_GPIO_Init holds low.
  W5500 v1.0.2 p.61: RSTn low >= 500 us (it has been low since boot), PLL
  lock <= 1 ms after RSTn rises; wait osDelay(3) (>= 2 ms), then enable
  the VERSIONR check (expect 0x04). No cable, PHY link or IP traffic.

* firmware: LoRa radio (SX1262) on SPI1, out of reset

- board_spi: route BOARD_SPI_RADIO to SPI1 with chip-select RADIO_CS
  (PC4) and BUSY (PC5). Every radio frame waits for BUSY low, bounded by
  the caller's deadline. SPI1 is mode 0 at ~8.06 MHz (SX1262: CPOL=0,
  CPHA=0, <= 16 MHz).
- board_bringup: release RADIO_NRST (PB0), which MX_GPIO_Init holds low
  (NRESET low typ. 100 us, DS 8.1 p.50), then wait up to 50 ms for BUSY
  to fall (STARTUP -> STDBY_RC, 8.2.2 / 9.1).
- The GetStatus/GetDeviceErrors check is enabled even if BUSY never falls:
  it then reports TIMEOUT, the truthful result for a radio that didn't
  start, rather than NOT_CONFIGURED. Nothing transmits; RF_SW stays low.

* firmware: GNSS (MAX-M10S) on UART9

- gnss_frame.c/.h (portable): byte-at-a-time validator for NMEA
  ($...*HH, XOR) and UBX (B5 62 ..., 8-bit Fletcher) frames, with length
  limits and a rejected-frame count.
- test_gnss_frame.c: vectors computed outside the code (the published GGA
  example *47; TXT and UBX-ACK checksums from Python). Covers valid frames,
  lower-case hex, wrong checksum, a flipped body byte, each corrupted UBX
  byte, noise and cut-off sentences, overlong lines, control bytes and the
  UBX length cap. Mutation-checked: accepting any NMEA checksum, a wrong
  Fletcher CK_B and allowing control bytes each turn the test red.
  Registered in the existing CMake project, so the CI job runs it.
- board_bringup: power the GPS (REG_3V6_EN PE11 -> 3V6 buck -> 3V3A LDO),
  wait 10 ms; GPS_RST is already released. The probe listens on UART9 for
  up to 1.5 s and passes on one valid frame (no fix required, #137).
  Baud is still open, so attempts 1/3 listen at 38400 and attempt 2 at
  9600; PASS reports the baud that worked. A miss reports TIMEOUT, flagged
  if GPS_ANT_STATUS (PD10) shows an antenna short. Nothing is sent to the
  module.

* firmware: SD NAND (ZDSD01GLGEAG) on SPI4, SD SPI mode

- sd_spi.c/.h (portable): CRC7, 6-byte command frames, R1/R7 checks and
  a CID check. 16 x 0xFF (a floating MISO) happens to satisfy CID CRC7,
  so uniform 0xFF/0x00 contents are rejected explicitly.
- test_sd_spi.c: CMD0 ...95 and CMD8 ...87 are the published constants;
  the other frames and the CID vector come from an independent Python
  CRC7. Mutation-checked: dropping the uniform-contents rule, a wrong CRC7
  polynomial and ignoring the R7 pattern each turn it red.
- board_spi: route BOARD_SPI_NAND to SPI4 with chip-select NAND_CS (PE4).
- board_bringup: read-only SD init at 250 kHz under the SPI4 lock:
  >= 74 wake clocks, CMD0 (expect idle), CMD8 (R7 echo 0x1AA), CMD55 +
  ACMD41 HCS until ready (<= 1 s), CMD58 (OCR), CMD10 (CID, after the
  0xFE data token). Nothing is written. FAIL/TIMEOUT report
  (stage << 8 | R1); PASS reports the CID manufacturer ID and the CCS bit.

* firmware: eMMC (THGBMTG5D1LBAIL) on SDMMC1

- .ioc: SDMMC1 ClockDiv 0 -> 3. With the 129 MHz SDMMC kernel clock,
  ClockDiv 0 ran transfers at 129 MHz; eMMC default speed is <= 26 MHz.
  129 / (2 x 3) = 21.5 MHz. Regenerated with CubeMX 6.18; the only code
  change is hmmc1.Init.ClockDiv (CubeMX wrote CRLF; normalized to LF).
- board_bringup: release EMMC_RST (PA8), held low by MX_GPIO_Init, and
  wait 2 ms. The probe runs CubeMX's MX_SDMMC1_MMC_Init() through
  board_soft_init(), so a missing or dead eMMC is a FAIL with the HAL
  error code instead of a halted board. HAL_MMC_Init completes the full
  identification and the CMD6 switch to 4-bit (a bus-width setting, no
  stored data). Then the CID is read and the card must be in TRANSFER;
  PASS reports the CID manufacturer ID (Kioxia/Toshiba: 0x11). Retries
  DeInit first. HAL command timeouts, not budget_ms, bound the init.

* firmware: ADC1 analog inputs (battery, currents, pyro continuity)

- board_adc.c/.h: offset + linearity calibration once at bring-up
  (HAL_ADCEx_Calibration_Start, before any conversion), then one-channel
  conversions with MX_ADC1_Init's settings (16-bit, 387.5-cycle sampling
  for the TLV9004 buffers), only the channel changing. Covers all seven
  analog pins the .ioc already puts in analog mode: VBAT PA0 (INP16),
  EXT_SENSE_1 PA1 (INP17), PYRO_1/2_CONT PA2/PA3 (INP14/15), EXT_SENSE_2
  PA4 (INP18), ALT_CURR PC0 (INP10), CURR PC1 (INP11).
  board_adc_snapshot() reads them all for the bring-up report.
- board_bringup_read_battery: self_test_port_t.read_battery returning raw
  PA0 counts stamped with now_ms. Volts (x 0.3125, VREF+ 3V3) and the
  warn/fail thresholds stay with the battery adapter (#137, #162).
Read-only: nothing here drives a pyro output.

* firmware: run the self-test over every chip at boot

- bringup_task.c/.h: a FreeRTOS task (6 KB stack, started from main.c's
  RTOS_THREADS user block) that runs board_bringup_power_up() and then
  Pranay's self-test coordinator with board_bringup_probe and
  board_bringup_read_battery, then takes an ADC snapshot.
  - Config: 3 attempts per device, 2 s per call (GNSS listens 1.5 s, SD
    init up to 1 s; the coordinator needs callback <= tick / 3, tick 6 s),
    default 29 s session so it always finishes (#137). Checked on the host
    against self_test.c: this config is accepted and completes; a
    callback budget of 2001 ms is rejected, so the check can fail.
  - Required (LED2): IMU, high-g, baro, radio, eMMC, per Inez's #137
    proposal. Warn-only: GNSS, Ethernet, SD NAND. Not an arming policy.
  - publish_status is NULL: radio transmit is not written yet.
- Results without a console: LED1 fast blink while running, then 1 Hz;
  LED2 on if a required check failed. g_bringup_report (global) holds the
  live coordinator status and the ADC snapshot for the debugger.
- STM32-UPLOAD-REQUIREMENTS.md: "First power-up" table of LED meanings
  and how to read g_bringup_report.

Nothing enables a pyro output or transmits.

* SX1262: report a missing radio instead of "no data" (review S1)

Sx1262::receive never looked at the status byte, so a missing chip or a
stuck MISO line (all 0x00 or all 0xFF) came back as NoData forever: 0x00
read as "no IRQ flags", 0xFF as "header + CRC error" and was cleared.
A dead radio looked like a quiet one.

Every "get" reply now has its status byte (reply byte 1) checked against
datasheet Rev 1.2, Table 13-76, p.95: chip mode (bits 6:4) must be 2..6,
and command status (bits 3:1) must not be 3 timeout, 4 processing error
or 5 failure to execute. Otherwise receive() returns ErrNotFound. 0x00
and 0xFF decode as modes 0 and 7.

Fake chip: its status byte was 0x2A, which decodes as STBY_RC + "failure
to execute"; now 0x54 (RX, data available). Adds set_status() and
set_stuck(level). Tests: stuck 0x00, stuck 0xFF, a failed command, and a
bad status in the second reply. Mutation-checked: accepting status 5,
or accepting chip mode 7, each turns one of them red. 75/75 pass.

* SX1262: add start_rx_continuous and state the RX requirement (review S2)

In single RX the chip returns to standby after one packet, and nothing in
the receive path put it back into RX. Sx1262::start_rx_continuous() sends
SetRx (0x82, datasheet Rev 1.2 p.62) with timeout 0xFFFFFF, continuous RX
(p.70). The class comment now says it must be called after start-up and
after every transmission, which leaves the chip in standby.

Fake chip records the bytes of the last command. Tests: the exact four
bytes go out after a BUSY check; nothing is sent if BUSY never clears.
Mutation-checked: timeout 0x000000 (single RX) turns the test red.
77/77 pass.

* SX1262: count packets the radio rejected (review S3)

Packets that fail the radio's own LoRa header or CRC check are discarded
and reported as NoData, so a bad antenna or too much range looked like
silence. Sx1262::crc_errors() counts them for telemetry. The header
notes it relies on LoRa CRC being enabled at start-up (review S4).

Test: one CRC error and one header error count 2, a good packet adds
nothing. Mutation-checked: removing the increment turns it red. 78/78.

* Link: count radio errors apart from bad frames (review L1)

ErrNotFound from the radio (chip not answering) went into
frames_dropped, the same counter as a bad CRC, so a dead radio and a
noisy channel looked the same. Link::radio_errors() now counts every
receive failure except ErrTooLong; ErrTooLong (a packet arrived but was
unusable) stays in frames_dropped.

Fake radio: fail_next_receive(status) makes the next radio_receive()
return that status once. Test: ErrNotFound and ErrTimeout count as 2
radio errors and 0 dropped frames. Mutation-checked: counting them as
dropped frames turns it red. 79/79 pass.

* Radio: keep packet buffers off the task stack (review L2)

Link::poll held a 255-byte packet buffer and a 254-byte Frame, and
Sx1262::receive two 258-byte ReadBuffer arrays: about 1.1 KB of stack per
poll, over twice the 512-byte default FreeRTOS task stack. They are now
members of Link and Sx1262 (one of each per radio task). ReadBuffer's
dummy bytes are still zeros.

Measured with arm-none-eabi-g++ -O2 -fstack-usage (Cortex-M7):
  Link::poll        536 -> 32 bytes
  Sx1262::receive   568 -> 48 bytes
79/79 native tests pass.

* ARM gate: pin the ground-station reboot behaviour (review A1, A2, A3)

If the ground station reboots and its sequence counter restarts, every
ARM is RejectStale until the rocket reboots. This fails safe, but on
launch day it looks like "ARM doesn't work". How to fix it (the ground
keeps its counter, or ARM carries a session number) is a protocol
decision, so it goes under "Decisions for the lead" in the README. No
behaviour changes here.

- test_ground_reboot_rejects_arm_until_rocket_reboots pins today's
  behaviour, so the chosen fix has to change this test on purpose:
  seq 100/101 arm, seq 1 and 2 are stale, UN_ARM still disarms.
- arm_gate.h: rule 3 says the ground counter must survive restarts; UN_ARM
  ignores the target id on purpose (A2); whether arming is allowed now is
  the state machine's decision, not the gate's (A3).
80/80 pass.

* Fake radio: refuse empty sends loudly (review #148 F2)

radio.h says a packet is 1 to 255 bytes, but the fake took len 0 (and a
null pointer) and answered Ok; memcpy from nullptr is also undefined
behaviour. The fake now asserts bytes != nullptr && len > 0, so a caller
that sends nothing stops the test run instead of passing. No new
RadioStatus value, so #147's contract is unchanged.

Checked with a small separate program: radio_send(nullptr, 0) aborts
(exit 134), a 1-byte send still answers Ok. 80/80 pass.

* Radio: start-up requirements and citation revision in comments (review S4-S6, L3)

Comments and README only, no code change:
- README "Not done yet": start-up must turn LoRa CRC on and call
  start_rx_continuous() after start-up and after every send; measured
  stack for Link::poll / Sx1262::receive and that both objects should be
  allocated once, statically.
- link.h: poll() drains one packet; the SX1262 holds one at a time.
- sx1262.h: the page citations are correct for datasheet Rev 1.2; the
  revision is now named (verified against DS.SX1261-2 Rev 1.2, June 2019:
  opcodes pp.62-64, IRQ table 13-29 p.80).
80/80 pass.

* firmware: initialize the eMMC once per power-up

The bring-up probe re-ran DeInit + MX_SDMMC1_MMC_Init on every self-test
retry (up to 3 attempts). THGBMTG5D1LBAIL rev 1.0 p.28: "avoid any
excessive iteration of resets and initialization sequences (Device
identification mode) ... which may result in read disturb failure",
e.g. repeated CMD0 - CMD1.

The probe now identifies the card on its first attempt only and reports
that cached result on retries. hmmc1 stays READY for the eMMC log adapter
(emmc_stm32.c on inez/emmc), which takes over every transfer after
bring-up. Found while coordinating with that work.

* firmware: eMMC flight log, recording from ARMED

Adds the flight computer's eMMC (U9, KIOXIA THGBMTG5D1LBAIL, 4 GB) flight
log, following the Flight_computer.drawio state machine. At this stage
recording starts at ARMED, not LAUNCHED, because launch detection does not
exist yet. Self-test and Idle never read or write the card.

- flight_state: the diagram's transition table and which states record.
  A stand-in for the real state machine (#162).
- emmc_log: append-only raw-block log, no filesystem. Every 512 B block
  carries an epoch, its own position, its session and a CRC32, so a power
  cut can only lose the chunk in flight. The end is found at mount by
  binary search. Sensor tasks never wait on the card: records go into
  16 KB RAM chunks; one writer task does all I/O; when full, records are
  dropped, counted and reported.
- emmc_card: CID/EXT_CSD checks against the datasheet.
- emmc_port: the seam, so the log runs on a laptop against a RAM disk.
- emmc_stm32: SDMMC1 + IDMA adapter. NOT YET COMPILED (the build comes
  with #165); its DMA buffers need a RAM_D1 linker section first.
- tests/emmc: 3 host suites, new CI job stm32-emmc-host. Five deliberate
  breaks of the code were each caught by the matching test.
- EMMC-ARCHITECTURE.md: design, datasheet facts, integration status.

Datasheet: https://datasheet.lcsc.com/datasheet/pdf/ea386c834ed06c7e4629df6606f52741.pdf
Refs #137

* firmware: CubeMX for interrupt-driven, RTOS-safe chip communication

.ioc (regenerated with CubeMX 6.18; generated diff checked line by line):
- NVIC on for EXTI0 (IMU_INT1 PD0), EXTI2 (RADIO_DIO1 PB2), EXTI3
  (ACCEL_INT_1 PD3), EXTI15_10 (ETH_INT PE15), UART9, SDMMC1, TIM2. All at
  priority 5 = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, so their ISRs
  may wake tasks (CubeMX clamps "uses FreeRTOS functions" IRQs to >= 5).
- ETH_INT on the falling edge: W5500 INTn is active low (W5500 v1.0.2,
  p.10, pin 36); it was rising.
- SPI1-4 Master Receiver Auto-Suspend: when a task is preempted mid
  transfer the master stops the clock instead of overrunning its RX FIFO
  (RM0468 Rev 3, MASRX, p.2201).
- TIM2 prescaler 63: a free-running 32-bit 1 MHz timebase at today's
  64 MHz timer clock; CH4 still captures GPS TIMEPULSE on the same clock.
- UART9 hardware FIFO on, RX interrupt at half full.
- The watchdog is NOT enabled yet; it comes with the task that feeds it.

Linker: a .dma_buffers (NOLOAD) section in RAM_D1. .data/.bss/stack are
in DTCM, which only the core and MDMA can reach (RM0468 Table 2 p.106,
Section 2.1.2 p.108), not the SDMMC IDMA or DMA1/2. board.h
BOARD_DMA_BUFFER places a buffer there (checked: a test buffer linked at
0x24000000). CubeMX leaves an existing linker script alone (checked).

scripts/cubemx_generate.sh regenerates without the GUI and restores each
file's line endings as git has them (CubeMX's CLI writes CRLF).

* eMMC: put the adapter's DMA buffers in RAM_D1

As agreed with the eMMC log work: chunks (64 KB), scratch and ext_csd
(512 B each) now use BOARD_DMA_BUFFER, i.e. the .dma_buffers NOLOAD
section in AXI SRAM, instead of plain aligned(32) .bss, which this
linker script places in DTCM where the SDMMC IDMA cannot reach (start()
would have refused with EMMC_ERR_PARAM). Checked in the object file: all
three are in .dma_buffers, 32-byte aligned. First compile of
emmc_stm32.c for the STM32: no errors or warnings.

* firmware: microsecond timebase and interrupt routing to tasks

- board_time: TIM2 as a free-running 32-bit 1 MHz counter (wraps every
  ~71.6 min) for every sample timestamp; CH4 captures the GPS TIMEPULSE
  (PB11) on the same counter. board_time_start() computes TIM2's real
  kernel clock from RCC (RM0468 Rev 3, RCC_CFGR.TIMPRE rule, p.371) and
  returns false if prescaler + clock tree don't give exactly 1 MHz, so a
  later HSE/PLL change can't silently skew timestamps. Started first in
  bring-up; the result is kept in board_bringup_t.time_ok.
- board_exti: HAL_GPIO_EXTI_Callback stamps each edge with board_time_us()
  and sets the owning task's thread flags (osThreadFlagsSet, ISR-safe).
  Routes: IMU_INT1 PD0 and ACCEL_INT_1 PD3 (sensors), RADIO_DIO1 PB2
  (radio), ETH_INT PE15 (ethernet). No bus traffic in any ISR.

* firmware: IMU driver (ISM330DHCX), portable and host-tested

drivers/ holds chip drivers that see only dev_bus_t (one chip-select
frame + a delay), so the same code runs on board_spi and on a scripted
fake in host tests. The board build compiles drivers/*.c.

dev_ism330dhcx (DS13012 Rev 7):
- WHO_AM_I 0x6B (p.48) before any write; SW_RESET in CTRL3_C, polled
  until it self-clears, bounded at 10 ms (p.51)
- CTRL3_C 0x44 BDU + IF_INC (p.51), CTRL4_C 0x04 I2C_disable (p.52),
  CTRL1_XL 0x74 833 Hz +-16 g (p.49), CTRL2_G 0x71 833 Hz +-4000 dps
  (p.50), COUNTER_BDR_REG1 0x80 pulsed data-ready (p.46), INT1_CTRL 0x01
  accel DRDY on INT1 (p.47); every register read back and verified
- one 14-byte burst from OUT_TEMP_L (20h): temp, gyro, accel (p.64-66)
- scale 0.488 mg/LSB, 140 mdps/LSB (p.10); 256 LSB/degC, 0 at 25 degC
  (p.13, Table 4 note 4)

tests/drivers: fake_regs (register-file fake: auto-increment, MS bit,
self-clearing bits, stuck bits, bus failure) and 8 IMU tests: exact
config bytes in order, wrong ID refused before any write, dead bus
(0xFF), reset timeout, read-back mismatch, bus error, burst decode,
bad arguments. Mutation-checked: +-2 g instead of +-16 g, and skipping
the read-back check, each turn a test red. ASan/UBSan clean.

* firmware: high-g accelerometer driver (H3LIS100DL)

dev_h3lis100dl (DocID027504 Rev 2; the board carries the H3LIS100DLTR,
not the H3LIS331DLTR on the rev 1 schematic):
- SPI first byte: RW bit 7, MS (auto-increment) bit 6, 6-bit address
  (p.20); WHO_AM_I 0x32 before any write (p.25). The H3LIS331DL also
  answers 0x32, so identity alone can't tell them apart.
- CTRL_REG4 0x00 4-wire SPI, CTRL_REG3 0x02 INT1 = data ready, active
  high, push-pull (p.28, Table 27), CTRL_REG1 0x37 normal mode 400 Hz
  X/Y/Z (p.25-26, Tables 19-20), written last; each read back.
- one 5-byte MS burst from 29h: X, Y, Z at 29h/2Bh/2Dh, 8-bit two's
  complement (p.30), 780 mg/digit, fixed +-100 g (p.9).
- The DRDY line is a level, so the sensor task must also read on a
  timeout (noted in the header).

6 tests: exact config, wrong ID refused before any write, read-back
mismatch, bus error, X/Y/Z from the right registers (reserved bytes
skipped), MS-bit guard. Mutation-checked: dropping the MS bit and
100 Hz instead of 400 Hz each turn a test red.

* firmware: barometer driver (MS5611) with datasheet compensation

dev_ms5611 (MS5611-01BA03 datasheet 06/2017, AN520):
- PROM read 0xA0..0xAE (p.10 Figure 4), AN520 CRC4; blank (all 0 / all
  1) PROM rejected before the CRC, since a dead bus can match by chance
- D1 0x48 / D2 0x58 at OSR 4096, read with 0x00 >= 10 ms later (9.04 ms
  max, p.3); an ADC result of 0 means read too early -> DEV_ERR_DATA
- first-order (p.8) and second-order (p.9, below 20 degC and below
  -15 degC) compensation in 64-bit integers with C division, exactly as
  the datasheet; temperature in 0.01 degC, pressure in Pa
- the power-on reset with CSB held low stays in board_bringup

test_ms5611 (command-driven fake chip): PROM + CRC (vector computed with
AN520 in Python), flipped bit / all 0 / all 1 rejected, D1/D2 commands
and early-read 0, the datasheet worked example (TEMP 2007, P 100009),
and two second-order vectors (11.75 degC; -30.22 degC very-low branch)
from an independent Python model using C truncating division.
Mutation-checked: no second order, >> instead of / (floor vs truncate),
and skipping the CRC each turn a test red.

* firmware: sensors task: IMU, high-g and baro on interrupts under RTOS

app/ holds the application. Each task is a portable core (no HAL, no RTOS;
time and events passed in) plus a thin RTOS loop, so flight_test can run
the same code on a laptop.

- app/records.h: record types 0x10+ (IMU, high-g, baro, ...) and packed
  little-endian payloads with pinned sizes; every one starts with t_us.
- app/sensors_core: SPI3 state machine. IMU read on its data-ready edge,
  stamped with the edge time from board_exti; high-g likewise, and read
  on a 2-period timeout when no edge comes (its DRDY is a level, so a
  missed read would otherwise silence it; counted as missed_drdy); baro
  D1 -> 10 ms -> D2 -> 10 ms -> compensate, ~50 Hz. A sensor whose init
  fails, or that fails 3 reads in a row, is re-initialized every second.
- app/sensors_task: Realtime priority, routes IMU_INT1/ACCEL_INT_1 to its
  thread flags, sleeps until an edge or the core's next deadline, appends
  each record to the eMMC log (emmc_log_append, non-blocking).
- app/app: app_start() brings up the eMMC log (emmc_stm32_init + its
  writer task) and the sensors task; bringup_task calls it after the
  self-test, so every chip is out of reset first.
- Core/board_devbus: dev_bus_t over board_spi (one locked CS frame,
  5 ms deadline; delay = osDelay(ms + 1), which is >= ms).
- tests/fakes: fake_regs moved here, fake_baro shared (was private to
  test_ms5611). tests/app/test_sensors_core: virtual clock with a 37 us
  task wake latency: rates (833 / 400 / ~50 Hz), values, edge-time
  stamps, high-g timeout reads, IMU failure -> dropped -> recovered,
  wrong chip keeps retrying, dead baro bus, deadlines, 32-bit clock
  wrap. Mutation-checked: no high-g timeout read, IMU stamped at read
  time, failed IMU never retried each turn it red.

Firmware: RAM_D1 now holds the eMMC log's 65 KB of DMA buffers.

* firmware: move chip drivers from drivers/ to chips/

macOS file systems are case-insensitive, so drivers/ and CubeMX's
Drivers/ (ST HAL + CMSIS) were the same folder on a Mac: the drivers
were committed under Drivers/, inside the vendored code. On Linux (CI,
teammates) platformio.ini's ../drivers would not have existed, and
format.sh skipped them as vendored (Flight_Computer/Drivers is in its
skip list).

chips/ cannot collide with anything CubeMX generates. tests/drivers ->
tests/chips; platformio.ini, both test CMakeLists and dev_bus.h updated.
No code change. Checked: nothing of ours left under Drivers/ in git;
firmware builds; chips (3) and app (1) host suites pass under
ASan/UBSan; format.sh now checks all 7 chip files (dev_bus.h needed
reformatting, done).

* firmware: UBX protocol for the MAX-M10S (VALSET, NAV-PVT)

chips/ubx (u-blox M10 SPG 5.10 Interface Description, UBX-21035062 R02):
- ubx_frame: B5 62 class id len payload + 8-bit Fletcher
- ubx_valset: UBX-CFG-VALSET (0x06 0x8A, 3.10.5.1 p.55), version 0,
  RAM layer only (re-sent every power-up, nothing burnt to flash)
- ubx_parse_nav_pvt: UBX-NAV-PVT (0x01 0x07, 92 bytes, 3.15.11 p.95)
- keys: CFG-UART1-BAUDRATE 0x40520001 (p.153), CFG-UART1OUTPROT-NMEA
  0x10740002 (p.154), CFG-MSGOUT-UBX_NAV_PVT_UART1 0x20910007 (p.136),
  CFG-RATE-MEAS 0x30210001 (p.147), CFG-NAVSPG-DYNMODEL 0x20110021 with
  AIR4 = 8 "airborne <4g" (Table 23, p.141), the highest model there is

Core/gnss_frame: keeps the class, id, length and first 100 payload bytes
of each UBX frame, so one byte-at-a-time parser serves the self-test
probe and the GNSS task.

Datasheet facts for the GNSS task (MAX-M10S data sheet UBX-20035208 R02):
the default UART is 9600 baud (5.3, p.13), not the 38400 assumed in
#137; 10 Hz NAV-PVT (~1000 B/s) does not fit at 9600, so the task will
raise the module to 115200. PVT up to 10 Hz (p.4).

test_ubx: VALSET frames and a NAV-PVT frame encoded independently in
Python, decoded through gnss_frame + ubx_parse_nav_pvt. Mutation-checked:
writing all layers (incl. flash) and reading velD from the wrong offset
each turn it red.

* firmware: GPS task: MAX-M10S on interrupt-driven UART9, 10 Hz NAV-PVT

board_uart9 (Core): HAL ReceiveToIdle interrupts (UART FIFO at half
full, from the .ioc) into a 1 KB single-producer/single-consumer ring;
each burst sets the GNSS task's thread flag. No DMA, so no DTCM issue.
Blocking 100 ms-bounded transmit for the short UBX config frames;
set_baud re-inits UART9 and re-arms receive.

gnss_core (app, portable):
- DETECT: listen 1.5 s each at 9600 (the module's default, data sheet
  UBX-20035208 p.13), 38400, 115200 for one valid NMEA/UBX frame
- CONFIG: VALSET CFG-UART1-BAUDRATE 115200 if lower (10 Hz PVT is
  ~1000 B/s, more than 9600 baud carries), then NMEA off, NAV-PVT on
  UART1, CFG-RATE-MEAS 100 ms, dynamic model AIR4; waits for ACK-ACK of
  CFG-VALSET, 3 tries of 500 ms; a NAK restarts detection
- RUN: every NAV-PVT -> REC_GNSS (rec_gnss_t, 49 bytes) stamped with its
  arrival and the latest TIMEPULSE edge (TIM2 CH4); 2 s without a fix
  -> back to DETECT, so a power-cycled module (RAM config lost) is
  reconfigured
gnss_task: Normal priority, woken by received bytes or the core's next
deadline. Started from app_start after the sensors task.
records.h: record_sink_t shared by the task cores (sensors_sink_t is now
an alias).

AIR4 is the highest dynamic model the M10 has (Table 23, p.141); a boost
above 4 g can lose the fix, which the 2 s watchdog then recovers.

Tests:
- fake_gnss: a simulated MAX-M10S that parses VALSET itself, sizing each
  value from the key ID (bits 30..28, Interface Description p.124), only
  hears the board at a matching baud, and sends garbage at a wrong one
- test_gnss_core: cold start at 9600, warm module at 115200, NAK,
  silence + power cycle, PPS stamping. Mutation-checked: skipping the
  baud change, treating NAK as ACK, ignoring silence each turn it red
The end-to-end [gps] check lives on inez/flight/flight_test.

* firmware: task-core comments name the host tests, not a tool on another branch

* firmware: link newlib-nano in the PlatformIO build, as CubeMX does

CubeMX's cmake/gcc-arm-none-eabi.cmake links with --specs=nano.specs;
env:flight did not, so the two builds of one project used different C
libraries. With the full newlib, one vsnprintf (the boot report) cost
~29 KB of flash; with nano the image is 69.7 KB instead of 98.2 KB.
Nano's printf has no float support; no firmware code prints floats.

* firmware: start-up self-test reports battery voltage and a verdict

The self-test already checked every chip at boot (IMU/high-g WHO_AM_I,
baro PROM CRC, W5500 version, SX1262 status, GPS frame, SD NAND CID,
eMMC CID) and read raw PA0 counts. Missing was the battery adapter and a
report a person can read.

app/battery: counts -> mV -> health.
- Schematic rev 1 p.2: VDD -> R1 22k / R3 10k (x 0.3125) -> TLV9004
  follower -> PA0; VREF+ = VDDA = 3V3 through FB1. p.12: 3V3 from the
  TPS562201, 0.768 V x (1 + 33.2k/10k) = 3.318 V (~ +/-2 %).
  mV = counts x 10624 / 65535, the same as Aaron's idle module (#162).
- p.12: VDD is the TPS2121's output (IN1 battery, IN2 USB; battery wins
  above ~3.5 V). SW_ST (PE10) HIGH = battery, LOW = USB (TPS2121 p.21).
  On USB the reading is USB_5V and is never judged as the pack.
- OK >= 7.0 V, WARN < 7.0 V, FAIL < 6.6 V (proposals, the same as #162),
  FAIL > 8.8 V (above a full 2S pack + 2 %: wrong pack or divider).
board_bringup_read_battery now averages 16 conversions within its
budget; board_bringup_on_usb reads SW_ST.

app/boot_report: verdict (READY / WARN / FAIL), result_bits (bit =
device id passed: the SelfTest radio frame's field, src/frame.h) and a
text report, one line per chip plus the battery and the verdict. The
GPS line shows the baud it was heard at. FAIL = a required chip
(IMU, high-g, baro, radio, eMMC) failed or the battery is FAIL/unread;
WARN = an optional chip (GPS, Ethernet, SD NAND) failed or the battery
is low. Required vs optional is #137's proposal, not an arming policy.

bringup_task: builds the report into g_bringup_report.report after the
checks (battery sampled before anything transmits). LED2: off READY,
blinking WARN, solid FAIL. In the debugger:
printf "%s", g_bringup_report.report.text

test_boot_report: conversion against counts computed independently in
Python (incl. #162's 40712 -> 6600, 51818 -> 8400), every threshold edge,
USB, ADC failure, each verdict, the exact text. Mutation-checked:
ignoring SW_ST, dropping the WARN band and counting optional failures as
required each turn it red.

* firmware: build with debug info so gdb can read the board over ST-Link

env:flight compiled without -g, so the ELF had no symbol types and gdb
answered "'g_bringup_report' has unknown type": the self-test report
could not be read over SWD, by a person or by flight_test --board.
-g3 adds debug sections to the .elf only; the flashed image is the same
size (69,656 bytes) and the same code.

* radio: SX1262 start-up and transmit (TxDone), on Ryan's SpiBus

New src/sx1262_setup.{h,cpp} next to Ryan's receive path. Semtech
DS_SX1261-2 Rev 1.2; Seeed Wio-SX1262 datasheet V1.1.

configure(), in the order of 14.2 / 14.4 (p.99-100):
- SetStandby STDBY_RC; SetRegulatorMode DC-DC (the Wio uses DC-DC, p.4)
- SetDIO3AsTCXOCtrl 1.8 V, 5 ms (Table 13-35 p.82; the value Meshtastic's
  Seeed XIAO + Wio-SX1262 variants use; >= 200 mV under VCC per Seeed)
- Calibrate all blocks (p.57: the power-on calibration fails with a
  TCXO), ClearDeviceErrors (expected XOSC_START_ERR, p.82)
- SetDIO2AsRfSwitchCtrl (p.81; Wio: DIO2 high = TX)
- LoRa, 915 MHz (word = f x 2^25 / 32 MHz, p.83), CalibrateImage 902-928
  (Table 9-2 p.57), PA +22 dBm optimal setting 04 07 00 01 (Table 13-21
  p.77), SetTxParams +22 dBm / 200 us ramp (p.84), buffer base 0/0
- SF9 / 125 kHz / 4/5, LDRO when a symbol >= 16.38 ms (p.39); explicit
  header, CRC on (Ryan's crc_errors needs it), standard IQ (p.91-92)
- TxDone, RxDone, HeaderErr, CrcErr, Timeout all on DIO1 (p.79-80)
- errata 15.2: TxClampConfig 0x08D8 bits 4:1 = 1111 (p.103)
- sync word 0x1424 written explicitly (p.65)
- GetDeviceErrors must read 0 (p.98), then continuous RX
Returns the first failing step, so a dead radio says where it stopped.

send(), Ryan's radio_send() contract (Ok only after TxDone):
standby, RF_SW off, errata 15.1 (0x0889 bit 2, p.102), packet length,
WriteBuffer, clear only TxDone/Timeout (an Arm packet that arrived just
before is kept for the next receive()), SetTx with a chip timeout of 2 x
time on air (p.69), poll TxDone/Timeout 1 ms apart up to 2 x ToA + 50 ms,
then back to continuous RX with RF_SW on. Time on air from 6.1.4 (p.41).

RF_SW (PB1) is driven high while receiving: Meshtastic drives this
module's RF_SW as RXEN with DIO2 on the TX side. Verify on the bench.

Proposals for the lead (README "Decisions"): 915 MHz, SF9/125k/4-5,
+22 dBm, sync 0x1424. The ground station must match.

sx1262.h: Ryan's status-byte check exposed as sx1262_status_ok() so the
new code reuses it.

test_sx1262_setup (native, against a pretend chip with registers, IRQs
and device errors): exact command order and bytes, failing-step reports,
TxDone, timeouts (chip and host), RxDone preserved across a send, bad
input and a missing chip. Frequency word and time on air checked against
an independent Python calculation of p.41. Mutation-checked: clearing
every IRQ before TX, a 3.3 V TCXO and a skipped clamp fix each turn it
red. pio test -e native: 87/87.

* radio: radio task on the board (SPI1, DIO1, RF_SW), Ryan's Link in firmware

Ryan's radio code (src/*.cpp) only ran in the native tests; env:flight
now compiles it (+<*.cpp>, +<../app/*.cpp>, -Isrc) with -fno-exceptions
-fno-rtti -fno-threadsafe-statics. Startup already calls
__libc_init_array, so the global objects are constructed.

app/radio_task:
- BoardBus: Ryan's SpiBus over board_spi (SPI1, CS PC4), waiting on BUSY
  (PC5) up to 20 ms (calibrate 3.5 ms + TCXO 5 ms). A failed transfer
  returns zeros, which sx1262_status_ok() rejects as "no chip".
- BoardControl: RF_SW (PB1) high while receiving, osDelay for waits.
- Ryan's radio_probe/receive/send implemented on the real chip.
- The task: Sx1262Setup::configure(), retried every 5 s until it
  answers; DIO1 (PB2, EXTI2) wakes it; one Link::poll() per wake and once
  a second; a confirmed Arm or an Un-arm goes to a callback.
- radio_task_send_frame(): encode_frame + send under one mutex
  (priority inheritance), Ok only after TxDone. Any task may call it.
- radio_task_status(): setup step, device errors, Link counters, CRC
  errors, TX ok/timeouts, arms/disarms.
Target id 0x01 is a placeholder, like the key in arm_gate.h.

app_start starts it (AboveNormal, 1 KB stack: the packet buffers live in
the static Link and Sx1262Setup). Flash 72.3 KB (+2.6 KB).

* feat(idle): switch Idle radio to SetRxDutyCycle sniff mode

Replaces continuous RX (4.6 mA) with SetRxDutyCycle 33 ms / 1 s (~0.15 mA
average) in Idle. The STM32 side is unchanged — it still waits for DIO1.

- Sx1262Setup: add start_rx_duty_cycle(), start_rx_continuous(), rearm_rx();
  back_to_rx() and send() restore whichever mode is active.
- radio_task: re-arm after every real DIO1 event (not the 1-second fallback
  poll); expose radio_task_start_sniff() / radio_task_start_continuous_rx().
- idle_task: starts radio in sniff mode (33 ms / 1 s).
- mode: on Arm → continuous RX; on Disarm → sniff.
- Tests: 6 new unit tests (byte values, 1 ms = 64 steps, re-arm, no-op in
  continuous, send restores duty cycle, start_rx_continuous); fake_air listen-
  window model; idle_e2e (long preamble always heard, short preamble missed,
  average current < 0.3 mA, re-arm after RxDone). 93/93 pass.

Ground station must send Arm/Un-arm with ≥260-symbol preamble (~1.08 s at
SF9/125 kHz). kArmConfirmWindowMs (2 s) is tight with two 1.2 s frames —
recommend widening before flight.

* feat(idle): switch Idle radio to SetRxDutyCycle sniff mode

Replaces continuous RX (4.6 mA) with SetRxDutyCycle 33 ms / 1 s (~0.15 mA
average) in Idle. The STM32 side is unchanged — it still waits for DIO1.

- Sx1262Setup: add start_rx_duty_cycle(), start_rx_continuous(), rearm_rx();
  back_to_rx() and send() restore whichever mode is active.
- radio_task: re-arm after every real DIO1 event (not the 1-second fallback
  poll); expose radio_task_start_sniff() / radio_task_start_continuous_rx().
- idle_task: starts radio in sniff mode (33 ms / 1 s).
- mode: on Arm → continuous RX; on Disarm → sniff.
- Tests: 6 new unit tests (byte values, 1 ms = 64 steps, re-arm, no-op in
  continuous, send restores duty cycle, start_rx_continuous); fake_air listen-
  window model; idle_e2e (long preamble always heard, short preamble missed,
  average current < 0.3 mA, re-arm after RxDone). 93/93 pass.

Ground station must send Arm/Un-arm with ≥260-symbol preamble (~1.08 s at
SF9/125 kHz). kArmConfirmWindowMs (2 s) is tight with two 1.2 s frames —
recommend widening before flight.

Ported from #182 onto main after #187/#188: paths follow the src/ layout
(src/chips/sx1262_setup, src/radio/radio_task, tests/radio/). The sniff
tests are their own suite, tests/radio/test_sniff, with fake_air beside them;
the stand-in idle_task/mode files are replaced by the wiring in the next
commit, since main now has the real Idle.

* Sniff mode: clang-format Megan's files to the repo style (no code change)

* firmware: Idle sniffs, Armed listens: wire Megan's duty cycle into the mode table

mode_core gains radio_sniff (true only in IDLE); mode.c applies it with
radio_task_start_sniff(33 ms, 1 s) / radio_task_start_continuous_rx(), so
every state change sets the RX mode, including Un-arm back to Idle. The
radio task remembers the mode asked for and applies it after a late
start-up (Idle can begin before the SX1262 is configured).

idle_e2e follows the board: the fake SX1262 models SetRxDutyCycle and
drops to standby after a packet in sniff mode (DS 13.1.7, p.71). Checks:
- idle_rx_asleep: the radio is sniffing in every Stop (was: continuous)
- idle_arm_wake: both Arms heard (the first ends the cycle; re-armed on
  DIO1), and ARMED listens continuously
Without the re-arm idle_arm_wake fails; with Idle not sniffing app and
idle_rx_asleep fail. Preamble timing is Megan's tests/radio/test_sniff.

---------

Co-authored-by: R-Leano <ryanleanoj@gmail.com>
Co-authored-by: inez9 <145737083+inez9@users.noreply.github.com>
Co-authored-by: Megan Hu <meganxhu@berkeley.edu>
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.

2 participants