Skip to content

Clear the H7 ADC buffer at init - #12123

Open
MrScothh wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
MrScothh:fix/h7-adc-clear
Open

MrScothh wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
MrScothh:fix/h7-adc-clear

Conversation

@MrScothh

@MrScothh MrScothh commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

On H7 adcValues sits in DMA_RAM, a NOLOAD section in D2 SRAM that is never zeroed. If the ADC or its DMA does not
start (any of the early returns in adcInstanceInit()), battery voltage, current, RSSI and airspeed are computed from
whatever that RAM held: the previous boot's readings after a soft reset, random values after a power-up. They now
read 0. #12119, which moves the F7 buffer into DMA_RAM, clears it the same way.

Tested

On a KAKUTEH7MINI, with a test-only build (not in this PR) that skips HAL_ADC_Start_DMA() for one soft reset and
prints the buffer in status:

maintenance-10.x this PR
normal boot readings same readings
boot with the DMA start skipped previous boot's readings, 120 of 140 samples non-zero 0 of 140 samples non-zero

Size

Target Flash
KAKUTEH7MINI, KAKUTEH7, MATEKH743, TBS_LUCID_H7, AEDROXH7 +16 B each

adcValues is in DMA_RAM, which on H7 is a NOLOAD section that startup does
not zero. adcInstanceInit() returns early if the ADC or its DMA fails to
start, after the channels were marked enabled, so adcGetChannel() then
returned whatever the RAM held instead of 0: random battery voltage and
current. Clear the buffer before the ADC starts, as iNavFlight#12119 does on F7.
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Clear the H7 ADC buffer before initialization

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Clear H7 ADC samples before initialization because startup does not zero DMA_RAM.
• Failed ADC or DMA startup now leaves channel readings at zero instead of stale values.
Diagram

graph TD
  INIT["H7 ADC init"] --> CLEAR["Clear DMA buffer"] --> START{"ADC DMA starts?"} -->|Yes| SAMPLES["DMA writes samples"] --> READ["Channel readings"]
  START -->|No| ZERO["Zeroed samples"] --> READ
Loading
High-Level Assessment

Clearing each buffer at instance initialization is appropriate: it covers early failures without changing startup handling for the entire NOLOAD DMA_RAM section. The reported soft-reset test supports the intended behavior; no test code is included in the PR.

Files changed (1) +3 / -0

Bug fix (1) +3 / -0
adc_stm32h7xx.cZero H7 ADC samples before peripheral setup +3/-0

Zero H7 ADC samples before peripheral setup

• Clears the selected ADC instance's sample buffer before any initialization step can return early. This prevents stale or uninitialized DMA_RAM contents from appearing as channel readings when ADC or DMA startup fails.

src/main/drivers/adc_stm32h7xx.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can route each severity your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

RAM / Flash usage vs. base commit e87050f — commit fa985de

Using the nearest available size baseline — the PR's exact base commit has no stored baseline yet.

Target Flash Δ RAM Δ
MATEKF405 -32 B (-0.00%) CCM: ±0 B (±0.00%)
RAM: +8 B (+0.01%)
MATEKF722 +56 B (+0.01%) ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
TCM: ±0 B (±0.00%)
MATEKF765 +104 B (+0.01%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: ±0 B (±0.00%)
MATEKH743 +48 B (+0.01%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)

See RAM/flash optimization guide for techniques to reduce usage.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Test firmware build ready — commit fa985de

Download firmware for PR #12123

251 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

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.

1 participant