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