diff options
Diffstat (limited to 'examples/rp/src/bin/overclock_manual.rs')
| -rw-r--r-- | examples/rp/src/bin/overclock_manual.rs | 79 |
1 files changed, 79 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..35160b250 --- /dev/null +++ b/examples/rp/src/bin/overclock_manual.rs | |||
| @@ -0,0 +1,79 @@ | |||
| 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, CoreVoltage, PllConfig}; | ||
| 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 the PLL settings. | ||
| 20 | fn configure_manual_overclock() -> Config { | ||
| 21 | // Set the PLL configuration manually, starting from default values | ||
| 22 | let mut config = Config::default(); | ||
| 23 | |||
| 24 | // Set the system clock to 200 MHz | ||
| 25 | config.clocks = ClockConfig::manual_pll( | ||
| 26 | 12_000_000, // Crystal frequency, 12 MHz is common. If using custom, set to your value. | ||
| 27 | PllConfig { | ||
| 28 | refdiv: 1, // Reference divider | ||
| 29 | fbdiv: 100, // Feedback divider | ||
| 30 | post_div1: 3, // Post divider 1 | ||
| 31 | post_div2: 2, // Post divider 2 | ||
| 32 | }, | ||
| 33 | CoreVoltage::V1_15, // Core voltage, should be set to V1_15 for 200 MHz | ||
| 34 | ); | ||
| 35 | |||
| 36 | config | ||
| 37 | } | ||
| 38 | |||
| 39 | #[embassy_executor::main] | ||
| 40 | async fn main(_spawner: Spawner) -> ! { | ||
| 41 | // Initialize with our manual overclock configuration | ||
| 42 | let p = embassy_rp::init(configure_manual_overclock()); | ||
| 43 | |||
| 44 | // Verify the actual system clock frequency | ||
| 45 | let sys_freq = clocks::clk_sys_freq(); | ||
| 46 | info!("System clock frequency: {} MHz", sys_freq / 1_000_000); | ||
| 47 | |||
| 48 | // LED to indicate the system is running | ||
| 49 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 50 | |||
| 51 | loop { | ||
| 52 | // Reset the counter at the start of measurement period | ||
| 53 | let mut counter = 0; | ||
| 54 | |||
| 55 | // Turn LED on while counting | ||
| 56 | led.set_high(); | ||
| 57 | |||
| 58 | let start = Instant::now(); | ||
| 59 | |||
| 60 | // This is a busy loop that will take some time to complete | ||
| 61 | while counter < COUNT_TO { | ||
| 62 | counter += 1; | ||
| 63 | } | ||
| 64 | |||
| 65 | let elapsed = Instant::now() - start; | ||
| 66 | |||
| 67 | // Report the elapsed time | ||
| 68 | led.set_low(); | ||
| 69 | info!( | ||
| 70 | "At {}Mhz: Elapsed time to count to {}: {}ms", | ||
| 71 | sys_freq / 1_000_000, | ||
| 72 | counter, | ||
| 73 | elapsed.as_millis() | ||
| 74 | ); | ||
| 75 | |||
| 76 | // Wait 2 seconds before starting the next measurement | ||
| 77 | Timer::after(Duration::from_secs(2)).await; | ||
| 78 | } | ||
| 79 | } | ||
