-
Notifications
You must be signed in to change notification settings - Fork 3
CPU only runs with ~6.5 MHz because we aren't initializing the clocks #7
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
Comments
Relevant quotes from the RP2040 datasheet:
And:
|
Turns out we can observe the different clock speeds on the oscilloscope. Let's write a tight infinite loop that toggles a GPIO pin as fast as possible: while true {
gpioSet(pin: led, high: true)
gpioSet(pin: led, high: false)
} Each call to Hooking up the oscilloscope to the GPIO pin, we see this when running with the default system clock after boot, i.e. without ramping up the clock speed: Note the scale (100 ns per division), so each instruction (each switch from high to low and vice versa represents one instruction) takes ~200 ns = ~5 Mhz. This roughly fits the ~6.5 MHz spec. Now the same code with the system clock properly initialized: Note the different scale (10 ns per division). My oscilloscope isn't fast enough to see the rectangle signal, but we can discern that it takes approximately 10 ns per instruction = ~100 MHz, qed. Interesting tidbit: the ripple on the left side of the graph is the jump back to the start of the loop, which takes longer because branches take 2 cycles on arm6m (I think). Naively, we would expect on such ripple after each high/low cycle because that's how we wrote the code. But it turns out the compiler is unrolling our infinite loop, putting 4 high/low cycles into a single loop iterations. Nice! |
Uh oh!
There was an error while loading. Please reload this page.
I have only added the absolute minimum amount of post-boot init code that’s required to talk to the GPIOs so far. As a consequence, the CPU runs only at ~6.5 MHz, which is the frequency the RP2040 gets from its on-chip ring oscillator by default on boot.
To ramp up the clock speed to 125 MHz, we need to switch the system clock to the external crystal oscillator (XOSC) and PLLs.
You can sort of observe the slow clock speed when you flash the Pico without disconnecting it from power, e.g. via picoprobe/the RPi Debug Probe:
Result: the LED will blink very fast because the correct program from step 1 performed the required steps to ramp up the CPU frequency, and this config survives a soft reset (not sure if it survives all types of resets, but it works this way with whatever type of reset
probe_rs
performs by default).I'm working on a fix.
The text was updated successfully, but these errors were encountered: