aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2025-05-09 19:34:43 +0200
committerGitHub <[email protected]>2025-05-09 19:34:43 +0200
commit11364077a7bb6d14bd37567d17ddb21249409ec7 (patch)
treec1d3fb45984b5ae17a684a32f6d45aff63b5592d /tests
parent2a27aa828cdc310b17c379183bdfaba6585ad933 (diff)
parent4621c8aa7a1ee1b55f2f0bf80fc48eddf76af320 (diff)
Merge pull request #4150 from 1-rafael-1/rp2040-overclocking
RP: rp2040 overclocking
Diffstat (limited to 'tests')
-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}