aboutsummaryrefslogtreecommitdiff
path: root/tests/rp/src/bin/overclock.rs
diff options
context:
space:
mode:
author1-rafael-1 <[email protected]>2025-05-01 22:17:25 +0200
committer1-rafael-1 <[email protected]>2025-05-01 22:17:25 +0200
commit561356f68ab2d3d6fbe1f85245eb320dbc3e59f0 (patch)
treea27fa59e2eda7849f334872fc2af597980be0b57 /tests/rp/src/bin/overclock.rs
parent7fa59a6b31c7c9744e5cdef3826bc4e726736606 (diff)
overclock test, should now run on all rp chips
Diffstat (limited to 'tests/rp/src/bin/overclock.rs')
-rw-r--r--tests/rp/src/bin/overclock.rs94
1 files changed, 40 insertions, 54 deletions
diff --git a/tests/rp/src/bin/overclock.rs b/tests/rp/src/bin/overclock.rs
index c4393dde4..d6d6062f2 100644
--- a/tests/rp/src/bin/overclock.rs
+++ b/tests/rp/src/bin/overclock.rs
@@ -1,79 +1,65 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#![cfg_attr(not(feature = "rp2040"), allow(unused_imports))]
4 3
5#[cfg(feature = "rp2040")] 4#[cfg(feature = "rp2040")]
6teleprobe_meta::target!(b"rpi-pico"); 5teleprobe_meta::target!(b"rpi-pico");
6#[cfg(feature = "rp235xb")]
7teleprobe_meta::target!(b"pimoroni-pico-plus-2");
7 8
8#[cfg(feature = "rp2040")]
9use defmt::{assert, assert_eq, info}; 9use defmt::{assert, assert_eq, info};
10#[cfg(feature = "rp2040")]
11use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_rp::clocks;
12#[cfg(feature = "rp2040")] 12#[cfg(feature = "rp2040")]
13use embassy_rp::config::Config; 13use embassy_rp::clocks::ClockConfig;
14#[cfg(feature = "rp2040")]
15use embassy_rp::gpio::{Input, Pull};
16#[cfg(feature = "rp2040")]
17use embassy_rp::pwm::{Config as PwmConfig, Pwm};
18#[cfg(feature = "rp2040")]
19use embassy_time::{Instant, Timer};
20#[cfg(feature = "rp2040")] 14#[cfg(feature = "rp2040")]
15use embassy_rp::clocks::VoltageScale;
16use embassy_rp::config::Config;
17use embassy_time::Instant;
21use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
22 19
23#[cfg(feature = "rp2040")] 20const COUNT_TO: i64 = 10_000_000;
21
24#[embassy_executor::main] 22#[embassy_executor::main]
25async fn main(_spawner: Spawner) { 23async fn main(_spawner: Spawner) {
26 // Initialize with 200MHz clock configuration for RP2040
27 let mut config = Config::default(); 24 let mut config = Config::default();
28 config.clocks = embassy_rp::clocks::ClockConfig::at_sys_frequency_mhz(200);
29 25
30 let p = embassy_rp::init(config); 26 // Initialize with 200MHz clock configuration for RP2040, other chips will use default clock
27 #[cfg(feature = "rp2040")]
28 {
29 config.clocks = ClockConfig::at_sys_frequency_mhz(200);
30 let voltage = config.clocks.voltage_scale.unwrap();
31 assert!(matches!(voltage, VoltageScale::V1_15), "Expected voltage scale V1_15");
32 }
31 33
32 info!("RP2040 overclocked to 200MHz!"); 34 let _p = embassy_rp::init(config);
33 info!("System clock frequency: {} Hz", embassy_rp::clocks::clk_sys_freq());
34 35
35 // Test 1: Timer accuracy at 200MHz 36 let (time_elapsed, clk_sys_freq) = {
36 info!("Testing timer accuracy at 200MHz..."); 37 // Test the system speed
37 let start = Instant::now(); 38 let mut counter = 0;
38 Timer::after_millis(100).await; 39 let start = Instant::now();
39 let end = Instant::now(); 40 while counter < COUNT_TO {
40 let ms = (end - start).as_millis(); 41 counter += 1;
41 info!("slept for {} ms", ms); 42 }
42 assert!(ms >= 99); 43 let elapsed = Instant::now() - start;
43 assert!(ms < 110);
44 info!("Timer test passed!");
45 44
46 // Test 2: PWM functionality at 200MHz 45 (elapsed.as_millis(), clocks::clk_sys_freq())
47 info!("Testing PWM functionality at 200MHz...");
48 let pwm_cfg = {
49 let mut c = PwmConfig::default();
50 c.divider = ((embassy_rp::clocks::clk_sys_freq() / 1_000_000) as u8).into();
51 c.top = 10000;
52 c.compare_a = 5000;
53 c.compare_b = 5000;
54 c
55 }; 46 };
56 47
57 // Test PWM output 48 // Report the elapsed time, so that the compiler doesn't optimize it away for chips other than RP2040
58 let pin1 = Input::new(p.PIN_9, Pull::None); 49 info!(
59 let _pwm = Pwm::new_output_a(p.PWM_SLICE3, p.PIN_6, pwm_cfg); 50 "At {}Mhz: Elapsed time to count to {}: {}ms",
60 Timer::after_millis(1).await; 51 clk_sys_freq / 1_000_000,
61 let initial_state = pin1.is_low(); 52 COUNT_TO,
62 Timer::after_millis(5).await; 53 time_elapsed
63 assert_eq!(pin1.is_high(), initial_state); 54 );
64 Timer::after_millis(5).await;
65 assert_eq!(pin1.is_low(), initial_state);
66 info!("PWM test passed!");
67 55
68 info!("All tests passed at 200MHz!"); 56 #[cfg(feature = "rp2040")]
69 info!("Overclock test successful"); 57 {
70 cortex_m::asm::bkpt(); 58 // we should be at 200MHz
71} 59 assert_eq!(clk_sys_freq, 200_000_000, "System clock frequency is not 200MHz");
60 // At 200MHz, the time to count to 10_000_000 should be at 600ms, testing with 1% margin
61 assert!(time_elapsed <= 606, "Elapsed time is too long");
62 }
72 63
73#[cfg(not(feature = "rp2040"))]
74#[embassy_executor::main]
75async fn main(_spawner: embassy_executor::Spawner) {
76 // This is an empty placeholder main function for non-RP2040 targets
77 // It should never be called since the test only runs on RP2040
78 cortex_m::asm::bkpt(); 64 cortex_m::asm::bkpt();
79} 65}