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.
|
ⓘ 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 opt-in F4/F7 gyro data-ready reads and improve SPI transfers
AI Description
Diagram
High-Level Assessment
Files changed (120)
|
Code Review by Qodo
1.
|
…et does not enable
|
Test firmware build ready — commit Download firmware for PR #12065 251 targets built. Find your board's
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
685a7e7 to
891ce2e
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.
ac7ce0e to
93bfebe
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 a field to the end of |
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 (ICM-42688-P on SPI1, interrupt on PC3), image merged on the current maintenance-10.x. Data-ready engages, GYRO task 12 -> 3 us, IMU still and moved by hand consistent, blackbox at rest and in motion with no missing iteration; details in the description under "Tested on more boards". F4 still has no tester. Is there anything else you would like tested? |
|
Also ran on a second F7: a Diatone Mamba F722 2022B (ICM-42688-P), with data-ready on. The GYRO task takes 4 us on average instead of 12 polled, 15 at most instead of 22. Moved by hand into three poses, it shows the same axes and signs as polling; the numbers are in #12067 (comment). |
# Conflicts: # src/main/drivers/bus_spi_hal_ll.c
|
I tested on an F4 (SKYSTARSF405V2), an F7 (X8, including armed blackbox and DShot), and the ACCTON_GFF4 (null case plus data-ready on). |
|
Thanks for the PR! I looked at this with an AI-based tool that read the diff, audited the DMA stream choices and ran it on a few boards. It may well be wrong on any of these points, so please treat them as questions, and correct me if I have misread something. What we saw on hardware
The DMA audit found no stream conflict on the boards we looked at. Nice work on that. A few things I am curious about
Not yet testedDo you know of runs on an F4 with an SD card on SDIO (SYNERDUINOSTM_F405, PIXRACER)? |
|
The F722 now fails to build on ITC RAM overflow. This change to common.h turns on USE_SPI_DATA_READY for F4 and F7 as well as H7.
To make room, we can probably NOINLINE some SD-card code. I did that in: |
|
Thanks for testing it on the DAKEFPVF722X8 and the SKYSTARSF405V2, and for #12169: with it KAKUTEF7 and KAKUTEF7HDV fit their ITCM with data-ready on (93.6% and 94.3%), and CI is green again. 1. Reserved UART streams. The list fills itself: it is built at compile time from the target's 2. Failure counter. The one-way fallback is deliberate (the description says so). A read that never ends points to the bus or to the DMA setup rather than to chance, and each one costs the main loop up to 300 µs of waiting plus a bus reset. Resetting the counter on disarm would bring those back on every flight while the cause is still there; three leaves room for a rare glitch before giving up. A reset on disarm is only a few lines if you prefer it, but I'd keep it one-way. 3. Retry on gyroDataReadyStart. The search runs once per boot: 4. Flash. On F4 it is not a concern: +4.3 KB on MATEKF405SE, which stays at 79.6%. On F722 I built all 88 targets from this branch against next-10.1: all of them fit, the PR adds 2.9 to 3.3 KB, and six end above 99%: FLASHHOBBYF722 (99.35%, 3,177 B free), IFLIGHT_BLITZ_F722_X1_OSD, MAMBAF722_2022B, TMOTORF7V2, MATEKF722SE and JHEMCUF722. I'd keep it on everywhere for now and SDIO. I have no F4 with SDIO. From the code there is no conflict: the SDIO driver claims its DMA stream (DMA2 stream 3 or 6) in |
|
Against an older baseline, as the report says: the ITCM drop on F722 and H743 is #12169, merged into next-10.1 since. The rest is this PR's data-ready reads on F4 and F7, about 4.3 KB on F405 and 2.6 to 3.3 KB on F722; all 88 F722 targets fit, the fullest (FLASHHOBBYF722) at 99.35 %. |
I have a Question on SDIO for F405 if it exist , would the code be similar on the H7 or is it something different |
|
@synersignart INAV has SDIO on the F4 too: |
ah ok, yes about the GyroAcc drives in the BMI160 yes alter it on my commit / pull request because for the longest time im using the BMI160 the Gyro and Accelerometer are always oriented in a weird way that prevents Horizon and Angle mode from operating correctly. |
Builds on #12064 (read the ICM426xx on its data-ready interrupt), which is H7 only and builds on #12061. Their commits show here until they are merged, with copies of the fixes from their review; the rest are this PR: the same read on F4 and F7, the interrupt pins of F4 and F7 boards, the fixes from its review, and data-ready on by default.
CI needs #12075. The red
build (7)here is KAKUTEH7WING failing incommon/log.c: the settings generator dropsUSE_LOGfor that target because of how it reads the compiler's output, not because of this code. #12075 fixes the generator. The same tree builds locally.On by default, run on two F7 boards and not yet on an F4 (Flywoo F722 Pro V2 and Diatone Mamba F722, see below). With
gyro_data_ready = AUTO(the default) F4 and F7 read the ICM426xx on data-ready where the target declares the pin; where no interrupt comes, the gyro is read from its registers as before.set gyro_data_ready = OFFgoes back to polling.What changes
The read goes through DMA. The data-ready PR reads the gyro out of the SPI FIFO on H7. F7 has a 4-byte FIFO and F4 none, so here every data-ready read goes through two DMA streams, like the longer reads on H7:
The ADC can move to its other stream. On F4 and F7 each SPI request can use only one or two fixed streams, and on many boards the ADC holds DMA2 stream 0 while a timer holds the other stream SPI1 could receive on. ADC1 can also use DMA2 stream 4: when both streams an SPI needs are taken and the ADC has one of them, the ADC is stopped, moved to the other stream if it is free, and started again, once, at the end of initialisation. The receive stream is claimed before the transmit one is looked for, so a move for the transmit side can not put the ADC back onto it. By a count over the targets' timer and serial stream tables, this is what gives 43 of them a free pair of streams.
Why most of this is already tested. The turn-taking with the main loop, the queue, the fallbacks and the DMA stream programming are shared with H7, where they ran on the bench, the stream programming included (a 15-byte read through DMA, 716 000 samples, no error). What is new here is the SPI side: how F4 and F7 start and end a transfer with DMA.
What could still go wrong, and what a first test must look at:
Targets
Pins come from Betaflight's config for the same board, only where both configs agree on the gyro's CS pin and SPI bus. In a folder with several targets, only those Betaflight confirms get the pin.
Pins added (IMU 1, and IMU 2 where there is one):
GYRO_INT_EXTI; FLYWOOF745 (and NANO) PE1; FOXEERF745AIO_V3 PD0; GEPRC_F722_AIO (and _UART3) and GEPRCF722_BT_HD PA8; HAKRCF411D PA1; HUMMINGBIRD_FC305 PB6; IFLIGHT_BLITZ_F7_AIO PD0; KAKUTEF4 and KAKUTEF4V2 PC5 (not V23, V24); MATEKF405TE (and _SD) PC15Fixed, where INAV and Betaflight disagreed. INAV never read these pins, so a wrong value never showed; Betaflight uses its pins on every flight:
Already declared, not checked against Betaflight (no config there), and used with
ON: FLYDRAGONPRO PB3, HGLRCF722LITE PC4. AIKONF4V3, DAKEFPVF722X8 and KAKUTEF7MINIV3 also declared theirs, and they match Betaflight.Left out: ZEEZF7 and ZEEZF7V2, where Betaflight's pin is I2C3 SDA and the beeper in INAV; SPEEDYBEEF405WING, where Betaflight declares none; SPEEDYBEEF405AIO, where Betaflight's PE9 is on port E, which the INAV target does not enable; 54 targets with no Betaflight config to compare against.
Size
Against #12064:
The H7 and AT32 builds do not change. Built without warnings on all five.
Not tested, testing wanted
Two F7 boards have run this (see below); nothing has run on an F4, and I have not checked the ADC move on hardware. Please try it on a board from the lists above, props off first.
get gyro_data_readyshowsAUTO, the default.resourcelists the gyro's interrupt pin asMPU1 EXTI. If it does not, data-ready was not set up: no pin, a wrong pin, or no free DMA stream.set gyro_data_ready = OFFand please report it.tasks: the GYRO task average drops by several µs.GYRO_RAWandACC, board still and moving.A report of which board, which MCU, and what was checked is very welcome, even if everything simply works.
After review
GYRO_INT_EXTI, and Betaflight's), which my comparison script missed: it read a#definewithout a value as swallowing the next line. With that fixed, no pin added before changes.Built on F4, F7, H7, AT32 and SITL; KAKUTEF7 and KAKUTEF7HDV fit their ITCM. F7 has run on two boards (see below); F4 is untested on hardware.
Related PRs
Tested on more boards (2026-10-06)
Testing: the branch has maintenance-10.x merged in since e642af2, 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 (ICM-42688-P on SPI1, EXTI PC3), image merged on maintenance-10.x
f6579d2:
resourceshowsC03: MPU1 EXTI, GYRO task 12 -> 3 us average; IMU at rest acc (29, -4, 506) with 0.3 ofnoise, gyro 0 +-0.1; moved by hand 25 s, gravity propagated by the gyro vs the accelerometer 8.0 deg median with the
true signs, 16 to 77 deg with any axis flipped; blackbox at rest 103 s at 989 Hz with no iteration gap, and 431 s at
200 Hz with 21 s of motion (gyroRaw consecutive duplicates 3.8 %, |acc| 1.00 g). F4 still untested.
A second F7 the same day, a Diatone Mamba F722 2022B (ICM-42688-P on SPI1, EXTI PC4), image merged on maintenance-10.x:
resourceC04: MPU1 EXTI, GYRO task 12 -> 3 us average, IMU at rest acc (-100, -31, 511) noise 0.4, moved by hand 60 s with peaks of 477 to 574 deg/s and gyro-propagated gravity vs accelerometer 8.0 deg median (18 to 45 deg with an axis flipped), blackbox at rest 12.6 s at 990 Hz with no missing iteration.