Repository navigation
Conversation
RP2350 stage 2 is generated from boot_stage2/RP2350.c.jinja, but it has never run, because RP2350 builds don't set PICO_EMBED_XIP_SETUP. Fix it before turning it on: - The read that puts the flash into continuous-read mode wasn't volatile, so the compiler dropped it. Every flash read after stage 2 then failed. - All the data pads were set from SD0's settings, which dropped the SD2/SD3 (WP#/HOLD#) pull-ups. Clear only each pad's Schmitt trigger bit instead. - Use a slow clock divider (8) and a late sample delay (6), so stage 2's own reads are safe at any system clock. It reruns after every flash erase or program. - Always use the 0xeb quad read. Datasheets rate 0xeb, but often give no separate rating for 0xe7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without stage 2, RP2350 boards read flash with the boot ROM's settings: clock divider 3 (50 MHz at 150 MHz) and no continuous-read mode. - Set PICO_EMBED_XIP_SETUP, so crt0 runs stage 2 at boot and copies it to boot RAM. The SDK then reruns it after each flash erase or program. - Pad RP2350 stage 2 with the SDK's RP2350 pad script, which adds no checksum and defines __boot2_entry_point. - Add a .boot2 section to link-rp2350.ld. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RP2350 flash timing never changed with the system clock. Overclocking pushed the flash past its rating, and underclocking left it slow. Each flash erase or program also reset the timing. - gen_stage2.py writes the worst-case read timing of the board's flash devices, from data/nvm.toml, into flash_info.h. - mcu_processor_update_flash_timing() picks the smallest clock divider within the flash's 0xeb rating whose sample point meets the flash's setup and hold times, assuming the RP2350's worst-case pad delays. - common_hal_mcu_processor_set_frequency() uses the timing for the faster clock while the clock changes. - supervisor_flash_post_write() restores the timing after each flash erase, program or command. - A board can set a lower limit with CIRCUITPY_FLASH_MAX_SCK_HZ. At 150 MHz, boards with Winbond or GigaDevice flash now read it at 75 MHz instead of 50, with continuous-read mode. A Python workload runs 22% faster on a Pico 2. Boards with Puya flash, which has a 0 ns output hold time, stay at 50 MHz. Update data/nvm.toml for the new read timing fields. Requires adafruit/nvm.toml#26. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RP2040 stage 2 sets a fixed flash clock divider of 4, so flash reads ran at 31.25 MHz at the default 125 MHz system clock. Now, as on RP2350, CircuitPython sets the flash timing after stage 2, after each clock change, and after each flash erase or program. RP2040 uses the smallest even divider that keeps the flash clock at or below the flash's 0xeb rating, 62.5 MHz, and CIRCUITPY_FLASH_MAX_SCK_HZ if set. The sample delay stays at 1. The RP2040 datasheet gives no QSPI pad delays, so the RP2350 timing calculation can't be used. Stage 2 now uses the 0xeb quad read on both chips, because the datasheet timing is rated for 0xeb. Python code runs about 22% faster on a Feather RP2040 at 125 MHz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Exploring that issue brought up a whole host of interesting stuff, including the speedup below.
Code and testing by Claude, with review by @dhalbert.
Draft for now: requires adafruit/nvm.toml#26, which adds flash read timing values to
data/nvm.toml. The submodule points at that PR's branch now. I'll update the submodule when that PR is merged.Speedup: after this PR is merged, common RP2040 and RP2350 boards like the Pi Picos and the Adafruit boards will run Python code faster at the default CPU frequency: about 22% faster on RP2350 and about 28% faster on RP2040.
Issues
microcontroller.cpu.frequency. On RP2040, stage 2 set a fixed divider of 4: a 31.25 MHz flash clock at 125 MHz.Fix
PICO_EMBED_XIP_SETUP). The pico-sdk reruns it after each flash erase or program, so it was made safe to rerun:volatile. Without it, the compiler removed the read, and all later flash reads failed.data/nvm.toml. It uses the safest values across the board's listed flash chips. It also considers the RP2350 QSPI pad delays (RP2350 datasheet, Table 1291). It does not identify the flash chip at run time. For current boards, that would not change any flash clock.CIRCUITPY_FLASH_MAX_SCK_HZinmpconfigboard.h.0xebquad read on both chips, because the datasheet timing is rated for0xeb. Seven RP2040 boards used0xe7before.0xe7has 2 fewer dummy clocks, so it could be a few percent faster at the same flash clock, but datasheets often give no clock rating for it. The seven former0xe7boards still get faster overall, because their flash clock doubles.Results
Python benchmark time at the default system clock:
Tested on Pico 2, Pico 2 W (with Wi-Fi), Fruit Jam (with PSRAM), Feather RP2350, Feather RP2040 and Pico, from 48 to 300 MHz, including flash writes at high clocks.
On RP2040, 150 MHz is now slower than 125 MHz, because 150 MHz needs divider 4 to stay at or below 62.5 MHz. MicroPython chooses the same divider. The
frequencydocumentation now notes this.Lowering the clock can crash some RP2350 boards. That's not caused by this PR: it was already happening on
main.See in #11882.