diff options
Diffstat (limited to 'examples/rp/src')
| -rw-r--r-- | examples/rp/src/bin/overclock.rs | 64 | ||||
| -rw-r--r-- | examples/rp/src/bin/overclock_manual.rs | 79 | ||||
| -rw-r--r-- | examples/rp/src/bin/sharing.rs | 2 | ||||
| -rw-r--r-- | examples/rp/src/bin/uart_buffered_split.rs | 2 | ||||
| -rw-r--r-- | examples/rp/src/bin/uart_unidir.rs | 2 |
5 files changed, 146 insertions, 3 deletions
diff --git a/examples/rp/src/bin/overclock.rs b/examples/rp/src/bin/overclock.rs new file mode 100644 index 000000000..9c78e0c9d --- /dev/null +++ b/examples/rp/src/bin/overclock.rs | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | //! # Overclocking the RP2040 to 200 MHz | ||
| 2 | //! | ||
| 3 | //! This example demonstrates how to configure the RP2040 to run at 200 MHz. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_rp::clocks::{clk_sys_freq, ClockConfig}; | ||
| 11 | use embassy_rp::config::Config; | ||
| 12 | use embassy_rp::gpio::{Level, Output}; | ||
| 13 | use embassy_time::{Duration, Instant, Timer}; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | |||
| 16 | const COUNT_TO: i64 = 10_000_000; | ||
| 17 | |||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) -> ! { | ||
| 20 | // Set up for clock frequency of 200 MHz, setting all necessary defaults. | ||
| 21 | let config = Config::new(ClockConfig::system_freq(200_000_000)); | ||
| 22 | |||
| 23 | // Show the voltage scale for verification | ||
| 24 | info!("System core voltage: {}", Debug2Format(&config.clocks.core_voltage)); | ||
| 25 | |||
| 26 | // Initialize the peripherals | ||
| 27 | let p = embassy_rp::init(config); | ||
| 28 | |||
| 29 | // Show CPU frequency for verification | ||
| 30 | let sys_freq = clk_sys_freq(); | ||
| 31 | info!("System clock frequency: {} MHz", sys_freq / 1_000_000); | ||
| 32 | |||
| 33 | // LED to indicate the system is running | ||
| 34 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 35 | |||
| 36 | loop { | ||
| 37 | // Reset the counter at the start of measurement period | ||
| 38 | let mut counter = 0; | ||
| 39 | |||
| 40 | // Turn LED on while counting | ||
| 41 | led.set_high(); | ||
| 42 | |||
| 43 | let start = Instant::now(); | ||
| 44 | |||
| 45 | // This is a busy loop that will take some time to complete | ||
| 46 | while counter < COUNT_TO { | ||
| 47 | counter += 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | let elapsed = Instant::now() - start; | ||
| 51 | |||
| 52 | // Report the elapsed time | ||
| 53 | led.set_low(); | ||
| 54 | info!( | ||
| 55 | "At {}Mhz: Elapsed time to count to {}: {}ms", | ||
| 56 | sys_freq / 1_000_000, | ||
| 57 | counter, | ||
| 58 | elapsed.as_millis() | ||
| 59 | ); | ||
| 60 | |||
| 61 | // Wait 2 seconds before starting the next measurement | ||
| 62 | Timer::after(Duration::from_secs(2)).await; | ||
| 63 | } | ||
| 64 | } | ||
diff --git a/examples/rp/src/bin/overclock_manual.rs b/examples/rp/src/bin/overclock_manual.rs new file mode 100644 index 000000000..35160b250 --- /dev/null +++ b/examples/rp/src/bin/overclock_manual.rs | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | //! # Overclocking the RP2040 to 200 MHz manually | ||
| 2 | //! | ||
| 3 | //! This example demonstrates how to manually configure the RP2040 to run at 200 MHz. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_rp::clocks; | ||
| 11 | use embassy_rp::clocks::{ClockConfig, CoreVoltage, PllConfig}; | ||
| 12 | use embassy_rp::config::Config; | ||
| 13 | use embassy_rp::gpio::{Level, Output}; | ||
| 14 | use embassy_time::{Duration, Instant, Timer}; | ||
| 15 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | |||
| 17 | const COUNT_TO: i64 = 10_000_000; | ||
| 18 | |||
| 19 | /// Configure the RP2040 for 200 MHz operation by manually specifying the PLL settings. | ||
| 20 | fn configure_manual_overclock() -> Config { | ||
| 21 | // Set the PLL configuration manually, starting from default values | ||
| 22 | let mut config = Config::default(); | ||
| 23 | |||
| 24 | // Set the system clock to 200 MHz | ||
| 25 | config.clocks = ClockConfig::manual_pll( | ||
| 26 | 12_000_000, // Crystal frequency, 12 MHz is common. If using custom, set to your value. | ||
| 27 | PllConfig { | ||
| 28 | refdiv: 1, // Reference divider | ||
| 29 | fbdiv: 100, // Feedback divider | ||
| 30 | post_div1: 3, // Post divider 1 | ||
| 31 | post_div2: 2, // Post divider 2 | ||
| 32 | }, | ||
| 33 | CoreVoltage::V1_15, // Core voltage, should be set to V1_15 for 200 MHz | ||
| 34 | ); | ||
| 35 | |||
| 36 | config | ||
| 37 | } | ||
| 38 | |||
| 39 | #[embassy_executor::main] | ||
| 40 | async fn main(_spawner: Spawner) -> ! { | ||
| 41 | // Initialize with our manual overclock configuration | ||
| 42 | let p = embassy_rp::init(configure_manual_overclock()); | ||
| 43 | |||
| 44 | // Verify the actual system clock frequency | ||
| 45 | let sys_freq = clocks::clk_sys_freq(); | ||
| 46 | info!("System clock frequency: {} MHz", sys_freq / 1_000_000); | ||
| 47 | |||
| 48 | // LED to indicate the system is running | ||
| 49 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 50 | |||
| 51 | loop { | ||
| 52 | // Reset the counter at the start of measurement period | ||
| 53 | let mut counter = 0; | ||
| 54 | |||
| 55 | // Turn LED on while counting | ||
| 56 | led.set_high(); | ||
| 57 | |||
| 58 | let start = Instant::now(); | ||
| 59 | |||
| 60 | // This is a busy loop that will take some time to complete | ||
| 61 | while counter < COUNT_TO { | ||
| 62 | counter += 1; | ||
| 63 | } | ||
| 64 | |||
| 65 | let elapsed = Instant::now() - start; | ||
| 66 | |||
| 67 | // Report the elapsed time | ||
| 68 | led.set_low(); | ||
| 69 | info!( | ||
| 70 | "At {}Mhz: Elapsed time to count to {}: {}ms", | ||
| 71 | sys_freq / 1_000_000, | ||
| 72 | counter, | ||
| 73 | elapsed.as_millis() | ||
| 74 | ); | ||
| 75 | |||
| 76 | // Wait 2 seconds before starting the next measurement | ||
| 77 | Timer::after(Duration::from_secs(2)).await; | ||
| 78 | } | ||
| 79 | } | ||
diff --git a/examples/rp/src/bin/sharing.rs b/examples/rp/src/bin/sharing.rs index 5416e20ce..497c4f845 100644 --- a/examples/rp/src/bin/sharing.rs +++ b/examples/rp/src/bin/sharing.rs | |||
| @@ -31,7 +31,7 @@ use rand::RngCore; | |||
| 31 | use static_cell::{ConstStaticCell, StaticCell}; | 31 | use static_cell::{ConstStaticCell, StaticCell}; |
| 32 | use {defmt_rtt as _, panic_probe as _}; | 32 | use {defmt_rtt as _, panic_probe as _}; |
| 33 | 33 | ||
| 34 | type UartAsyncMutex = mutex::Mutex<CriticalSectionRawMutex, UartTx<'static, UART0, uart::Async>>; | 34 | type UartAsyncMutex = mutex::Mutex<CriticalSectionRawMutex, UartTx<'static, uart::Async>>; |
| 35 | 35 | ||
| 36 | struct MyType { | 36 | struct MyType { |
| 37 | inner: u32, | 37 | inner: u32, |
diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs index da7e94139..3adbc18ab 100644 --- a/examples/rp/src/bin/uart_buffered_split.rs +++ b/examples/rp/src/bin/uart_buffered_split.rs | |||
| @@ -48,7 +48,7 @@ async fn main(spawner: Spawner) { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | #[embassy_executor::task] | 50 | #[embassy_executor::task] |
| 51 | async fn reader(mut rx: BufferedUartRx<'static, UART0>) { | 51 | async fn reader(mut rx: BufferedUartRx) { |
| 52 | info!("Reading..."); | 52 | info!("Reading..."); |
| 53 | loop { | 53 | loop { |
| 54 | let mut buf = [0; 31]; | 54 | let mut buf = [0; 31]; |
diff --git a/examples/rp/src/bin/uart_unidir.rs b/examples/rp/src/bin/uart_unidir.rs index a45f40756..c2c8dfad8 100644 --- a/examples/rp/src/bin/uart_unidir.rs +++ b/examples/rp/src/bin/uart_unidir.rs | |||
| @@ -39,7 +39,7 @@ async fn main(spawner: Spawner) { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | #[embassy_executor::task] | 41 | #[embassy_executor::task] |
| 42 | async fn reader(mut rx: UartRx<'static, UART1, Async>) { | 42 | async fn reader(mut rx: UartRx<'static, Async>) { |
| 43 | info!("Reading..."); | 43 | info!("Reading..."); |
| 44 | loop { | 44 | loop { |
| 45 | // read a total of 4 transmissions (32 / 8) and then print the result | 45 | // read a total of 4 transmissions (32 / 8) and then print the result |
