diff options
| author | Jakob <[email protected]> | 2025-05-14 18:57:49 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-14 18:57:49 +0200 |
| commit | b17da5b79470cb6b9877ec9fd5682062f7a37aec (patch) | |
| tree | 4d60a3e4b9404a8b566b069358d700a6cfb5f8b2 /examples/rp/src | |
| parent | a71642ca01190d1a8f8bd652bd41d8a9539fe2ee (diff) | |
| parent | b9ed61cdd99be4a58a757a0eb32c1fa77a696d6a (diff) | |
Merge branch 'embassy-rs:main' into update_doc_comment_for_adc_read
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 | 81 | ||||
| -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, 148 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..83b17308b --- /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, core_voltage, 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).unwrap()); | ||
| 22 | |||
| 23 | // Initialize the peripherals | ||
| 24 | let p = embassy_rp::init(config); | ||
| 25 | |||
| 26 | // Show CPU frequency for verification | ||
| 27 | let sys_freq = clk_sys_freq(); | ||
| 28 | info!("System clock frequency: {} MHz", sys_freq / 1_000_000); | ||
| 29 | // Show core voltage for verification | ||
| 30 | let core_voltage = core_voltage().unwrap(); | ||
| 31 | info!("Core voltage: {}", core_voltage); | ||
| 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..dea5cfb3c --- /dev/null +++ b/examples/rp/src/bin/overclock_manual.rs | |||
| @@ -0,0 +1,81 @@ | |||
| 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::{clk_sys_freq, core_voltage, ClockConfig, CoreVoltage, PllConfig}; | ||
| 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 | /// Configure the RP2040 for 200 MHz operation by manually specifying the PLL settings. | ||
| 19 | fn configure_manual_overclock() -> Config { | ||
| 20 | // Set the PLL configuration manually, starting from default values | ||
| 21 | let mut config = Config::default(); | ||
| 22 | |||
| 23 | // Set the system clock to 200 MHz | ||
| 24 | config.clocks = ClockConfig::manual_pll( | ||
| 25 | 12_000_000, // Crystal frequency, 12 MHz is common. If using custom, set to your value. | ||
| 26 | PllConfig { | ||
| 27 | refdiv: 1, // Reference divider | ||
| 28 | fbdiv: 100, // Feedback divider | ||
| 29 | post_div1: 3, // Post divider 1 | ||
| 30 | post_div2: 2, // Post divider 2 | ||
| 31 | }, | ||
| 32 | CoreVoltage::V1_15, // Core voltage, should be set to V1_15 for 200 MHz | ||
| 33 | ); | ||
| 34 | |||
| 35 | config | ||
| 36 | } | ||
| 37 | |||
| 38 | #[embassy_executor::main] | ||
| 39 | async fn main(_spawner: Spawner) -> ! { | ||
| 40 | // Initialize with our manual overclock configuration | ||
| 41 | let p = embassy_rp::init(configure_manual_overclock()); | ||
| 42 | |||
| 43 | // Show CPU frequency for verification | ||
| 44 | let sys_freq = clk_sys_freq(); | ||
| 45 | info!("System clock frequency: {} MHz", sys_freq / 1_000_000); | ||
| 46 | // Show core voltage for verification | ||
| 47 | let core_voltage = core_voltage().unwrap(); | ||
| 48 | info!("Core voltage: {}", core_voltage); | ||
| 49 | |||
| 50 | // LED to indicate the system is running | ||
| 51 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 52 | |||
| 53 | loop { | ||
| 54 | // Reset the counter at the start of measurement period | ||
| 55 | let mut counter = 0; | ||
| 56 | |||
| 57 | // Turn LED on while counting | ||
| 58 | led.set_high(); | ||
| 59 | |||
| 60 | let start = Instant::now(); | ||
| 61 | |||
| 62 | // This is a busy loop that will take some time to complete | ||
| 63 | while counter < COUNT_TO { | ||
| 64 | counter += 1; | ||
| 65 | } | ||
| 66 | |||
| 67 | let elapsed = Instant::now() - start; | ||
| 68 | |||
| 69 | // Report the elapsed time | ||
| 70 | led.set_low(); | ||
| 71 | info!( | ||
| 72 | "At {}Mhz: Elapsed time to count to {}: {}ms", | ||
| 73 | sys_freq / 1_000_000, | ||
| 74 | counter, | ||
| 75 | elapsed.as_millis() | ||
| 76 | ); | ||
| 77 | |||
| 78 | // Wait 2 seconds before starting the next measurement | ||
| 79 | Timer::after(Duration::from_secs(2)).await; | ||
| 80 | } | ||
| 81 | } | ||
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 |
