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/clocks_extra: Set VREG like the Pico SDK does: needed for 200 MHz.
Summary
The RP2040 now supports running at 200 MHz, but the datasheet says that speed requires an elevated core supply of 1.15 V. The SDK implements that in runtime_clocks_init, but we do not call that function because we override it in clocks_extra.c.
Testing
On a Pololu Zumo 2040 Robot (RP2 port), I read the RP2040 VSEL bitfield using the expression machine.mem32[0x40064000] >> 4 & 15. It was 11 (the default) before this patch and 12 after. Additional patches were needed to set the Zumo's speed to 200 MHz in the Pico SDK and to make Micropython respect the settings for the Zumo 2040 in the Pico SDK. Those patches were confirmed separately using machine.freq() and the RP2040 frequency counter.