raspberrypi: derive QMI PSRAM timings from clk_sys - #11250
Merged
tannewt merged 3 commits intoAug 28, 2026
Conversation
Co-authored-by: Limor Fried <ladyada@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Derives RP2350 PSRAM QMI timings from clk_sys rather than fixed 133 MHz assumptions.
Changes:
- Reads the system clock before QMI direct mode.
- Calculates maximum select and minimum deselect timings dynamically.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Limor Fried <ladyada@users.noreply.github.com>
tannewt
requested changes
Aug 26, 2026
tannewt
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix! Please drop the common_hal_ prefix because this isn't an API that applies across ports. Most common_hal API should be setup in a bindings header.
Co-authored-by: Limor Fried <ladyada@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Derive the RP2350 QMI PSRAM timing fields from the actual
clk_sysfrequency at boot and whenevermicrocontroller.cpu.frequencychanges.Why
The existing QMI values encode absolute-time PSRAM requirements in clock cycles calculated for a 7.52 ns cycle. At the RP2350 port's 150 MHz clock, the fixed
MIN_DESELECTvalue becomes 46.7 ns, below the PSRAM's 50 ns minimum; higher clocks shorten it further.This belongs in the Raspberry Pi port because it programs the RP2350-specific QMI timing register.
MAX_SELECTtargets 7.5 us to leave margin below the 8 us ceiling, whileMIN_DESELECTrounds up so it stays at or above 50 ns. The calculation keeps kHz precision so valid fractional-MHz clocks remain safe.Forum report
Calculated timings
These values are calculated from the register settings; they are not hardware measurements.
clk_sysMAX_SELECTMIN_DESELECTFor comparison, the old fixed values give 46.7 ns at 150 MHz and 27.8 ns at 252 MHz.
Hardware tested
Not run on hardware; no Fruit Jam or other
CIRCUITPY_PSRAMdevice was connected. In particular, thegc.mem_free()regression check and runtime frequency-change test still need hardware confirmation.How I tested it
adafruit_fruit_jamsuccessfully: 919,152 bytes flash, 74,312 bytes RAM.firmware.elf: boot readsclk_sysbefore QMI direct-mode access; the timing updater is RAM-resident and has no function calls; the runtime path masks interrupts, changes the clock, updates QMI timing, and restores interrupts in that order.Scope
This PR only corrects QMI PSRAM timing across boot and runtime system-clock changes. The separate DVI vertical-back-porch issue mentioned in the forum discussion is deliberately excluded.
AI assistance
I used Codex from a detailed task prompt that identified the suspected fixed-clock timing bug, source area, timing formulas, expected clock table, build target, and forum report. The agent reviewed the implementation and pinned Pico SDK register definitions, built the Fruit Jam target, inspected the linked image for RAM safety and call ordering, and incorporated automated review feedback. No hardware test results were generated or inferred.