diff --git a/embassy-nrf/CHANGELOG.md b/embassy-nrf/CHANGELOG.md index b77688148..ffa7997f7 100644 --- a/embassy-nrf/CHANGELOG.md +++ b/embassy-nrf/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - bugfix: nrf twim return errors in async\_wait instead of waiting indefinitely - bugfix: fix missing setting input as disconnected. +- changed: Modify Uarte and BufferedUarte initialization to take pins before interrupts ([#3983](https://github.com/embassy-rs/embassy/pull/3983)) + ## 0.3.0 - 2025-01-06 diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index f939be004..29e126903 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -227,9 +227,9 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { ppi_ch1: Peri<'d, impl ConfigurableChannel>, ppi_ch2: Peri<'d, impl ConfigurableChannel>, ppi_group: Peri<'d, impl Group>, - _irq: impl interrupt::typelevel::Binding> + 'd, rxd: Peri<'d, impl GpioPin>, txd: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, rx_buffer: &'d mut [u8], tx_buffer: &'d mut [u8], @@ -262,11 +262,11 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { ppi_ch1: Peri<'d, impl ConfigurableChannel>, ppi_ch2: Peri<'d, impl ConfigurableChannel>, ppi_group: Peri<'d, impl Group>, - _irq: impl interrupt::typelevel::Binding> + 'd, rxd: Peri<'d, impl GpioPin>, txd: Peri<'d, impl GpioPin>, cts: Peri<'d, impl GpioPin>, rts: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, rx_buffer: &'d mut [u8], tx_buffer: &'d mut [u8], @@ -377,8 +377,8 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> { /// Create a new BufferedUarteTx without hardware flow control. pub fn new( uarte: Peri<'d, U>, - _irq: impl interrupt::typelevel::Binding> + 'd, txd: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, tx_buffer: &'d mut [u8], ) -> Self { @@ -392,9 +392,9 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> { /// Panics if `rx_buffer.len()` is odd. pub fn new_with_cts( uarte: Peri<'d, U>, - _irq: impl interrupt::typelevel::Binding> + 'd, txd: Peri<'d, impl GpioPin>, cts: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, tx_buffer: &'d mut [u8], ) -> Self { @@ -588,9 +588,9 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> { ppi_ch1: Peri<'d, impl ConfigurableChannel>, ppi_ch2: Peri<'d, impl ConfigurableChannel>, ppi_group: Peri<'d, impl Group>, - _irq: impl interrupt::typelevel::Binding> + 'd, rxd: Peri<'d, impl GpioPin>, rts: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, rx_buffer: &'d mut [u8], ) -> Self { diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index b44edfe84..f377df49e 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -155,9 +155,9 @@ impl<'d, T: Instance> Uarte<'d, T> { /// Create a new UARTE without hardware flow control pub fn new( uarte: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rxd: Peri<'d, impl GpioPin>, txd: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, ) -> Self { Self::new_inner(uarte, rxd.into(), txd.into(), None, None, config) @@ -166,11 +166,11 @@ impl<'d, T: Instance> Uarte<'d, T> { /// Create a new UARTE with hardware flow control (RTS/CTS) pub fn new_with_rtscts( uarte: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rxd: Peri<'d, impl GpioPin>, txd: Peri<'d, impl GpioPin>, cts: Peri<'d, impl GpioPin>, rts: Peri<'d, impl GpioPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, ) -> Self { Self::new_inner( diff --git a/embassy-rp/CHANGELOG.md b/embassy-rp/CHANGELOG.md index 8ad3b0b76..7ac0a47cb 100644 --- a/embassy-rp/CHANGELOG.md +++ b/embassy-rp/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - rp235x: add ImageDef features. ([#3890](https://github.com/embassy-rs/embassy/pull/3890)) - doc: Fix "the the" ([#3903](https://github.com/embassy-rs/embassy/pull/3903)) - pio: Add access to DMA engine byte swapping ([#3935](https://github.com/embassy-rs/embassy/pull/3935)) +- Modify BufferedUart initialization to take pins before interrupts ([#3983](https://github.com/embassy-rs/embassy/pull/3983)) ## 0.3.1 - 2025-02-06 diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index 5b5159d22..da18138b5 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs @@ -91,9 +91,9 @@ impl<'d, T: Instance> BufferedUart<'d, T> { /// Create a buffered UART instance. pub fn new( _uart: Peri<'d, T>, - irq: impl Binding>, tx: Peri<'d, impl TxPin>, rx: Peri<'d, impl RxPin>, + irq: impl Binding>, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], config: Config, @@ -110,11 +110,11 @@ impl<'d, T: Instance> BufferedUart<'d, T> { /// Create a buffered UART instance with flow control. pub fn new_with_rtscts( _uart: Peri<'d, T>, - irq: impl Binding>, tx: Peri<'d, impl TxPin>, rx: Peri<'d, impl RxPin>, rts: Peri<'d, impl RtsPin>, cts: Peri<'d, impl CtsPin>, + irq: impl Binding>, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], config: Config, diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md index 10b0739fb..c50ab5294 100644 --- a/embassy-stm32/CHANGELOG.md +++ b/embassy-stm32/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +- Modify BufferedUart initialization to take pins before interrupts ([#3983](https://github.com/embassy-rs/embassy/pull/3983)) + ## 0.2.0 - 2025-01-10 Starting 2025 strong with a release packed with new, exciting good stuff! 🚀 @@ -272,4 +275,4 @@ Misc: ## 0.1.0 - 2024-01-12 -First release. \ No newline at end of file +First release. diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index b1640b6dc..8a33a152c 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -208,11 +208,11 @@ impl<'d> BufferedUart<'d> { /// Create a new bidirectional buffered UART driver pub fn new( peri: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rx: Peri<'d, impl RxPin>, tx: Peri<'d, impl TxPin>, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], + _irq: impl interrupt::typelevel::Binding> + 'd, config: Config, ) -> Result { Self::new_inner( @@ -231,11 +231,11 @@ impl<'d> BufferedUart<'d> { /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins pub fn new_with_rtscts( peri: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rx: Peri<'d, impl RxPin>, tx: Peri<'d, impl TxPin>, rts: Peri<'d, impl RtsPin>, cts: Peri<'d, impl CtsPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], config: Config, @@ -256,10 +256,10 @@ impl<'d> BufferedUart<'d> { /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin pub fn new_with_rts_as_de( peri: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rx: Peri<'d, impl RxPin>, tx: Peri<'d, impl TxPin>, rts: Peri<'d, impl RtsPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], config: Config, @@ -280,10 +280,10 @@ impl<'d> BufferedUart<'d> { /// Create a new bidirectional buffered UART driver with only the request-to-send pin pub fn new_with_rts( peri: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rx: Peri<'d, impl RxPin>, tx: Peri<'d, impl TxPin>, rts: Peri<'d, impl RtsPin>, + _irq: impl interrupt::typelevel::Binding> + 'd, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], config: Config, @@ -305,10 +305,10 @@ impl<'d> BufferedUart<'d> { #[cfg(not(any(usart_v1, usart_v2)))] pub fn new_with_de( peri: Peri<'d, T>, - _irq: impl interrupt::typelevel::Binding> + 'd, rx: Peri<'d, impl RxPin>, tx: Peri<'d, impl TxPin>, de: Peri<'d, impl DePin>, + _irq: impl interrupt::typelevel::Binding> + 'd, tx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8], config: Config, diff --git a/examples/nrf52840/src/bin/buffered_uart.rs b/examples/nrf52840/src/bin/buffered_uart.rs index 77d017964..f0a066818 100644 --- a/examples/nrf52840/src/bin/buffered_uart.rs +++ b/examples/nrf52840/src/bin/buffered_uart.rs @@ -28,9 +28,9 @@ async fn main(_spawner: Spawner) { p.PPI_CH0, p.PPI_CH1, p.PPI_GROUP0, - Irqs, p.P0_08, p.P0_06, + Irqs, config, &mut rx_buffer, &mut tx_buffer, diff --git a/examples/nrf52840/src/bin/uart.rs b/examples/nrf52840/src/bin/uart.rs index 23154672f..f9f8d74ab 100644 --- a/examples/nrf52840/src/bin/uart.rs +++ b/examples/nrf52840/src/bin/uart.rs @@ -17,7 +17,7 @@ async fn main(_spawner: Spawner) { config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; - let mut uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config); + let mut uart = uarte::Uarte::new(p.UARTE0, p.P0_08, p.P0_06, Irqs, config); info!("uarte initialized!"); diff --git a/examples/nrf52840/src/bin/uart_idle.rs b/examples/nrf52840/src/bin/uart_idle.rs index a42e84fa4..00e3ae904 100644 --- a/examples/nrf52840/src/bin/uart_idle.rs +++ b/examples/nrf52840/src/bin/uart_idle.rs @@ -18,7 +18,7 @@ async fn main(_spawner: Spawner) { config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; - let uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config); + let uart = uarte::Uarte::new(p.UARTE0, p.P0_08, p.P0_06, Irqs, config); let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1); info!("uarte initialized!"); diff --git a/examples/nrf52840/src/bin/uart_split.rs b/examples/nrf52840/src/bin/uart_split.rs index 94af4be86..46be8f636 100644 --- a/examples/nrf52840/src/bin/uart_split.rs +++ b/examples/nrf52840/src/bin/uart_split.rs @@ -23,7 +23,7 @@ async fn main(spawner: Spawner) { config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; - let uart = uarte::Uarte::new(p.UARTE0, Irqs, p.P0_08, p.P0_06, config); + let uart = uarte::Uarte::new(p.UARTE0, p.P0_08, p.P0_06, Irqs, config); let (mut tx, rx) = uart.split(); info!("uarte initialized!"); diff --git a/examples/nrf5340/src/bin/uart.rs b/examples/nrf5340/src/bin/uart.rs index 7b41d7463..7e8b8d418 100644 --- a/examples/nrf5340/src/bin/uart.rs +++ b/examples/nrf5340/src/bin/uart.rs @@ -18,7 +18,7 @@ async fn main(_spawner: Spawner) { config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; - let mut uart = uarte::Uarte::new(p.SERIAL0, Irqs, p.P1_00, p.P1_01, config); + let mut uart = uarte::Uarte::new(p.SERIAL0, p.P1_00, p.P1_01, Irqs, config); info!("uarte initialized!"); diff --git a/examples/nrf9151/ns/src/bin/uart.rs b/examples/nrf9151/ns/src/bin/uart.rs index 234ff35f2..6fd377978 100644 --- a/examples/nrf9151/ns/src/bin/uart.rs +++ b/examples/nrf9151/ns/src/bin/uart.rs @@ -17,7 +17,7 @@ async fn main(_spawner: Spawner) { config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; - let mut uart = uarte::Uarte::new(p.SERIAL0, Irqs, p.P0_26, p.P0_27, config); + let mut uart = uarte::Uarte::new(p.SERIAL0, p.P0_26, p.P0_27, Irqs, config); info!("uarte initialized!"); diff --git a/examples/nrf9160/src/bin/modem_tcp_client.rs b/examples/nrf9160/src/bin/modem_tcp_client.rs index 2ba964b1f..a36b14626 100644 --- a/examples/nrf9160/src/bin/modem_tcp_client.rs +++ b/examples/nrf9160/src/bin/modem_tcp_client.rs @@ -127,8 +127,8 @@ async fn main(spawner: Spawner) { let uart = BufferedUarteTx::new( //let trace_uart = BufferedUarteTx::new( unsafe { peripherals::SERIAL0::steal() }, - Irqs, unsafe { peripherals::P0_01::steal() }, + Irqs, //unsafe { peripherals::P0_14::steal() }, config, unsafe { &mut *addr_of_mut!(TRACE_BUF) }, diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs index 468d2b61a..da7e94139 100644 --- a/examples/rp/src/bin/uart_buffered_split.rs +++ b/examples/rp/src/bin/uart_buffered_split.rs @@ -30,7 +30,7 @@ async fn main(spawner: Spawner) { 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 uart = BufferedUart::new(uart, tx_pin, rx_pin, Irqs, tx_buf, rx_buf, Config::default()); let (mut tx, rx) = uart.split(); unwrap!(spawner.spawn(reader(rx))); diff --git a/examples/rp235x/src/bin/uart_buffered_split.rs b/examples/rp235x/src/bin/uart_buffered_split.rs index 468d2b61a..da7e94139 100644 --- a/examples/rp235x/src/bin/uart_buffered_split.rs +++ b/examples/rp235x/src/bin/uart_buffered_split.rs @@ -30,7 +30,7 @@ async fn main(spawner: Spawner) { 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 uart = BufferedUart::new(uart, tx_pin, rx_pin, Irqs, tx_buf, rx_buf, Config::default()); let (mut tx, rx) = uart.split(); unwrap!(spawner.spawn(reader(rx))); diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs index c99807f11..3b6cdad8d 100644 --- a/examples/stm32f4/src/bin/usart_buffered.rs +++ b/examples/stm32f4/src/bin/usart_buffered.rs @@ -21,7 +21,7 @@ async fn main(_spawner: Spawner) { let mut tx_buf = [0u8; 32]; let mut rx_buf = [0u8; 32]; - let mut buf_usart = BufferedUart::new(p.USART3, Irqs, p.PD9, p.PD8, &mut tx_buf, &mut rx_buf, config).unwrap(); + let mut buf_usart = BufferedUart::new(p.USART3, p.PD9, p.PD8, &mut tx_buf, &mut rx_buf, Irqs, config).unwrap(); loop { let buf = buf_usart.fill_buf().await.unwrap(); diff --git a/examples/stm32g0/src/bin/usart_buffered.rs b/examples/stm32g0/src/bin/usart_buffered.rs index c097a0c5a..6d9ec8cb4 100644 --- a/examples/stm32g0/src/bin/usart_buffered.rs +++ b/examples/stm32g0/src/bin/usart_buffered.rs @@ -21,7 +21,7 @@ async fn main(_spawner: Spawner) { config.baudrate = 115200; let mut tx_buf = [0u8; 256]; let mut rx_buf = [0u8; 256]; - let mut usart = BufferedUart::new(p.USART1, Irqs, p.PB7, p.PB6, &mut tx_buf, &mut rx_buf, config).unwrap(); + let mut usart = BufferedUart::new(p.USART1, p.PB7, p.PB6, &mut tx_buf, &mut rx_buf, Irqs, config).unwrap(); usart.write_all(b"Hello Embassy World!\r\n").await.unwrap(); info!("wrote Hello, starting echo"); diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs index 2c96a8bc2..a51ddbcbb 100644 --- a/examples/stm32l0/src/bin/usart_irq.rs +++ b/examples/stm32l0/src/bin/usart_irq.rs @@ -21,7 +21,7 @@ async fn main(_spawner: Spawner) { config.baudrate = 9600; let mut tx_buf = [0u8; 256]; let mut rx_buf = [0u8; 256]; - let mut usart = BufferedUart::new(p.USART2, Irqs, p.PA3, p.PA2, &mut tx_buf, &mut rx_buf, config).unwrap(); + let mut usart = BufferedUart::new(p.USART2, p.PA3, p.PA2, &mut tx_buf, &mut rx_buf, Irqs, config).unwrap(); usart.write_all(b"Hello Embassy World!\r\n").await.unwrap(); info!("wrote Hello, starting echo"); diff --git a/tests/nrf/src/bin/buffered_uart.rs b/tests/nrf/src/bin/buffered_uart.rs index 2eecafb95..8c4827464 100644 --- a/tests/nrf/src/bin/buffered_uart.rs +++ b/tests/nrf/src/bin/buffered_uart.rs @@ -30,9 +30,9 @@ async fn main(_spawner: Spawner) { p.PPI_CH0.reborrow(), p.PPI_CH1.reborrow(), p.PPI_GROUP0.reborrow(), - irqs!(UART0_BUFFERED), peri!(p, PIN_A).reborrow(), peri!(p, PIN_B).reborrow(), + irqs!(UART0_BUFFERED), config.clone(), &mut rx_buffer, &mut tx_buffer, diff --git a/tests/nrf/src/bin/buffered_uart_full.rs b/tests/nrf/src/bin/buffered_uart_full.rs index 09353bbe8..e0f41b891 100644 --- a/tests/nrf/src/bin/buffered_uart_full.rs +++ b/tests/nrf/src/bin/buffered_uart_full.rs @@ -28,9 +28,9 @@ async fn main(_spawner: Spawner) { p.PPI_CH0, p.PPI_CH1, p.PPI_GROUP0, - irqs!(UART0_BUFFERED), peri!(p, PIN_A), peri!(p, PIN_B), + irqs!(UART0_BUFFERED), config.clone(), &mut rx_buffer, &mut tx_buffer, diff --git a/tests/nrf/src/bin/buffered_uart_halves.rs b/tests/nrf/src/bin/buffered_uart_halves.rs index adfba509d..e6debd76e 100644 --- a/tests/nrf/src/bin/buffered_uart_halves.rs +++ b/tests/nrf/src/bin/buffered_uart_halves.rs @@ -28,8 +28,8 @@ async fn main(_spawner: Spawner) { let mut tx = BufferedUarteTx::new( peri!(p, UART1).reborrow(), - irqs!(UART1_BUFFERED), peri!(p, PIN_A).reborrow(), + irqs!(UART1_BUFFERED), config.clone(), &mut tx_buffer, ); diff --git a/tests/nrf/src/bin/uart_split.rs b/tests/nrf/src/bin/uart_split.rs index f24903297..8fe710068 100644 --- a/tests/nrf/src/bin/uart_split.rs +++ b/tests/nrf/src/bin/uart_split.rs @@ -22,9 +22,9 @@ async fn main(_spawner: Spawner) { let uarte = Uarte::new( peri!(p, UART0).reborrow(), - irqs!(UART0), peri!(p, PIN_A).reborrow(), peri!(p, PIN_B).reborrow(), + irqs!(UART0), config.clone(), ); let (mut tx, mut rx) = uarte.split(); diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs index b270a60ce..d5f655e9b 100644 --- a/tests/rp/src/bin/uart_buffered.rs +++ b/tests/rp/src/bin/uart_buffered.rs @@ -75,9 +75,9 @@ async fn main(_spawner: Spawner) { let rx_buf = &mut [0u8; 16]; let mut uart = BufferedUart::new( uart.reborrow(), - Irqs, tx.reborrow(), rx.reborrow(), + Irqs, tx_buf, rx_buf, config, @@ -103,9 +103,9 @@ async fn main(_spawner: Spawner) { let rx_buf = &mut [0u8; 16]; let mut uart = BufferedUart::new( uart.reborrow(), - Irqs, tx.reborrow(), rx.reborrow(), + Irqs, tx_buf, rx_buf, config, @@ -146,9 +146,9 @@ async fn main(_spawner: Spawner) { let rx_buf = &mut [0u8; 16]; let mut uart = BufferedUart::new( uart.reborrow(), - Irqs, tx.reborrow(), rx.reborrow(), + Irqs, tx_buf, rx_buf, config,