Pico Micropython overclocked twice (250MHz) works fine

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
HermannSW
Posts: 145
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Pico Micropython overclocked twice (250MHz) works fine

Post by HermannSW » Thu Feb 18, 2021 8:57 pm

Pico is rated 133MHz, running at default 125MHz system clock.
I have tested my three Picos, and all allow for >420MHz overclocking (running with 1.3V).
I tested that USB works fine up to 250MHz, at default voltage of 1.1V.
So I added small piece of code to soft reboot part of ports/rp2/main.c.
It switches to 250MHz and initializes uart (again).
Now USB, I2C as well as UART work without issues, details in this forum thread:
https://www.raspberrypi.org/forums/view ... 6&t=304360

For just playing with the change without having to build yourself, .uf2 is available:
https://stamm-wilbrandt.de/en/forum/firmware.250MHZ.uf2

This is short demo of switching to 250MHz via soft reboot.
Before switching timestamp diff is roughly 20us, after it is 10us:
Image


P.S:
Just measured Pico Micropython current with constant voltage power supply.

In REPL doing nothing: 18mA
Running blink switches between 18mA and 19mA.

Then I did soft reboot to switch to 250MHz, and that had an effect:

In REPL doing nothing: 31mA
Running blink switches between 31mA and 32mA.

shaoziyang
Posts: 353
Joined: Sun Apr 17, 2016 1:55 pm

Re: Pico Micropython overclocked twice (250MHz) works fine

Post by shaoziyang » Fri Feb 19, 2021 2:23 pm

Yes, it really works, the calculation time of PI is reduced by almost half.

Code: Select all

import gc
from utime import ticks_ms, ticks_diff
 
def pi(places=100):
  # 3 + 3*(1/24) + 3*(1/24)*(9/80) + 3*(1/24)*(9/80)*(25/168)
  # The numerators 1, 9, 25, ... are given by (2x + 1) ^ 2
  # The denominators 24, 80, 168 are given by (16x^2 -24x + 8)
  extra = 8
  one = 10 ** (places+extra)
  t, c, n, na, d, da = 3*one, 3*one, 1, 0, 0, 24
 
  while t > 1: 
    n, na, d, da = n+na, na+8, d+da, da+32
    t = t * n // d
    c += t
  return c // (10 ** extra)
 
def pi_t(n=1000):
    gc.collect()
    t1 = ticks_ms()
    pi(n)
    t2 = ticks_ms()
    print('  ', ticks_diff(t2, t1), 'ms')
 
for i in (100, 500, 1000, 5000, 10000):
    try:
        print('\nCalc {} bits pi'.format(i))
        pi_t(i)
    except:
        print('Calc error!')

User avatar
Roberthh
Posts: 2454
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pico Micropython overclocked twice (250MHz) works fine

Post by Roberthh » Fri Feb 19, 2021 6:14 pm

It works, but to the output is distorted in my tests. So practically not always useful. But it should be exposed via machine.freq.

User avatar
Roberthh
Posts: 2454
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pico Micropython overclocked twice (250MHz) works fine

Post by Roberthh » Fri Feb 19, 2021 8:14 pm

For everyone who is interested, here is a modified machine.freq() code, to replace the sections in modmachine.c.

Code: Select all

#include "pico/stdlib.h"

STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
    if (n_args == 0) {
        // get
        return MP_OBJ_NEW_SMALL_INT(clock_get_hz(clk_sys));
    } else {
        // set
        mp_int_t freq = mp_obj_get_int(args[0]);
        if (set_sys_clock_khz(freq / 1000, false)) {
            return mp_const_none;
        } else {
            mp_raise_ValueError("valid range 10-270MHz");
        }
    }
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
The additional # include would typically sit in the include section at the file head.
You can set higher and lower frequencies. I tried 270Mhz, 250MHz, 150MHz, 80MHz, 40MHz, 20MHz, 10MHz. In all cases, USB worked fine. Whether higher frequency work is not clear. Sometimes I get an error, sometimes the board is silent. At 250MHz I tried a PIO example which toggles a PIN, and I could get a 125MHz square-about signal. It seems that the I/O driver is at it's limit for that frequency. The same for 270MHz and 10 MHz.
P.S.: The level at the pin is about 3Vpp. I used a 470/56 ohm resistor divider into a 50 Ohm cable cable to pick up the signal, to have a 50Ohm source and no ringing. Together with the 50 Ohm of the cable, that scales down the level by about 20.
Attachments
125Mhz_toggle.png
125Mhz_toggle.png (40.85 KiB) Viewed 231 times

Georgeskingv
Posts: 3
Joined: Mon Feb 22, 2021 4:48 pm

Re: Pico Micropython overclocked twice (250MHz) works fine

Post by Georgeskingv » Mon Feb 22, 2021 4:51 pm

Hi,

Can we change the clock frequency from a micropython program ?
Like machine.freq(125000000)

Best regards

Georges

User avatar
Roberthh
Posts: 2454
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Pico Micropython overclocked twice (250MHz) works fine

Post by Roberthh » Mon Feb 22, 2021 7:00 pm

I made a PR for that. Eventually it will be included.
See: https://github.com/micropython/micropython/pull/6941

Post Reply