RP2: Overclock or CPU_MHZ as a board config option
For PicoSystem we shipped a port of MicroPython that clocks the RP2040 to 250MHz at 1.2v (up from the stock 133MHz 1.1v settings) and have (short of needing to apply the slight overvolt in response to some units not being stable) generally seen these settings to be stable and safe. I accomplished this by maintaining a fork full of hacks where I've modified main.c :grimacing:
Many RP2040-based projects leveraging MicroPython could probably benefit from this same overclock, particularly if the manufacturers are happy to support boards at these speeds.
As such I'd like to propose a board config approach to setting CPU frequency and overvolt, with a view to supporting this in the RP2 port at first and perhaps expanding to other boards (we've encountered MCUs that are ostensibly one speed, but get a manufacturer certified OC frequency later).
This is part of a multi-step process to untie all the hacks I needed to implement for PicoSystem, justify their existence and bring them upstream for the benefit of everyone.
It also seems a shame to leave that 2x+ speedup on the table.
- What settings are common across MCUs for achieving overclock? I guess CPU_FREQ and VOLTAGE perhaps, but the latter could be derived from the former in most cases
- Is there anywhere in the MicroPython codebase where assumptions are made about CPU frequency that this would horribly break?
- Would it be appropriate to configure an "Overclocked Pico" board variant, for those who want to opt in to more performance?
rp2/modmachine: Do not use deprecated XOSC_MHZ.
Summary
I replaced the crystal on a W5500_EVB_PICO board by a custom clock source which is not 12 MHz. Therefore I need to configure the SYS and USB PLL with custom dividers. The script vcocalc.py is used to calculate the needed values and to generate the compiler definitions that need to be added to cmake.
But when using such custom defines the XOSC_MHZ is not defined and the build fails.
Testing
I tested this change while compiling for a W5500_EVB_PICO board with custom PLL settings as described above.