diff options
| author | 1-rafael-1 <[email protected]> | 2025-05-01 00:11:56 +0200 |
|---|---|---|
| committer | 1-rafael-1 <[email protected]> | 2025-05-01 00:11:56 +0200 |
| commit | 22b5f73811a7cc0dbca920e02b5d001d252d344c (patch) | |
| tree | d3fd2d801ffddc74a43f04c7892c953356647904 /examples/rp/src/bin/overclock_manual.rs | |
| parent | d44b94523576d3f8c1f586811f600eb3ba223606 (diff) | |
add manual overclock example, finalize API, cleanup
Diffstat (limited to 'examples/rp/src/bin/overclock_manual.rs')
| -rw-r--r-- | examples/rp/src/bin/overclock_manual.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/examples/rp/src/bin/overclock_manual.rs b/examples/rp/src/bin/overclock_manual.rs new file mode 100644 index 000000000..ad6abf0e7 --- /dev/null +++ b/examples/rp/src/bin/overclock_manual.rs | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | //! # Overclocking the RP2040 to 200 MHz manually | ||
| 2 | //! | ||
| 3 | //! This example demonstrates how to manually configure the RP2040 to run at 200 MHz. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_rp::clocks; | ||
| 11 | use embassy_rp::clocks::{ClockConfig, PllConfig, VoltageScale}; | ||
| 12 | use embassy_rp::config::Config; | ||
| 13 | use embassy_rp::gpio::{Level, Output}; | ||
| 14 | use embassy_time::{Duration, Instant, Timer}; | ||
| 15 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | |||
| 17 | const COUNT_TO: i64 = 10_000_000; | ||
| 18 | |||
| 19 | /// Configure the RP2040 for 200 MHz operation by manually specifying | ||
| 20 | /// all the required parameters instead of using higher-level APIs. | ||
| 21 | fn configure_manual_overclock() -> Config { | ||
| 22 | // Set the PLL configuration manually, starting from default values | ||
| 23 | let mut config = Config::default(); | ||
| 24 | |||
| 25 | // Set the system clock to 200 MHz using a PLL with a reference frequency of 12 MHz | ||
| 26 | config.clocks = ClockConfig::manual_pll( | ||
| 27 | 12_000_000, | ||
| 28 | PllConfig { | ||
| 29 | refdiv: 1, | ||
| 30 | fbdiv: 100, | ||
| 31 | post_div1: 3, | ||
| 32 | post_div2: 2, | ||
| 33 | }, | ||
| 34 | // For 200 MHz, we need a voltage scale of 1.15V | ||
| 35 | Some(VoltageScale::V1_15), | ||
| 36 | ); | ||
| 37 | |||
| 38 | config | ||
| 39 | } | ||
| 40 | |||
| 41 | #[embassy_executor::main] | ||
| 42 | async fn main(_spawner: Spawner) -> ! { | ||
| 43 | // Initialize with our manual overclock configuration | ||
| 44 | let p = embassy_rp::init(configure_manual_overclock()); | ||
| 45 | |||
| 46 | // Verify the actual system clock frequency | ||
| 47 | let sys_freq = clocks::clk_sys_freq(); | ||
| 48 | info!("System clock frequency: {} MHz", sys_freq / 1_000_000); | ||
| 49 | |||
| 50 | // LED to indicate the system is running | ||
| 51 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 52 | |||
| 53 | loop { | ||
| 54 | // Reset the counter at the start of measurement period | ||
| 55 | let mut counter = 0; | ||
| 56 | |||
| 57 | // Turn LED on while counting | ||
| 58 | led.set_high(); | ||
| 59 | |||
| 60 | let start = Instant::now(); | ||
| 61 | |||
| 62 | // This is a busy loop that will take some time to complete | ||
| 63 | while counter < COUNT_TO { | ||
| 64 | counter += 1; | ||
| 65 | } | ||
| 66 | |||
| 67 | let elapsed = Instant::now() - start; | ||
| 68 | |||
| 69 | // Report the elapsed time | ||
| 70 | led.set_low(); | ||
| 71 | info!( | ||
| 72 | "At {}Mhz: Elapsed time to count to {}: {}ms", | ||
| 73 | sys_freq / 1_000_000, | ||
| 74 | counter, | ||
| 75 | elapsed.as_millis() | ||
| 76 | ); | ||
| 77 | |||
| 78 | // Wait 2 seconds before starting the next measurement | ||
| 79 | Timer::after(Duration::from_secs(2)).await; | ||
| 80 | } | ||
| 81 | } | ||
