aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/rp/src/bin/overclock.rs70
-rw-r--r--tests/rp/src/bin/uart.rs6
-rw-r--r--tests/rp/src/bin/uart_buffered.rs6
-rw-r--r--tests/rp/src/bin/uart_dma.rs6
4 files changed, 79 insertions, 9 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}
diff --git a/tests/rp/src/bin/uart.rs b/tests/rp/src/bin/uart.rs
index 84744ab77..80230f3fe 100644
--- a/tests/rp/src/bin/uart.rs
+++ b/tests/rp/src/bin/uart.rs
@@ -8,17 +8,17 @@ teleprobe_meta::target!(b"pimoroni-pico-plus-2");
8use defmt::{assert_eq, *}; 8use defmt::{assert_eq, *};
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_rp::gpio::{Level, Output}; 10use embassy_rp::gpio::{Level, Output};
11use embassy_rp::uart::{Blocking, Config, Error, Instance, Parity, Uart, UartRx}; 11use embassy_rp::uart::{Blocking, Config, Error, Parity, Uart, UartRx};
12use embassy_time::Timer; 12use embassy_time::Timer;
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
15fn read<const N: usize>(uart: &mut Uart<'_, impl Instance, Blocking>) -> Result<[u8; N], Error> { 15fn read<const N: usize>(uart: &mut Uart<'_, Blocking>) -> Result<[u8; N], Error> {
16 let mut buf = [255; N]; 16 let mut buf = [255; N];
17 uart.blocking_read(&mut buf)?; 17 uart.blocking_read(&mut buf)?;
18 Ok(buf) 18 Ok(buf)
19} 19}
20 20
21fn read1<const N: usize>(uart: &mut UartRx<'_, impl Instance, Blocking>) -> Result<[u8; N], Error> { 21fn read1<const N: usize>(uart: &mut UartRx<'_, Blocking>) -> Result<[u8; N], Error> {
22 let mut buf = [255; N]; 22 let mut buf = [255; N];
23 uart.blocking_read(&mut buf)?; 23 uart.blocking_read(&mut buf)?;
24 Ok(buf) 24 Ok(buf)
diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs
index d5f655e9b..cb78fc142 100644
--- a/tests/rp/src/bin/uart_buffered.rs
+++ b/tests/rp/src/bin/uart_buffered.rs
@@ -10,7 +10,7 @@ use embassy_executor::Spawner;
10use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
11use embassy_rp::gpio::{Level, Output}; 11use embassy_rp::gpio::{Level, Output};
12use embassy_rp::peripherals::UART0; 12use embassy_rp::peripherals::UART0;
13use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config, Error, Instance, Parity}; 13use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config, Error, Parity};
14use embassy_time::Timer; 14use embassy_time::Timer;
15use embedded_io_async::{Read, ReadExactError, Write}; 15use embedded_io_async::{Read, ReadExactError, Write};
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
@@ -19,7 +19,7 @@ bind_interrupts!(struct Irqs {
19 UART0_IRQ => BufferedInterruptHandler<UART0>; 19 UART0_IRQ => BufferedInterruptHandler<UART0>;
20}); 20});
21 21
22async fn read<const N: usize>(uart: &mut BufferedUart<'_, impl Instance>) -> Result<[u8; N], Error> { 22async fn read<const N: usize>(uart: &mut BufferedUart) -> Result<[u8; N], Error> {
23 let mut buf = [255; N]; 23 let mut buf = [255; N];
24 match uart.read_exact(&mut buf).await { 24 match uart.read_exact(&mut buf).await {
25 Ok(()) => Ok(buf), 25 Ok(()) => Ok(buf),
@@ -29,7 +29,7 @@ async fn read<const N: usize>(uart: &mut BufferedUart<'_, impl Instance>) -> Res
29 } 29 }
30} 30}
31 31
32async fn read1<const N: usize>(uart: &mut BufferedUartRx<'_, impl Instance>) -> Result<[u8; N], Error> { 32async fn read1<const N: usize>(uart: &mut BufferedUartRx) -> Result<[u8; N], Error> {
33 let mut buf = [255; N]; 33 let mut buf = [255; N];
34 match uart.read_exact(&mut buf).await { 34 match uart.read_exact(&mut buf).await {
35 Ok(()) => Ok(buf), 35 Ok(()) => Ok(buf),
diff --git a/tests/rp/src/bin/uart_dma.rs b/tests/rp/src/bin/uart_dma.rs
index a09101223..a7af81f5f 100644
--- a/tests/rp/src/bin/uart_dma.rs
+++ b/tests/rp/src/bin/uart_dma.rs
@@ -10,7 +10,7 @@ use embassy_executor::Spawner;
10use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
11use embassy_rp::gpio::{Level, Output}; 11use embassy_rp::gpio::{Level, Output};
12use embassy_rp::peripherals::UART0; 12use embassy_rp::peripherals::UART0;
13use embassy_rp::uart::{Async, Config, Error, Instance, InterruptHandler, Parity, Uart, UartRx}; 13use embassy_rp::uart::{Async, Config, Error, InterruptHandler, Parity, Uart, UartRx};
14use embassy_time::Timer; 14use embassy_time::Timer;
15use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
16 16
@@ -18,13 +18,13 @@ bind_interrupts!(struct Irqs {
18 UART0_IRQ => InterruptHandler<UART0>; 18 UART0_IRQ => InterruptHandler<UART0>;
19}); 19});
20 20
21async fn read<const N: usize>(uart: &mut Uart<'_, impl Instance, Async>) -> Result<[u8; N], Error> { 21async fn read<const N: usize>(uart: &mut Uart<'_, Async>) -> Result<[u8; N], Error> {
22 let mut buf = [255; N]; 22 let mut buf = [255; N];
23 uart.read(&mut buf).await?; 23 uart.read(&mut buf).await?;
24 Ok(buf) 24 Ok(buf)
25} 25}
26 26
27async fn read1<const N: usize>(uart: &mut UartRx<'_, impl Instance, Async>) -> Result<[u8; N], Error> { 27async fn read1<const N: usize>(uart: &mut UartRx<'_, Async>) -> Result<[u8; N], Error> {
28 let mut buf = [255; N]; 28 let mut buf = [255; N];
29 uart.read(&mut buf).await?; 29 uart.read(&mut buf).await?;
30 Ok(buf) 30 Ok(buf)