aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src
diff options
context:
space:
mode:
author1-rafael-1 <[email protected]>2025-04-26 22:55:24 +0200
committer1-rafael-1 <[email protected]>2025-04-26 22:55:24 +0200
commitb0594d16f238f803a0192810833ae2b0c3941ec3 (patch)
tree5036f6f99ea691d1a8d56ed9a780a203e84475bd /examples/rp/src
parent45b7127d614ddc65181249e70d94422500865ecd (diff)
Add overclock example for RP2040 with 200 MHz clock configuration
Diffstat (limited to 'examples/rp/src')
-rw-r--r--examples/rp/src/bin/overclock.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/rp/src/bin/overclock.rs b/examples/rp/src/bin/overclock.rs
new file mode 100644
index 000000000..429fff1ac
--- /dev/null
+++ b/examples/rp/src/bin/overclock.rs
@@ -0,0 +1,60 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_rp::clocks::{clk_sys_freq, ClockConfig};
7use embassy_rp::config::Config;
8use embassy_rp::gpio::{Level, Output};
9use embassy_time::{Duration, Instant, Timer};
10use {defmt_rtt as _, panic_probe as _};
11
12const COUNT_TO: i32 = 1_000_000;
13
14#[embassy_executor::main]
15async fn main(_spawner: Spawner) -> ! {
16 // Set up for clock frequency of 200 MHz
17 // We will need a clock config in the HAL config that supports this frequency
18 // The RP2040 can run at 200 MHz with a 12 MHz crystal
19 let config = Config::new(ClockConfig::crystal_freq(12_000_000, 200_000_000));
20
21 // Initialize the peripherals
22 let p = embassy_rp::init(config);
23
24 // Show CPU frequency for verification
25 let sys_freq = clk_sys_freq();
26 info!("System clock frequency: {} Hz", sys_freq);
27
28 // LED to indicate the system is running
29 let mut led = Output::new(p.PIN_25, Level::Low);
30
31 loop {
32 // Reset the counter at the start of measurement period
33 let mut counter = 0;
34
35 // Turn LED on while counting
36 led.set_high();
37
38 let start = Instant::now();
39
40 // Count to COUNT_TO
41 // This is a busy loop that will take some time to complete
42 while counter < COUNT_TO {
43 counter += 1;
44 }
45
46 let elapsed = start - Instant::now();
47
48 // Report the elapsed time
49 led.set_low();
50 info!(
51 "At {}Mhz: Elapsed time to count to {}: {}ms",
52 sys_freq / 1_000_000,
53 COUNT_TO,
54 elapsed.as_millis()
55 );
56
57 // Wait 2 seconds before starting the next measurement
58 Timer::after(Duration::from_secs(2)).await;
59 }
60}