Repository navigation
Conversation
bus_i2c_hal.c drives the F7 I2C through HAL_I2C_Mem_Read/Write and their helpers, about 3.6 KB on F722 targets that are at their flash limit. This file gives the same API with the same behaviour on the peripheral's registers: blocking transfers that poll the same flags the HAL polls, a NACK or bus error or I2C_TIMEOUT counted and answered with i2cInit() as before, a register transfer of zero bytes refused as the HAL refused it, the same bus unstick, and TIMINGR computed as bus_i2c_hal.c does (equal values for every speed at PCLK1 from 27 to 60 MHz). The blocking calls use no interrupts, as the HAL's didn't. H7 keeps bus_i2c_hal.c. Under USE_I2C_ASYNC, which iNavFlight#12063 defines, it also has the interrupt driven i2cReadAsync() and i2cAsyncState() that iNavFlight#12063 gives bus_i2c_hal.c, with the same rules, so the two can be merged in either order. Unlike the HAL, an error flag set together with the final STOPF fails the transfer instead of leaving it for the next one. A register write of 255 data bytes, one more than NBYTES can carry with the register byte, is refused; no driver writes more than a few.
|
ⓘ 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 QodoReplace F7 HAL I2C master with a register-based driver
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Busy buses trigger premature recovery
|
|
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 #12157 251 targets built. Find your board's
|
|
I would say that there is no reasson use HAL for H7 and use direct register for manipulating for F7. The code should be same for H7 as well. What I see what can be a litlle bit problematic is that this PR changes code for all I2c devices, and all I2c devices would have to be tested. It's a reasson I why close PR for I2C refactor and create I2C async core + and then each driver in extra PR. So far here are two PRs for I2C refactor :( #12063 and #12133 which do same, and plenty of PRs whith dependency. |
|
Agreed on the H7: its I2C is the same V2 peripheral, so the same file would cover it with its own clock inputs. I kept it to F7 because that is where the flash is short and because the PR is a stopgap, as the body says: the H7 binaries stay as they are and nothing has to be reverted there. If you would rather have one driver for both I will extend it. On #12063 and #12133: they overlap on the asynchronous read and #12133 is the general one. I am fine closing #12063 once #12133 is in, and this driver then takes #12133's API in register form, or F7 goes back to the HAL with it. |
This is meant as a stopgap for the F722 targets' flash until the non-blocking I2C of #12133 (issue #12100) lands. When it does, this driver either takes #12133's API in register form, or F7 goes back to
bus_i2c_hal.ctogether with it. Until then the F722 targets are within a few KB of their 480 KB (MATEKF722SE 98.6 % on maintenance-10.x), and every open PR that adds code to them competes for that space.bus_i2c_stm32f7xx.creplacesbus_i2c_hal.con F7 only. H7 keeps the HAL driver, and its binaries don't change. The API and the behaviour are the same:I2C_TIMEOUTover the whole transfer is counted in the I2C error counter and answered withi2cInit(), which unsticks the bus, as before; a register transfer of zero bytes is refused, asHAL_I2C_Mem_Read/Writerefused it;bus_i2c_hal.ccomputes it. I compiled the two functions side by side: equal at 100, 200, 400 and 800 kHz for PCLK1 from 27 to 60 MHz in 250 kHz steps (532 cases);Two differences, both on purpose: an error flag already set together with the final STOPF fails the transfer (the HAL returned success and left the NACK for the next transfer), and a register write of 255 data bytes, 256 with the register byte and one more than NBYTES can hold, is refused. No driver writes more than a few bytes.
With #12063 (barometer read without waiting on the bus): it defines
USE_I2C_ASYNCand givesbus_i2c_hal.can interrupt driveni2cReadAsync()/i2cAsyncState(). This file has the same two underUSE_I2C_ASYNC, with the same rules (a blocking transfer lets the read end first, a held bus or a stuck read fails and reinitialises the bus), so the two PRs can be merged in either order. On maintenance-10.x alone that part is not built. A test merge of the two builds on every target listed below, and against maintenance-10.x with #12063 it saves more, since #12063 adds the HAL's interrupt state machine: MAMBAF722_2022B -5544 B, MATEKF722 -5808 B, MATEKF722SE -5364 B, FLYWOOF722PRO -5560 B, KAKUTEF7 -6500 B, MATEKF765 -6824 B, and KAKUTEF7HDV -5880 B with its ITCM from 16384 of 16384 (full with #12063) back to 16232.Size against maintenance-10.x: