From b185e02a42ad751ec6c31ffa6a1b87503f15489d Mon Sep 17 00:00:00 2001 From: Caleb Jamison Date: Wed, 7 Aug 2024 23:20:26 -0400 Subject: Initial rp235x support Examples have been run, but there is not yet a test suite. --- examples/rp23/src/bin/uart_buffered_split.rs | 74 ++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/rp23/src/bin/uart_buffered_split.rs (limited to 'examples/rp23/src/bin/uart_buffered_split.rs') diff --git a/examples/rp23/src/bin/uart_buffered_split.rs b/examples/rp23/src/bin/uart_buffered_split.rs new file mode 100644 index 000000000..f7acdade9 --- /dev/null +++ b/examples/rp23/src/bin/uart_buffered_split.rs @@ -0,0 +1,74 @@ +//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip. +//! +//! No specific hardware is specified in this example. If you connect pin 0 and 1 you should get the same data back. +//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used +//! with its UART port. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_rp::bind_interrupts; +use embassy_rp::peripherals::UART0; +use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; +use embassy_time::Timer; +use embedded_io_async::{Read, Write}; +use static_cell::StaticCell; +use {defmt_rtt as _, panic_probe as _}; +use embassy_rp::block::ImageDef; + +#[link_section = ".start_block"] +#[used] +pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); + +// Program metadata for `picotool info` +#[link_section = ".bi_entries"] +#[used] +pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ + embassy_rp::binary_info_rp_cargo_bin_name!(), + embassy_rp::binary_info_rp_cargo_version!(), + embassy_rp::binary_info_rp_program_description!(c"Blinky"), + embassy_rp::binary_info_rp_program_build_attribute!(), +]; + + +bind_interrupts!(struct Irqs { + UART0_IRQ => BufferedInterruptHandler; +}); + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0); + + static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new(); + let tx_buf = &mut TX_BUF.init([0; 16])[..]; + static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new(); + let rx_buf = &mut RX_BUF.init([0; 16])[..]; + let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default()); + let (mut tx, rx) = uart.split(); + + unwrap!(spawner.spawn(reader(rx))); + + info!("Writing..."); + loop { + let data = [ + 1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, + ]; + info!("TX {:?}", data); + tx.write_all(&data).await.unwrap(); + Timer::after_secs(1).await; + } +} + +#[embassy_executor::task] +async fn reader(mut rx: BufferedUartRx<'static, UART0>) { + info!("Reading..."); + loop { + let mut buf = [0; 31]; + rx.read_exact(&mut buf).await.unwrap(); + info!("RX {:?}", buf); + } +} -- cgit From 6f03c40516b49104b33a51f6e189a7fc812c1068 Mon Sep 17 00:00:00 2001 From: Caleb Jamison Date: Thu, 8 Aug 2024 21:54:21 -0400 Subject: cargo fmt --- examples/rp23/src/bin/uart_buffered_split.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/rp23/src/bin/uart_buffered_split.rs') diff --git a/examples/rp23/src/bin/uart_buffered_split.rs b/examples/rp23/src/bin/uart_buffered_split.rs index f7acdade9..2b14520d5 100644 --- a/examples/rp23/src/bin/uart_buffered_split.rs +++ b/examples/rp23/src/bin/uart_buffered_split.rs @@ -10,13 +10,13 @@ use defmt::*; use embassy_executor::Spawner; use embassy_rp::bind_interrupts; +use embassy_rp::block::ImageDef; use embassy_rp::peripherals::UART0; use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; use embassy_time::Timer; use embedded_io_async::{Read, Write}; use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; -use embassy_rp::block::ImageDef; #[link_section = ".start_block"] #[used] @@ -32,7 +32,6 @@ pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [ embassy_rp::binary_info_rp_program_build_attribute!(), ]; - bind_interrupts!(struct Irqs { UART0_IRQ => BufferedInterruptHandler; }); -- cgit