-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
fix: solve the problem that the flash clock frequency is too high and… #17374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You can get more information through this issue: #17375 |
Code size report:
|
042433c
to
ae80654
Compare
Signed-off-by: Lesords <lesords168@gmail.com>
Forgive me for making so many changes, all to get past the commit format checking |
From the code comments it seems this is an issue with Winbond external SPI flash. If different manufacturers use Flash chips with different maximum clock rates should this be a board-specific build option? |
You can check this issue:#17375 Previously, PICO could modify the flash clock frequency based on this macro PICO_FLASH_SPI_CLKDIV |
Before this commit 91cff8e, everything was working fine. |
Looks like the linked commit - which entered the codebase via the PSRAM changes IIRC - does indeed ignore The normal flash speed is Looks like the formula should be something like Ideally it would be Pico SDK is weird in that I suggest we make this value a board configuration option that defaults to -- Edit: Sorry RP2040's clocks are 125MHz or 200MHz: https://github.com/raspberrypi/pico-sdk/blob/ee68c78d0afae2b69c03ae1a72bf5cc267a2d94c/src/rp2040/hardware_regs/include/hardware/platform_defs.h#L76-L80 (afaik there's no accounting for flash divider here?) And RP2350 is 150MHz. |
I think a cleaner approach would be something like: // Use the minimum divisor assuming a 133MHz flash.
#ifdef WAVESHARE_RP2350_ZERO
const int max_flash_freq = 60000000;
#else
const int max_flash_freq = 133000000;
#endif Then we would just add boards to #ifdef WAVESHARE_RP2350_ZERO And whenever we add a board that is officially supported by
|
Nvm, something better, assuming // Use the minimum divisor assuming a 133MHz flash.
const int max_flash_freq = 133000000;
int divisor = (clock_hz + max_flash_freq - 1) / max_flash_freq;
// For boards with PICO_FLASH_SPI_CLKDIV = 3
#if PICO_FLASH_SPI_CLKDIV == 3
divisor++;
#endif
// For boards with PICO_FLASH_SPI_CLKDIV = 4
#if PICO_FLASH_SPI_CLKDIV == 4
divisor += 2;
#endif or a little harder to read, but more future proof // Use the minimum divisor assuming a 133MHz flash.
const int max_flash_freq = 133000000;
int divisor = (clock_hz + max_flash_freq - 1) / max_flash_freq + PICO_FLASH_SPI_CLKDIV - 2; This should cover all future problems with other vendors boards, if |
This definitely needs to be fixed. It looks like
Yes, I think this is the right approach. So a board would define something like: #define MICROPY_HW_SPIFLASH_MAX_FREQ (133000000) and it would default to: #ifndef MICROPY_HW_SPIFLASH_MAX_FREQ
#if PICO_RP2040
#define MICROPY_HW_SPIFLASH_MAX_FREQ (125000000 / PICO_FLASH_SPI_CLKDIV)
#else
#define MICROPY_HW_SPIFLASH_MAX_FREQ (150000000 / PICO_FLASH_SPI_CLKDIV)
#endif
#endif |
Basically what I've done here: #17389
|
Ah, sorry, I missed that! Let's close this PR then, in favour of that one. |
No worries, if you're coming up with basically the same fix then I can't have gone far wrong... y'know apart from adopting the change that broke this in the first place 😆 |
Haha, indeed! |
Summary
Reduce the flash clock frequency to avoid the problem of XIAO RP2350 not responding and having no serial port after flashing the firmware.
Testing
Tested on XIAO RP2350