aboutsummaryrefslogtreecommitdiff
path: root/tests/rp/src/bin/overclock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/rp/src/bin/overclock.rs')
-rw-r--r--tests/rp/src/bin/overclock.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/rp/src/bin/overclock.rs b/tests/rp/src/bin/overclock.rs
new file mode 100644
index 000000000..be8e85a3f
--- /dev/null
+++ b/tests/rp/src/bin/overclock.rs
@@ -0,0 +1,70 @@
1#![no_std]
2#![no_main]
3
4#[cfg(feature = "rp2040")]
5teleprobe_meta::target!(b"rpi-pico");
6#[cfg(feature = "rp235xb")]
7teleprobe_meta::target!(b"pimoroni-pico-plus-2");
8
9use defmt::info;
10#[cfg(feature = "rp2040")]
11use defmt::{assert, assert_eq};
12use embassy_executor::Spawner;
13use embassy_rp::clocks;
14#[cfg(feature = "rp2040")]
15use embassy_rp::clocks::ClockConfig;
16#[cfg(feature = "rp2040")]
17use embassy_rp::clocks::CoreVoltage;
18use embassy_rp::config::Config;
19use embassy_time::Instant;
20use {defmt_rtt as _, panic_probe as _};
21
22const COUNT_TO: i64 = 10_000_000;
23
24#[embassy_executor::main]
25async fn main(_spawner: Spawner) {
26 #[cfg(feature = "rp2040")]
27 let mut config = Config::default();
28 #[cfg(not(feature = "rp2040"))]
29 let config = Config::default();
30
31 // Initialize with 200MHz clock configuration for RP2040, other chips will use default clock
32 #[cfg(feature = "rp2040")]
33 {
34 config.clocks = ClockConfig::system_freq(200_000_000);
35 let voltage = config.clocks.core_voltage;
36 assert!(matches!(voltage, CoreVoltage::V1_15), "Expected voltage scale V1_15");
37 }
38
39 let _p = embassy_rp::init(config);
40
41 // Test the system speed
42 let (time_elapsed, clk_sys_freq) = {
43 let mut counter = 0;
44 let start = Instant::now();
45 while counter < COUNT_TO {
46 counter += 1;
47 }
48 let elapsed = Instant::now() - start;
49
50 (elapsed.as_millis(), clocks::clk_sys_freq())
51 };
52
53 // Report the elapsed time, so that the compiler doesn't optimize it away for chips other than RP2040
54 info!(
55 "At {}Mhz: Elapsed time to count to {}: {}ms",
56 clk_sys_freq / 1_000_000,
57 COUNT_TO,
58 time_elapsed
59 );
60
61 #[cfg(feature = "rp2040")]
62 {
63 // we should be at 200MHz
64 assert_eq!(clk_sys_freq, 200_000_000, "System clock frequency is not 200MHz");
65 // At 200MHz, the time to count to 10_000_000 should be at 600ms, testing with 1% margin
66 assert!(time_elapsed <= 606, "Elapsed time is too long");
67 }
68
69 cortex_m::asm::bkpt();
70}