User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Pico Micropython overclocked twice (250MHz) works fine

Wed Feb 17, 2021 8:56 am

Currently change to 250MHz happens on soft reboot, allows for comparion to running with default 125MHz system clock.
More details on how to build yourself, as well as prebuild firmware image to try out here:
viewtopic.php?f=145&t=304309&p=1821617#p1821617

Code: Select all

>>> 
MPY: soft reboot
system clock now is 250MHz
MicroPython de1239b6a-dirty on 2021-02-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.                                            
>>> 
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Thu Feb 18, 2021 2:11 am

I did add REPL over UART by building Micropython as described in doc:
https://datasheets.raspberrypi.org/pico ... df#page=10

Minicom works fine on /dev/serial0.
But when I press CTRL-D for soft reboot, and Micropython switches to 250MHz, minicom I/O does not work anymore.
Only unreadable characters appear, and command input to REPL does not work anymore:

Code: Select all

pðpppð

So while Micropython@250MHz works fine over USB and can drive I2C display fine, UART does not work,
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

nollkolltroll
Posts: 2
Joined: Fri Feb 12, 2021 7:07 am

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

Thu Feb 18, 2021 5:24 am

A guess is that the UART-code is unaware of the overclocking, thus setting a baudrate twice the one requested. Easy to check if you can change baudrate on the terminal program to twice expected.
/NollKollTroll

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Thu Feb 18, 2021 8:41 am

nollkolltroll wrote:
Thu Feb 18, 2021 5:24 am
A guess is that the UART-code is unaware of the overclocking, thus setting a baudrate twice the one requested. Easy to check if you can change baudrate on the terminal program to twice expected.
Good idea, but does not work.
I started minicom over UART to see there is REPL:

Code: Select all

$ minicom -b 115200 -o -D /dev/serial0

After pressing CTRL-D I see wrong characters:

Code: Select all

pðpppð

Then I pressed CTRL-A Q ENTER to leave minicom, and started minicom again with double baudrate:

Code: Select all

$ minicom -b 230400 -o -D /dev/serial0

I/O (REPL) does not work, although minicom states it runs at 230400 with CTRL-A P:

Code: Select all

Welcome to minicom 2.7.1

OPTIONS: I18n         +---------[Comm Parameters]----------+
Compiled on Aug 13 201|                                    |
Port /dev/serial0, 09:|     Current: 230400 8N1            |
                      | Speed            Parity      Data  |
Press CTRL-A Z for hel| A: <next>        L: None     S: 5  |
                      | B: <prev>        M: Even     T: 6  |
                      | C:   9600        N: Odd      U: 7  |
                      | D:  38400        O: Mark     V: 8  |
                      | E: 115200        P: Space          |
                      |                                    |
                      | Stopbits                           |
                      | W: 1             Q: 8-N-1          |
                      | X: 2             R: 7-E-1          |
                      |                                    |
                      |                                    |
                      | Choice, or <Enter> to exit?        |
                      +------------------------------------+



CTRL-A Z for help | 230400 8N1 | NOR | Minicom 2.7.1 | VT102 | Offline | erial0
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

cleverca22
Posts: 3588
Joined: Sat Aug 18, 2012 2:33 pm

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

Thu Feb 18, 2021 8:42 am

Code: Select all

int set_sysclk(int argc, const console_cmd_args *argv) {
  dump_ssi_state();
  if (argc != 2) {
    printf("usage: sysclock 133 (mhz)\n");
    return -1;
  }
  if (set_sys_clock_khz(argv[1].u * 1000, false)) {
    uart_init(uart0, 1000000);
    puts("success");
    return 0;
  } else {
    puts("failure");
    return -2;
  }
}
yeah, when i was messing with the clock, i had to re-call the uart_init to repair the divider ratios

Code: Select all

[clever@amd-nixos:~/apps/rpi/pico/pico-sdk]$ git grep uart_init
src/host/hardware_uart/include/hardware/uart.h:uint uart_init(uart_inst_t *uart, uint baudrate);
also of use, all 3 of pico, ftdi, and pi400 (ttyS0) are capable of 1,000,000 baud without any issues

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Thu Feb 18, 2021 9:25 am

@cleverca Thanks, I just needed to reinitialize UART to make it work at 250MHz!

This is the small "enable 250MHz on soft reboot with working UART" diff:

Code: Select all

diff --git a/ports/rp2/main.c b/ports/rp2/main.c
index 0acab6735..ebbfe93b7 100644
--- a/ports/rp2/main.c
+++ b/ports/rp2/main.c
@@ -105,6 +105,18 @@ int main(int argc, char **argv) {
         machine_pin_deinit();
         gc_sweep_all();
         mp_deinit();
+
+        if (!set_sys_clock_khz(250000, false))
+            mp_printf(MP_PYTHON_PRINTER, "250MHz system clock failed\n");

Code: Select all

+        else
+        {
+            #if MICROPY_HW_ENABLE_UART_REPL
+            setup_default_uart();
+            mp_uart_init();
+            #endif
+
+            mp_printf(MP_PYTHON_PRINTER, "system clock now is 250MHz\n");
+        }
     }
 
     return 0;

And this is minicom with default 115200 baudrate in action @250MHz after pressing CTRL-D:

Code: Select all

Press CTRL-A Z for help on special keys


>>> 
MPY: soft reboot
system clock now is 250MHz
MicroPython de1239b6a-dirty on 2021-02-18; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> 
>>> 

Summary, 250MHz Pico Micropython works fine with:
  • USB
  • I2C
  • UART

P.S:
In case someone wants to just play with the diff without building, newly created 250MHz MP firmware is here:
https://stamm-wilbrandt.de/en/forum/firmware.250MHZ.uf2
Peek_2021-02-18_10-59.gif
Peek_2021-02-18_10-59.gif
Peek_2021-02-18_10-59.gif (46.99 KiB) Viewed 968 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Thu Feb 18, 2021 12:32 pm

Just verified that minicom over USB and UART do work concurrently.
And found a nice way to "see" the system clock to 250MHz change.
I utilized difference between two successive "time.ticks_us()" calls.
Difference is roughly 20us at 125MHz, and only 10us at 250MHz:
Peek_2021-02-18_13-40.gif
Peek_2021-02-18_13-40.gif
Peek_2021-02-18_13-40.gif (244.54 KiB) Viewed 933 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Thu Feb 18, 2021 9:51 pm

Just measured Pico Micropython current with constant voltage power supply:
viewtopic.php?f=144&t=304442&p=1822735#p1822735

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.


TIL: "overclocking does cost current"
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

blimpyway
Posts: 617
Joined: Mon Mar 19, 2018 1:18 pm

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

Fri Feb 19, 2021 11:56 am

H Hermann, can you please measure current while busy in python, eg:

Code: Select all

while True:
    pass


With 2 cores @ 250MHz it should compete with ESPs

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Sun Feb 21, 2021 9:36 pm

blimpyway wrote:
Fri Feb 19, 2021 11:56 am
H Hermann, can you please measure current while busy in python, eg:

Code: Select all

while True:
    pass


With 2 cores @ 250MHz it should compete with ESPs
One Pico now is attached to breadboard, and has I2C 128x64 display with os.dupterm(oled) REPL on I2C display:
viewtopic.php?f=146&t=304410&p=1824430#p1824430
20210221_221653.15%.jpg
20210221_221653.15%.jpg
20210221_221653.15%.jpg (62.49 KiB) Viewed 755 times

The first steps needed to eliminate OLED effect on measurents was to remove REPL from I2C display and clear display:

Code: Select all

>>> os.dupterm(None)
<FBConsole object at 20008290>
>>> oled.fill(0), oled.show()
(None, None)
>>>

With that current is 18mA, as reported before.
With "while True:" loop current increased to 21mA.
After soft reboot with switching to 250MHz and repeating above steps to eliminate OLED display effect, measured current was 31mA as reported before. With "while True:" loop current increased to 36mA.

Summary:
"while True:" loop does cost 3mA at 125MHz, and 5mA at 250MHz.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html


User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Tue Feb 23, 2021 9:06 am

I found a basic C SDK ili9341 320x240 display library that works for the Pico:
viewtopic.php?f=144&t=304442&p=1824485#p1824485
Is there a special ili9341 library needed for Pico, or can I take any like the Adafruit library for Pico Micropython?
Image
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4018
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

Thu Mar 04, 2021 11:46 pm

Pico Micropython frequency change will become available as "machine.freq(...)" soon with @roberthh's pull request:
https://forum.micropython.org/viewtopic ... 705#p55312

I built myself, measured with consecutive microsecond timestamp differences (10/125/250MHz):

Code: Select all

Type "help()" for more information.                                             
>>> import machine, time                                                        
>>> tus=time.ticks_us                                                           
>>> machine.freq(10000000)                                                      
>>> print(-tus()+tus(),-tus()+tus(),-tus()+tus(),-tus()+tus(),-tus()+tus())     
188 73 73 73 72                                                                 
>>> machine.freq(125000000)                                                     
>>> print(-tus()+tus(),-tus()+tus(),-tus()+tus(),-tus()+tus(),-tus()+tus())     
10 6 6 5 5                                                                      
>>> machine.freq(250000000)                                                     
>>> print(-tus()+tus(),-tus()+tus(),-tus()+tus(),-tus()+tus(),-tus()+tus())     
4 3 3 3 3                                                                       
>>> 
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

3ym3ym
Posts: 3
Joined: Tue Nov 20, 2012 11:42 pm

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

Sun May 02, 2021 8:12 pm

machine.freq works fine in the 2021-04-18 build of MicroPython.
I tried up to 250MHz.

Return to “MicroPython”