Skip to content

fix(gust): adc-thin strict single-shot on F1 — SWSTART needs EXTTRIG+EXTSEL (gale#216) - #221

Merged
avrabe merged 2 commits into
mainfrom
feat/adc-singleshot
Jul 23, 2026
Merged

fix(gust): adc-thin strict single-shot on F1 — SWSTART needs EXTTRIG+EXTSEL (gale#216)#221
avrabe merged 2 commits into
mainfrom
feat/adc-singleshot

Conversation

@avrabe

@avrabe avrabe commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What

Closes gale#216. Makes the dissolved adc-thin driver a strict single-shot on real STM32F1, and fixes a latent bug that silicon exposed along the way.

The story (silicon-driven)

gale#216 asked to remove the "double-ADON": the driver wrote CR2=ADON in both adc_enable and adc_configure, and on F1 an ADON-write-while-ADON=1 restarts a conversion, so adc_configure kicked an extra conversion.

Dropping adc_configure's CR2 write alone HUNG the F100 read (kill-criterion). A diagnostic build showed why: right after adc_start, SR = 0x0STRT=0, the conversion never started. On F1 the SWSTART bit is ignored unless EXTTRIG=1 (bit 20) and EXTSEL=111 (SWSTART source, bits 19:17) are also set — which the driver never did. The old code only ever worked because adc_configure's ADON-rewrite was the de-facto trigger; adc_start's SWSTART was decorative.

Fix (two parts)

  1. adc_configure no longer touches CR2 (drops the stray ADON-restart; CR2 stays ADON from adc_enable). Its now-unused cr2_extra param removed; the 3 callers updated.
  2. adc_start writes ADON | EXTTRIG | EXTSEL(SWSTART) | SWSTART | cr2_extra (CR2 = 0x5E0001) so the software trigger actually fires — exactly one conversion.

Oracles (grounded)

  • Real F100 silicon: re-flashed → Vrefint = 1645 raw, VDDA ≈ 2987 mV, EOC cleared=true — a true single conversion via one SWSTART (matches the earlier 1646, now clean).
  • Diagnostic (the proof of the root cause): pre-fix SR=0x0 after start (STRT=0); post-fix STRT/EOC set, DR valid.
  • Kani 7/7 — the pure FSM is untouched; only the C-ABI wrapper register writes changed.
  • qemu probe adc-probe ALL OK with adc-start ok: CR2=…=0x5e0001 and adc-config ok: CR2=ADON (configure no longer writes it).
  • Renode gate gust_adc start assertion updated to the new CR2 value.
  • .o regenerated on synth 0.49.0 (.text 740 B, 0-SRAM).

Kill-criterion

If the F100 read hangs or returns a raw outside the Vrefint band, adc_start isn't triggering — the exact failure this fix resolves.

🤖 Generated with Claude Code

avrabe and others added 2 commits July 23, 2026 19:21
…adc_configure (gale#216)

adc_configure no longer writes CR2; ADON is set once by adc_enable and stays
set, so a repeated ADON-write-while-on (which can trigger a spurious ch17
conversion on real STM32F1) is gone. adc_configure drops its now-unused
cr2_extra param (dead once CR2 is untouched); the 3 callers (gust_adc,
gust_adc_probe, gust_adc_silicon) drop the 4th arg. Regenerated
adc-thin-cm3.o with synth 0.49.0 / loom 1.2.0 (.text 772 -> 740 bytes).

Pure FSM + Kani harnesses untouched: cargo kani 7/7 SUCCESSFUL. qemu
gust_adc_probe still reports "adc-probe ALL OK" (cr2_2 == CR2_ADON holds,
now carried from adc_enable rather than re-written by configure).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011QG86sovTbfnPNY9SfhSmo
…le-shot confirmed on silicon (gale#216)

Silicon caught that dropping adc_configure's CR2=ADON write (prev commit) HUNG the
F100 read: a diagnostic showed SR.STRT=0 after adc_start — on F1 the SWSTART bit is
ignored unless EXTTRIG(bit20)=1 + EXTSEL(bits19:17)=111 (SWSTART source) are set,
which the driver never did. The old code only 'worked' because adc_configure's
ADON-rewrite was the de-facto trigger (ADON-write-while-on restarts a conversion).

Fix: adc_start now writes ADON|EXTTRIG|EXTSEL(SWSTART)|SWSTART (CR2=0x5E0001) so the
software trigger actually fires — one conversion, true single-shot. Re-flashed F100:
Vrefint=1645 raw, VDDA~2987mV, EOC cleared. Kani 7/7 (pure FSM untouched); qemu probe
+ Renode gust_adc gate updated to the new start CR2 value; .o regenerated (synth 0.49).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@avrabe
avrabe merged commit 7a35afb into main Jul 23, 2026
68 of 70 checks passed
@avrabe
avrabe deleted the feat/adc-singleshot branch July 23, 2026 18:18
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