aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src/bin/overclock.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-05-13 22:33:56 +0200
committerGitHub <[email protected]>2025-05-13 22:33:56 +0200
commit102258c0b07ca581d5dabdbd540febd54c0f4443 (patch)
tree05765308bab9131f93cd23e1aa5fe306122e8db7 /examples/rp/src/bin/overclock.rs
parent8e7e4332b40707e8d36338ad8ec486320bb3538f (diff)
parentaa85293457039a336eec1f10bcd32d47d7223f95 (diff)
Merge branch 'main' into add-rng
Diffstat (limited to 'examples/rp/src/bin/overclock.rs')
-rw-r--r--examples/rp/src/bin/overclock.rs64
1 files changed, 64 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..9c78e0c9d
--- /dev/null
+++ b/examples/rp/src/bin/overclock.rs
@@ -0,0 +1,64 @@
1//! # Overclocking the RP2040 to 200 MHz
2//!
3//! This example demonstrates how to configure the RP2040 to run at 200 MHz.
4
5#![no_std]
6#![no_main]
7
8use defmt::*;
9use embassy_executor::Spawner;
10use embassy_rp::clocks::{clk_sys_freq, ClockConfig};
11use embassy_rp::config::Config;
12use embassy_rp::gpio::{Level, Output};
13use embassy_time::{Duration, Instant, Timer};
14use {defmt_rtt as _, panic_probe as _};
15
16const COUNT_TO: i64 = 10_000_000;
17
18#[embassy_executor::main]
19async fn main(_spawner: Spawner) -> ! {
20 // Set up for clock frequency of 200 MHz, setting all necessary defaults.
21 let config = Config::new(ClockConfig::system_freq(200_000_000));
22
23 // Show the voltage scale for verification
24 info!("System core voltage: {}", Debug2Format(&config.clocks.core_voltage));
25
26 // Initialize the peripherals
27 let p = embassy_rp::init(config);
28
29 // Show CPU frequency for verification
30 let sys_freq = clk_sys_freq();
31 info!("System clock frequency: {} MHz", sys_freq / 1_000_000);
32
33 // LED to indicate the system is running
34 let mut led = Output::new(p.PIN_25, Level::Low);
35
36 loop {
37 // Reset the counter at the start of measurement period
38 let mut counter = 0;
39
40 // Turn LED on while counting
41 led.set_high();
42
43 let start = Instant::now();
44
45 // This is a busy loop that will take some time to complete
46 while counter < COUNT_TO {
47 counter += 1;
48 }
49
50 let elapsed = Instant::now() - start;
51
52 // Report the elapsed time
53 led.set_low();
54 info!(
55 "At {}Mhz: Elapsed time to count to {}: {}ms",
56 sys_freq / 1_000_000,
57 counter,
58 elapsed.as_millis()
59 );
60
61 // Wait 2 seconds before starting the next measurement
62 Timer::after(Duration::from_secs(2)).await;
63 }
64}