Repository navigation
Conversation
The SPI of F7 has a 4-byte FIFO and that of F4 none, so there every data-ready read goes through two DMA streams. The SPI stays enabled, as for the main loop's transfers, and setting its DMA requests starts the read. The streams are taken like on H7, among the options the reference manual gives each request, at the end of initialisation. Nobody has tested this on an F4 or F7 board yet, so gyro_data_ready AUTO leaves it off there: ON turns it on.
Pins added where INAV and Betaflight's config for the same board agree on the gyro's CS pin and SPI bus. In a folder with several targets the pin goes only to those Betaflight confirms. Two targets had a pin that disagreed with Betaflight and is fixed: KAKUTEF4WING (PB12, now PB2) and AOCODARCF405AIO (PC5, now PC4, as on the rest of the Aocoda F405 family, where PC5 is a PINIO). INAV never read those pins, so the wrong values never showed.
gyro_fifo_samples (0 to 4, default 0: register reads as before) lets the ICM426xx queue that many samples in its FIFO and raise its interrupt once for all of them. One read from FIFO_COUNTH brings the count and the packets, and the gyro task still gets every sample. A FIFO that falls behind or out of step is flushed from the gyro task.
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoAdd optional ICM426xx FIFO reads on gyro data-ready
AI Description
Diagram
High-Level Assessment
Files changed (120)
|
Code Review by Qodo
1.
|
…et does not enable
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #12067 251 targets built. Find your board's
|
1e18810 to
3b813d9
Compare
AUTO now reads the ICM-42605 and ICM-42688-P on their data-ready interrupt on every family. Where no interrupt arrives the gyro is read from its registers as before.
3b813d9 to
32f2928
Compare
…Betaflight comparison missed
…eads it Written once at setup, so cleaned once there: nothing at run time. A no-op today: DMA_RAM is Shareable in the H7 MPU setup and the Cortex-M7 does not cache it, and on F7, which runs the same setup, INAV leaves the D-cache off. It matches the invalidate on the reply and stays right should either change. (cherry picked from commit 4287429)
|
PG note (corrected): this PR appends |
The new fields are appended with a zero default, so stored settings load as they are: pgLoad copies the stored bytes over the defaults. On H7 without USE_DUAL_GYRO gyro_data_ready takes the old record's tail padding, which the reset template leaves at zero.
|
@sensei-hacker tested on an F7 today, a Flywoo F722 Pro V2 with |
|
The ICM-42605 has run this now, on two boards at rest (not moved by hand, no log yet):
|
|
Axes checked with the board moved by hand: the Diatone Mamba F722 2022B (ICM-42605) held in three poses and turned, on maintenance-10.x (polled), on data-ready, and with
Same axes and signs in all three. |
|
A correction to my comments of 2026-10-07 here and on #12064: the E-flite T-28's TBS Lucid H7 Wing and the Diatone Mamba F722 2022B both carry an ICM-42688-P, not an ICM-42605. INAV prints "ICM42605" for the 42605, the 42686-P and the 42688-P alike, and I took the name from |
# Conflicts: # src/main/drivers/bus_spi_hal_ll.c
|
Thanks for the PR! I looked at this with an AI-based tool that read the diff and ran it on one F7 board. It may well be wrong on any of these points, so please treat them as questions. On DAKEFPVF722X8 (F7, ICM-42605), Questions
|
…ebug USE_GYRO_FIFO is defined only when the ICM426xx driver is built and the target names its interrupt pin. It carries the FIFO code, the larger data-ready rows and sample queue, and gyro_fifo_samples; the other data-ready builds keep the smaller ones (about -0.6 KB flash, -0.4 KB RAM). Three flushes for a fault within a second make the FIFO give up for the session: the interrupt is disabled and the gyro is read from its registers. The flush and the clear of its flag run under one hold of the bus, so no read starts between them. The GYRO_FIFO debug mode shows the flushes, the samples they dropped, the samples per read and whether the FIFO gave up. On F7 and H7 the rows are 96 B, whole cache lines.
|
Thanks for testing it. 1. Loss visibility. Agreed, and I've added a limit too. What already guarded it: a FIFO more than two groups behind, a packet out of step or four reads in a row with nothing usable trigger a flush, a full queue pauses the interrupt, and 2 ms without a sample switches to the registers, so a lost interrupt can't freeze the gyro. What it lacked was a limit on the flushes: a fault that keeps raising them would leave the gyro running in fits. Now, if the FIFO needs three flushes for a fault within a second, it gives up for the rest of the session and the gyro is read from its registers, as with data-ready off, the same one-way fallback the data-ready reads have after three stalls. The 2. Flush race. Yes, and clearing the flag first isn't enough either: the read still running when the flush begins can raise it again with data from before the flush. The flush and the clear now run under one hold of the bus, so no read starts between them, and a request raised meanwhile can only come from that last read, which is about what the flush empties. 3. Flash cost. Done: 4. Merge order. 32f2928 is #12065's "data-ready on by default for the ICM426xx on F4 and F7 too" (93bfebe there), copied here because this PR builds on #12065, not on #12066. The order is #12064, #12065, then this one; #12066 is independent of it. 5. H7 buffer. On H7, DMA_RAM is shareable, which the Cortex-M7 does not cache unless CACR.SIWT is set, and INAV doesn't set it, so the alignment was harmless. The rows are now 96 B anyway, whole cache lines, on F7 and H7, which share this code (192 B more RAM). 6. Testing. So far only with the ICM-42688-P, on H7 and F7 boards: not on F4, not with the other ICM426xx chips and not with both gyros of a dual-gyro board. Inside a group the samples come oldest first, and the oldest is up to |
|
Against an older baseline: the ITCM drop is #12169, merged into next-10.1 since. Most of the rest is #12065, which this PR builds on. This PR's own share against #12065: +1296 B of flash, +512 B of D2_RAM (the FIFO's longer read buffers) and +256 B of RAM on MATEKH743; MATEKF405, MATEKF722 and MATEKF765 have no ICM426xx with its interrupt pin, so no FIFO, and only the debug mode's name (+28 to +36 B). |
Builds on #12065 (data-ready reads on F4 and F7), which builds on #12064 (data-ready on H7) and #12061 (SPI back to back), both merged. Their commits show here until they are merged, with copies of their later changes; the rest are this PR. It does not need #12066.
Off by default.
gyro_fifo_samples = 0keeps the data-ready read of those PRs exactly as it is.What this adds
With data-ready, the ICM426xx interrupts once per sample and each interrupt starts one SPI read.
gyro_fifo_samples(1 to 4) lets the IMU queue that many samples in its FIFO and interrupt once for all of them:FIFO_COUNTHbrings the count and the packets: one more packet than the threshold where the read fits, so a single late sample does not leave the reads one behind. Every packet read has left the FIFO, so all of them are decoded, up to the first empty one.debug_mode = GYRO_FIFO, first gyro: debug[0] flushes, debug[1] samples they dropped, debug[2] samples per read, debug[3] 1 once the FIFO has given up.Only where it can run.
USE_GYRO_FIFOis defined where the ICM426xx driver is built and the target names its interrupt pin (ICM42605_EXTI_PIN,GYRO1_EXTI_PINorGYRO2_EXTI_PIN): about 100 of the 300 F4, F7 and H7 builds. It carries the FIFO code, the longer read buffers (72 B on F4, 96 B on F7 and H7), the 16-sample queue andgyro_fifo_samples; the other builds keep #12065's.The trade-off, in the setting's description: fewer interrupts and nothing lost to a late read, but the oldest sample of a group reaches the gyro task up to
gyro_fifo_samplessample periods later (1 ms at 4 with a 4 kHz gyro).Measured
TBS Lucid H7 Wing, ICM-42688-P on SPI1 at 4 kHz, 20 s per setting, counters in a bench build that are not part of this PR:
gyro_fifo_samplesNo flush, no packet out of step, no invalid sample in any run. Each setting was also saved five times with the host closing the USB port during the write, plus another 20 saves at 1, all fine (that interaction is handled in #12064).
Size
Against #12065 (7c07383):
Without the FIFO only the debug mode's name is added. Also built on FLASHHOBBYF722 (99.60%, the fullest F722 with the FIFO), KAKUTEF7 and KAKUTEF7HDV (ITCM unchanged) and SITL.
Not tested, testing wanted
set gyro_fifo_samples = 2on the bench, then checktasks(GYRO task), the Sensors tab (gyro and accelerometer follow the board) and a blackbox log withGYRO_RAWandACC.A report of which board and what was checked is very welcome.
After review
gyro_fifo_samplesis appended with a zero default, so stored settings load unchanged.Built on F4, F7, H7, AT32 and SITL; KAKUTEF7 and KAKUTEF7HDV fit their ITCM. On the TBS Lucid H7 Wing after review: FIFO at 2 samples, 1996 reads/s and 3992 samples/s, no flush and no packet out of step; 40 saves with the USB port closing, no stop.
After sensei's review of 2026-10-18: the FIFO only where it can run, the limit on flushes, the
GYRO_FIFOdebug mode, the bus held across a flush and the clear of its flag, 96 B rows on F7 and H7 (whole cache lines). Built on F4, F7, H7, AT32 and SITL, unit tests pass.On the TBS Lucid H7 Wing (2026-10-20), at rest, 60 s per case, each ICM-42688-P in turn (
gyro_to_use0 on SPI1, 1 on SPI4): withgyro_fifo_samples2 and 4 every read held 2 and 4 samples (GYRO_FIFOdebug), there was no flush and the FIFO never gave up; the GYRO task ran at 3952 to 3984 Hz, 1 to 2 us on average, 7 to 10 us at most. The one flush is at boot, before the gyro task runs: the queue fills, the FIFO pauses and restarts flushed (15 samples), which doesn't count as a fault.Tested on more boards (2026-10-06)
Testing: the branch has maintenance-10.x merged in since 1ee20ac, with #12032 (H7 SPI2-4 divisors) and #11943 (flash flush), so an image from this head builds as tested below.
Tested 2026-10-06 on an F7, Flywoo F722 Pro V2,
gyro_fifo_samples = 2: GYRO task 5 us average (3 with data-readyalone, 12 polling), IMU at rest acc noise 0.7, gyro 0 +-0.2, moved by hand 25 s consistent (8 deg). Image from this
head on its old base (the F7 has nothing on SPI2-4 at risk); other ICM426xx variants still untested.