Skip to content

feat(debug): add IMUF9001_CRC debug_mode for CRC error + stale-transfer diagnostics [low priority / not required] #1339

Description

@nerdCopter

AI Generated [issue-ticket]

Summary

Add a new debug_mode for continuous, blackbox-correlated diagnostics of the IMUF9001 SPI link: CRC error count and stale-transfer (skipped GYROPID cycle) count. Currently these are either not measured at all, or only available as a cumulative CLI query, not correlated against flight time/motor output/vibration in blackbox.

Background

refactor/imuf9001-dma-migration (PR #1283) moved the IMUF9001 SPI transfer from the EXTI ISR into GYROPID task context, gated by a dataReady flag and an imufTransferPending race-clear flag (accgyro_mpu.c, accgyro_imuf9001.c). Two health signals exist for this path today but neither is continuously observable during flight:

  1. CRC errorscrcErrorCount (accgyro_mpu.c:198,211-212) increments on every CRC mismatch in imufIntCallback. Only exposed via the reportimuferrors CLI command (cli.c:4376,4448-4452) as a cumulative total queried before/after flight — not logged continuously, so a CRC error burst cannot be correlated to a specific flight moment (e.g. high vibration, hard throttle punch).
  2. Stale/skipped transfersimufSpiGyroRead() (accgyro_imuf9001.c:208-214) returns gyro->dataReady; if false, GYROPID skips the cycle (no new IMUF sample was ready). There is currently no counter for how often this happens. The theoretical race window from clearing imufTransferPending before the SPI call is estimated at ~0.1% of cycles but has never been measured on real hardware.

Neither of these is specific to any board — IMUF9001 is shared by HELIOSPRING, STRIXF10, and MODE2FLUX. A per-target name (e.g. HELIO_CRC) was considered and rejected in favor of a driver-scoped name, matching existing precedent: DEBUG_RX_FRSKY_SPI and DEBUG_RX_SFHSS_SPI (build/debug.h:70-71) are named after the protocol/driver, not the board they happen to run on.

Proposed Name

DEBUG_IMUF9001_CRC (working name — open to bikeshedding at implementation time).

Proposed Implementation

  • Add DEBUG_IMUF9001_CRC to debugType_e (build/debug.h) and debugModeNames[] (build/debug.c)
  • In imufIntCallback() (accgyro_mpu.c): DEBUG_SET(DEBUG_IMUF9001_CRC, 0, crcErrorCount)
  • Add a new counter (e.g. imufStaleTransferCount) incremented in imufSpiGyroRead() when dataReady is false at return; DEBUG_SET(DEBUG_IMUF9001_CRC, 1, imufStaleTransferCount)
  • Guard both behind #ifdef USE_GYRO_IMUF9001

Constraint

EmuFlight's debug[] array is DEBUG16_VALUE_COUNT = 4 (Betaflight is 8 — tracked separately in #1338). This proposal uses 2 of the 4 slots, leaving 2 free. Only one debug_mode can be active at a time, so this competes with any other diagnostic a pilot wants during the same flight — by design, this is meant for driver validation, not routine flying.

Scope

Out of scope for PR #1283 (pure host-driver migration, no debug_mode changes). This should land as its own focused PR once resourced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions