aboutsummaryrefslogtreecommitdiff
path: root/examples/rp
diff options
context:
space:
mode:
author1-rafael-1 <[email protected]>2025-05-01 00:11:56 +0200
committer1-rafael-1 <[email protected]>2025-05-01 00:11:56 +0200
commit22b5f73811a7cc0dbca920e02b5d001d252d344c (patch)
treed3fd2d801ffddc74a43f04c7892c953356647904 /examples/rp
parentd44b94523576d3f8c1f586811f600eb3ba223606 (diff)
add manual overclock example, finalize API, cleanup
Diffstat (limited to 'examples/rp')
-rw-r--r--examples/rp/src/bin/overclock.rs24
-rw-r--r--examples/rp/src/bin/overclock_manual.rs81
2 files changed, 87 insertions, 18 deletions
diff --git a/examples/rp/src/bin/overclock.rs b/examples/rp/src/bin/overclock.rs
index 9027f1516..e3ac77340 100644
--- a/examples/rp/src/bin/overclock.rs
+++ b/examples/rp/src/bin/overclock.rs
@@ -1,9 +1,13 @@
1//! # Overclocking the RP2040 to 200 MHz
2//!
3//! This example demonstrates how to configure the RP2040 to run at 200 MHz using a higher level API.
4
1#![no_std] 5#![no_std]
2#![no_main] 6#![no_main]
3 7
4use defmt::*; 8use defmt::*;
5use embassy_executor::Spawner; 9use embassy_executor::Spawner;
6use embassy_rp::clocks::{clk_sys_freq, ClockConfig, VoltageScale}; 10use embassy_rp::clocks::{clk_sys_freq, ClockConfig};
7use embassy_rp::config::Config; 11use embassy_rp::config::Config;
8use embassy_rp::gpio::{Level, Output}; 12use embassy_rp::gpio::{Level, Output};
9use embassy_time::{Duration, Instant, Timer}; 13use embassy_time::{Duration, Instant, Timer};
@@ -15,15 +19,10 @@ const COUNT_TO: i64 = 10_000_000;
15async fn main(_spawner: Spawner) -> ! { 19async fn main(_spawner: Spawner) -> ! {
16 // Set up for clock frequency of 200 MHz 20 // Set up for clock frequency of 200 MHz
17 // This will set all the necessary defaults including slightly raised voltage 21 // This will set all the necessary defaults including slightly raised voltage
18 // See embassy_rp::clocks::ClockConfig for more options, including full manual control
19 let config = Config::new(ClockConfig::at_sys_frequency_mhz(200)); 22 let config = Config::new(ClockConfig::at_sys_frequency_mhz(200));
20 23
21 // Show the voltage scale and brownout-detection for verification 24 // Show the voltage scale for verification
22 info!("System core voltage: {}", Debug2Format(&config.clocks.voltage_scale)); 25 info!("System core voltage: {}", Debug2Format(&config.clocks.voltage_scale));
23 // info!(
24 // "Brownout detection: {}",
25 // Debug2Format(&config.clocks.brownout_detection)
26 // );
27 26
28 // Initialize the peripherals 27 // Initialize the peripherals
29 let p = embassy_rp::init(config); 28 let p = embassy_rp::init(config);
@@ -64,14 +63,3 @@ async fn main(_spawner: Spawner) -> ! {
64 Timer::after(Duration::from_secs(2)).await; 63 Timer::after(Duration::from_secs(2)).await;
65 } 64 }
66} 65}
67
68// let config = Config::new(ClockConfig::with_speed_mhz_test_voltage(125, Some(VoltageScale::V1_10)));
69// let config = Config::default();
70// let config = Config::new(ClockConfig::with_speed_mhz_test_voltage_extended_delay(
71// 200, // Standard 125MHz clock
72// Some(VoltageScale::V1_15), // 1.15V voltage
73// Some(1000), // 1000μs (1ms) stabilization delay - significantly longer than default
74// ));
75// Initialize the peripherals
76
77// let p = embassy_rp::init(Default::default()); //testing the bog standard
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
8use defmt::*;
9use embassy_executor::Spawner;
10use embassy_rp::clocks;
11use embassy_rp::clocks::{ClockConfig, PllConfig, VoltageScale};
12use embassy_rp::config::Config;
13use embassy_rp::gpio::{Level, Output};
14use embassy_time::{Duration, Instant, Timer};
15use {defmt_rtt as _, panic_probe as _};
16
17const 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.
21fn 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]
42async 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}