rp2/rp2_psram: *Fully* switch to upstream hardware_psram.#19418
Open
Gadgetoid wants to merge 3 commits into
Open
rp2/rp2_psram: *Fully* switch to upstream hardware_psram.#19418Gadgetoid wants to merge 3 commits into
Gadgetoid wants to merge 3 commits into
Conversation
Required by the include-based linker script support that follows. Signed-off-by: Phil Howard <github@gadgetoid.com>
Pico SDK 2.3.0 makes its default linker script overridable via includes, so the port no longer needs to carry a full copy. Replace the monolithic memmap_mp_rp2040.ld and memmap_mp_rp2350.ld with memmap_mp_rp2.ld, which includes the SDK default, plus small override fragments under memmap_rp2/, memmap_rp2040/ and memmap_rp2350/ that supply only the MicroPython parts: the FLASH/FLASH_FS split, moving gc/vm/parse into RAM, and the GC heap and stack layout. Memory region boundaries are unchanged. Co-authored-by: Phil Howard <github@gadgetoid.com> Signed-off-by: Phil Howard <github@gadgetoid.com>
Pico SDK 2.3.0 provides a hardware_psram library that detects and initialises PSRAM during runtime_init. Use it instead of the port's hand-written rp2_psram.c. Boards that fit PSRAM set MICROPY_HW_ENABLE_PSRAM (and, where the pico-sdk board header does not already provide it, MICROPY_HW_PSRAM_CS_PIN) in their mpconfigboard.cmake. These gate the hardware_psram link and feed the SDK: where the board header configures a size, its chip-select and size are used as-is; otherwise the size is auto-detected on the configured chip-select. main.c asserts the configured chip-select matches the board header. The GC heap is sized from psram_get_size() and placed using the SDK's __psram_start__/__psram_end__ linker symbols. PSRAM QMI timing is re-tuned after clock changes; flash programming restores it via the SDK's CS1 setup callback. CMakeLists: Reconsile board header config with mpconfigboard.*. rp2/rp2_psram: Redundant, removed. rp2/boards: Config updated. rp2/modmachine: Reconfigure PSRAM on clock change. rp2/rp2_flash: Document that SDK implicitly restores PSRAM. Signed-off-by: Phil Howard <github@gadgetoid.com>
12fdb6a to
f52a077
Compare
|
Code size report: |
Contributor
Author
|
FWIW tested on a Pimoroni Pico LiPo 2: Note that the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19418 +/- ##
=======================================
Coverage 98.51% 98.51%
=======================================
Files 177 177
Lines 22927 22927
=======================================
Hits 22586 22586
Misses 341 341 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
This change is the more complete alternative to #19416
It builds on the idea that we should fully defer to the SDK for PSRAM bringup and configuration, and tries to handle MicroPython's downstream config where it has not yet been migrated to pico-sdk board header files.
Vendors should set the relevant PSRAM config in their boards header, regardless of whether this change (or the other one) lands in MicroPython. Several upstream headers for PSRAM boards already have 8MB enabled, see: https://github.com/search?q=repo%3Araspberrypi%2Fpico-sdk+PICO_PSRAM_SIZE_BYTES+path%3A%2F%5Esrc%5C%2Fboards%5C%2Finclude%5C%2Fboards%5C%2F%2F&type=code
I petitioned for upstream support for PSRAM in Pico SDK (raspberrypi/pico-sdk#2372) back when we first started the RP2350 bringup, it didn't arrive quickly enough for us to skip a downstream alternative but now it's here and we should switch to it.
Testing
As with #19416 I am only equipped to test this on Pimoroni boards.
Vendors, excuse me for the tag, these boards should also be tested:
You should test:
gc.mem_free()reports the correct gc_heap region (may include SRAM, will exclude a large chunk for GC tracking)machine.freq()changes (within reason) do not push PSRAM timings out of whack or baulk the boardFor the lazy I'm running verification with this mess: https://gist.github.com/Gadgetoid/4c86406f57995096c0aecab578a039f1
And probing clocks with: https://gist.github.com/Gadgetoid/e0673a3e1eaf7bef5f8557233122f4d3
Trade-offs and Alternatives
This change is the more complete alternative to #19416, touches more files and changes more things. It's probably the right approach, and lays the foundations for vendors to configure their boards upstream.
It still relies on
MICROPY_HW_ENABLE_PSRAMto opt-in to PSRAM support, but will defer to upstream'sPICO_PSRAM_SIZE_BYTESandPICO_PSRAM_CS_PINwhere available.When a CS pin is supplied and no
PICO_PSRAM_SIZE_BYTESis available, it will setPICO_AUTO_DETECT_PSRAM_SIZEand setsPICO_PSRAM_CS_PIN=MICROPY_HW_PSRAM_CS_PINwhich effectively recreates the previous behaviour.The biggest thrust of this change is the move from
mpconfigboard.htompconfigboard.cmakefor PSRAM config, this is necessary to support all the backwards-compatibility and mirrors config breaking changes like the move ofMICROPY_HW_FLASH_STORAGE_BYTESthat spicy downstream vendors (like meeee, aah) will just have to deal with.Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.