Merge pull request #1950 from embassy-rs/stm32-test-cleanup
stm32/usart: return error instead of panicking on bad baudrate.
This commit is contained in:
		@@ -118,7 +118,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> {
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.set_config(config)
 | 
					        unwrap!(self.set_config(config))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -126,7 +126,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> {
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.set_config(config)
 | 
					        unwrap!(self.set_config(config))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -134,7 +134,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> {
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.set_config(config)
 | 
					        unwrap!(self.set_config(config))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -147,7 +147,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
 | 
				
			|||||||
        tx_buffer: &'d mut [u8],
 | 
					        tx_buffer: &'d mut [u8],
 | 
				
			||||||
        rx_buffer: &'d mut [u8],
 | 
					        rx_buffer: &'d mut [u8],
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> BufferedUart<'d, T> {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        // UartRx and UartTx have one refcount ea.
 | 
					        // UartRx and UartTx have one refcount ea.
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
@@ -166,7 +166,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
 | 
				
			|||||||
        tx_buffer: &'d mut [u8],
 | 
					        tx_buffer: &'d mut [u8],
 | 
				
			||||||
        rx_buffer: &'d mut [u8],
 | 
					        rx_buffer: &'d mut [u8],
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> BufferedUart<'d, T> {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(cts, rts);
 | 
					        into_ref!(cts, rts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // UartRx and UartTx have one refcount ea.
 | 
					        // UartRx and UartTx have one refcount ea.
 | 
				
			||||||
@@ -194,7 +194,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
 | 
				
			|||||||
        tx_buffer: &'d mut [u8],
 | 
					        tx_buffer: &'d mut [u8],
 | 
				
			||||||
        rx_buffer: &'d mut [u8],
 | 
					        rx_buffer: &'d mut [u8],
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> BufferedUart<'d, T> {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(de);
 | 
					        into_ref!(de);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // UartRx and UartTx have one refcount ea.
 | 
					        // UartRx and UartTx have one refcount ea.
 | 
				
			||||||
@@ -217,7 +217,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
 | 
				
			|||||||
        tx_buffer: &'d mut [u8],
 | 
					        tx_buffer: &'d mut [u8],
 | 
				
			||||||
        rx_buffer: &'d mut [u8],
 | 
					        rx_buffer: &'d mut [u8],
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> BufferedUart<'d, T> {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(_peri, rx, tx);
 | 
					        into_ref!(_peri, rx, tx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let state = T::buffered_state();
 | 
					        let state = T::buffered_state();
 | 
				
			||||||
@@ -230,7 +230,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
 | 
				
			|||||||
        rx.set_as_af(rx.af_num(), AFType::Input);
 | 
					        rx.set_as_af(rx.af_num(), AFType::Input);
 | 
				
			||||||
        tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
 | 
					        tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        configure(r, &config, T::frequency(), T::KIND, true, true);
 | 
					        configure(r, &config, T::frequency(), T::KIND, true, true)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        r.cr1().modify(|w| {
 | 
					        r.cr1().modify(|w| {
 | 
				
			||||||
            #[cfg(lpuart_v2)]
 | 
					            #[cfg(lpuart_v2)]
 | 
				
			||||||
@@ -243,17 +243,17 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
 | 
				
			|||||||
        T::Interrupt::unpend();
 | 
					        T::Interrupt::unpend();
 | 
				
			||||||
        unsafe { T::Interrupt::enable() };
 | 
					        unsafe { T::Interrupt::enable() };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            rx: BufferedUartRx { phantom: PhantomData },
 | 
					            rx: BufferedUartRx { phantom: PhantomData },
 | 
				
			||||||
            tx: BufferedUartTx { phantom: PhantomData },
 | 
					            tx: BufferedUartTx { phantom: PhantomData },
 | 
				
			||||||
        }
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) {
 | 
					    pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) {
 | 
				
			||||||
        (self.tx, self.rx)
 | 
					        (self.tx, self.rx)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -333,7 +333,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -407,7 +407,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,11 +13,10 @@ use futures::future::{select, Either};
 | 
				
			|||||||
use crate::dma::{NoDma, Transfer};
 | 
					use crate::dma::{NoDma, Transfer};
 | 
				
			||||||
use crate::gpio::sealed::AFType;
 | 
					use crate::gpio::sealed::AFType;
 | 
				
			||||||
use crate::interrupt::typelevel::Interrupt;
 | 
					use crate::interrupt::typelevel::Interrupt;
 | 
				
			||||||
#[cfg(not(any(usart_v1, usart_v2)))]
 | 
					 | 
				
			||||||
#[allow(unused_imports)]
 | 
					#[allow(unused_imports)]
 | 
				
			||||||
 | 
					#[cfg(not(any(usart_v1, usart_v2)))]
 | 
				
			||||||
use crate::pac::usart::regs::Isr as Sr;
 | 
					use crate::pac::usart::regs::Isr as Sr;
 | 
				
			||||||
#[cfg(any(usart_v1, usart_v2))]
 | 
					#[cfg(any(usart_v1, usart_v2))]
 | 
				
			||||||
#[allow(unused_imports)]
 | 
					 | 
				
			||||||
use crate::pac::usart::regs::Sr;
 | 
					use crate::pac::usart::regs::Sr;
 | 
				
			||||||
#[cfg(not(any(usart_v1, usart_v2)))]
 | 
					#[cfg(not(any(usart_v1, usart_v2)))]
 | 
				
			||||||
use crate::pac::usart::Lpuart as Regs;
 | 
					use crate::pac::usart::Lpuart as Regs;
 | 
				
			||||||
@@ -76,12 +75,14 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
					#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
				
			||||||
 | 
					#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 | 
				
			||||||
pub enum DataBits {
 | 
					pub enum DataBits {
 | 
				
			||||||
    DataBits8,
 | 
					    DataBits8,
 | 
				
			||||||
    DataBits9,
 | 
					    DataBits9,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
					#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
				
			||||||
 | 
					#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 | 
				
			||||||
pub enum Parity {
 | 
					pub enum Parity {
 | 
				
			||||||
    ParityNone,
 | 
					    ParityNone,
 | 
				
			||||||
    ParityEven,
 | 
					    ParityEven,
 | 
				
			||||||
@@ -89,6 +90,7 @@ pub enum Parity {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
					#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
				
			||||||
 | 
					#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 | 
				
			||||||
pub enum StopBits {
 | 
					pub enum StopBits {
 | 
				
			||||||
    #[doc = "1 stop bit"]
 | 
					    #[doc = "1 stop bit"]
 | 
				
			||||||
    STOP1,
 | 
					    STOP1,
 | 
				
			||||||
@@ -100,6 +102,14 @@ pub enum StopBits {
 | 
				
			|||||||
    STOP1P5,
 | 
					    STOP1P5,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[non_exhaustive]
 | 
				
			||||||
 | 
					#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
				
			||||||
 | 
					#[cfg_attr(feature = "defmt", derive(defmt::Format))]
 | 
				
			||||||
 | 
					pub enum ConfigError {
 | 
				
			||||||
 | 
					    BaudrateTooLow,
 | 
				
			||||||
 | 
					    BaudrateTooHigh,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[non_exhaustive]
 | 
					#[non_exhaustive]
 | 
				
			||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
					#[derive(Clone, Copy, PartialEq, Eq, Debug)]
 | 
				
			||||||
pub struct Config {
 | 
					pub struct Config {
 | 
				
			||||||
@@ -173,8 +183,8 @@ impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma>
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.tx.set_config(config);
 | 
					        unwrap!(self.tx.set_config(config));
 | 
				
			||||||
        self.rx.set_config(config);
 | 
					        unwrap!(self.rx.set_config(config));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -187,7 +197,7 @@ impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> {
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.set_config(config);
 | 
					        unwrap!(self.set_config(config));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -203,7 +213,7 @@ impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> {
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.set_config(config);
 | 
					        unwrap!(self.set_config(config));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -214,7 +224,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
 | 
				
			|||||||
        tx: impl Peripheral<P = impl TxPin<T>> + 'd,
 | 
					        tx: impl Peripheral<P = impl TxPin<T>> + 'd,
 | 
				
			||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
        T::reset();
 | 
					        T::reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -227,7 +237,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
 | 
				
			|||||||
        cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
 | 
					        cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
 | 
				
			||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(cts);
 | 
					        into_ref!(cts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
@@ -245,25 +255,25 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
 | 
				
			|||||||
        tx: impl Peripheral<P = impl TxPin<T>> + 'd,
 | 
					        tx: impl Peripheral<P = impl TxPin<T>> + 'd,
 | 
				
			||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(_peri, tx, tx_dma);
 | 
					        into_ref!(_peri, tx, tx_dma);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let r = T::regs();
 | 
					        let r = T::regs();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
 | 
					        tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        configure(r, &config, T::frequency(), T::KIND, false, true);
 | 
					        configure(r, &config, T::frequency(), T::KIND, false, true)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // create state once!
 | 
					        // create state once!
 | 
				
			||||||
        let _s = T::state();
 | 
					        let _s = T::state();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            tx_dma,
 | 
					            tx_dma,
 | 
				
			||||||
            phantom: PhantomData,
 | 
					            phantom: PhantomData,
 | 
				
			||||||
        }
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -307,7 +317,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
 | 
				
			|||||||
        rx: impl Peripheral<P = impl RxPin<T>> + 'd,
 | 
					        rx: impl Peripheral<P = impl RxPin<T>> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
        T::reset();
 | 
					        T::reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -321,7 +331,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
 | 
				
			|||||||
        rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
 | 
					        rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(rts);
 | 
					        into_ref!(rts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
@@ -340,14 +350,14 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
 | 
				
			|||||||
        rx: impl Peripheral<P = impl RxPin<T>> + 'd,
 | 
					        rx: impl Peripheral<P = impl RxPin<T>> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(peri, rx, rx_dma);
 | 
					        into_ref!(peri, rx, rx_dma);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let r = T::regs();
 | 
					        let r = T::regs();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        rx.set_as_af(rx.af_num(), AFType::Input);
 | 
					        rx.set_as_af(rx.af_num(), AFType::Input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        configure(r, &config, T::frequency(), T::KIND, true, false);
 | 
					        configure(r, &config, T::frequency(), T::KIND, true, false)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        T::Interrupt::unpend();
 | 
					        T::Interrupt::unpend();
 | 
				
			||||||
        unsafe { T::Interrupt::enable() };
 | 
					        unsafe { T::Interrupt::enable() };
 | 
				
			||||||
@@ -355,16 +365,16 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
 | 
				
			|||||||
        // create state once!
 | 
					        // create state once!
 | 
				
			||||||
        let _s = T::state();
 | 
					        let _s = T::state();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            _peri: peri,
 | 
					            _peri: peri,
 | 
				
			||||||
            rx_dma,
 | 
					            rx_dma,
 | 
				
			||||||
            detect_previous_overrun: config.detect_previous_overrun,
 | 
					            detect_previous_overrun: config.detect_previous_overrun,
 | 
				
			||||||
            #[cfg(any(usart_v1, usart_v2))]
 | 
					            #[cfg(any(usart_v1, usart_v2))]
 | 
				
			||||||
            buffered_sr: stm32_metapac::usart::regs::Sr(0),
 | 
					            buffered_sr: stm32_metapac::usart::regs::Sr(0),
 | 
				
			||||||
        }
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -680,7 +690,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        // UartRx and UartTx have one refcount ea.
 | 
					        // UartRx and UartTx have one refcount ea.
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
        T::enable();
 | 
					        T::enable();
 | 
				
			||||||
@@ -699,7 +709,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(cts, rts);
 | 
					        into_ref!(cts, rts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // UartRx and UartTx have one refcount ea.
 | 
					        // UartRx and UartTx have one refcount ea.
 | 
				
			||||||
@@ -726,7 +736,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(de);
 | 
					        into_ref!(de);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // UartRx and UartTx have one refcount ea.
 | 
					        // UartRx and UartTx have one refcount ea.
 | 
				
			||||||
@@ -748,7 +758,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
					        tx_dma: impl Peripheral<P = TxDma> + 'd,
 | 
				
			||||||
        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
					        rx_dma: impl Peripheral<P = RxDma> + 'd,
 | 
				
			||||||
        config: Config,
 | 
					        config: Config,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Result<Self, ConfigError> {
 | 
				
			||||||
        into_ref!(peri, rx, tx, tx_dma, rx_dma);
 | 
					        into_ref!(peri, rx, tx, tx_dma, rx_dma);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let r = T::regs();
 | 
					        let r = T::regs();
 | 
				
			||||||
@@ -770,7 +780,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        configure(r, &config, T::frequency(), T::KIND, true, true);
 | 
					        configure(r, &config, T::frequency(), T::KIND, true, true)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        T::Interrupt::unpend();
 | 
					        T::Interrupt::unpend();
 | 
				
			||||||
        unsafe { T::Interrupt::enable() };
 | 
					        unsafe { T::Interrupt::enable() };
 | 
				
			||||||
@@ -778,7 +788,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
        // create state once!
 | 
					        // create state once!
 | 
				
			||||||
        let _s = T::state();
 | 
					        let _s = T::state();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            tx: UartTx {
 | 
					            tx: UartTx {
 | 
				
			||||||
                tx_dma,
 | 
					                tx_dma,
 | 
				
			||||||
                phantom: PhantomData,
 | 
					                phantom: PhantomData,
 | 
				
			||||||
@@ -790,10 +800,10 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
                #[cfg(any(usart_v1, usart_v2))]
 | 
					                #[cfg(any(usart_v1, usart_v2))]
 | 
				
			||||||
                buffered_sr: stm32_metapac::usart::regs::Sr(0),
 | 
					                buffered_sr: stm32_metapac::usart::regs::Sr(0),
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        }
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -842,18 +852,27 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn reconfigure<T: BasicInstance>(config: &Config) {
 | 
					fn reconfigure<T: BasicInstance>(config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
    T::Interrupt::disable();
 | 
					    T::Interrupt::disable();
 | 
				
			||||||
    let r = T::regs();
 | 
					    let r = T::regs();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let cr = r.cr1().read();
 | 
					    let cr = r.cr1().read();
 | 
				
			||||||
    configure(r, config, T::frequency(), T::KIND, cr.re(), cr.te());
 | 
					    configure(r, config, T::frequency(), T::KIND, cr.re(), cr.te())?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    T::Interrupt::unpend();
 | 
					    T::Interrupt::unpend();
 | 
				
			||||||
    unsafe { T::Interrupt::enable() };
 | 
					    unsafe { T::Interrupt::enable() };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: bool, enable_tx: bool) {
 | 
					fn configure(
 | 
				
			||||||
 | 
					    r: Regs,
 | 
				
			||||||
 | 
					    config: &Config,
 | 
				
			||||||
 | 
					    pclk_freq: Hertz,
 | 
				
			||||||
 | 
					    kind: Kind,
 | 
				
			||||||
 | 
					    enable_rx: bool,
 | 
				
			||||||
 | 
					    enable_tx: bool,
 | 
				
			||||||
 | 
					) -> Result<(), ConfigError> {
 | 
				
			||||||
    if !enable_rx && !enable_tx {
 | 
					    if !enable_rx && !enable_tx {
 | 
				
			||||||
        panic!("USART: At least one of RX or TX should be enabled");
 | 
					        panic!("USART: At least one of RX or TX should be enabled");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -921,7 +940,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
 | 
				
			|||||||
                found_brr = Some(brr);
 | 
					                found_brr = Some(brr);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            panic!("USART: baudrate too high");
 | 
					            return Err(ConfigError::BaudrateTooHigh);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if brr < brr_max {
 | 
					        if brr < brr_max {
 | 
				
			||||||
@@ -933,7 +952,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let brr = found_brr.expect("USART: baudrate too low");
 | 
					    let brr = found_brr.ok_or(ConfigError::BaudrateTooLow)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[cfg(not(usart_v1))]
 | 
					    #[cfg(not(usart_v1))]
 | 
				
			||||||
    let oversampling = if over8 { "8 bit" } else { "16 bit" };
 | 
					    let oversampling = if over8 { "8 bit" } else { "16 bit" };
 | 
				
			||||||
@@ -985,6 +1004,8 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
 | 
				
			|||||||
    r.cr3().modify(|w| {
 | 
					    r.cr3().modify(|w| {
 | 
				
			||||||
        w.set_onebit(config.assume_noise_free);
 | 
					        w.set_onebit(config.assume_noise_free);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod eh02 {
 | 
					mod eh02 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@ use embassy_embedded_hal::SetConfig;
 | 
				
			|||||||
use embassy_hal_internal::PeripheralRef;
 | 
					use embassy_hal_internal::PeripheralRef;
 | 
				
			||||||
use futures::future::{select, Either};
 | 
					use futures::future::{select, Either};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, Error, UartRx};
 | 
					use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, ConfigError, Error, UartRx};
 | 
				
			||||||
use crate::dma::ReadableRingBuffer;
 | 
					use crate::dma::ReadableRingBuffer;
 | 
				
			||||||
use crate::usart::{Regs, Sr};
 | 
					use crate::usart::{Regs, Sr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,7 +20,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUar
 | 
				
			|||||||
    type Config = Config;
 | 
					    type Config = Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn set_config(&mut self, config: &Self::Config) {
 | 
					    fn set_config(&mut self, config: &Self::Config) {
 | 
				
			||||||
        self.set_config(config);
 | 
					        unwrap!(self.set_config(config));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -63,7 +63,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> RingBufferedUartRx<'d, T, RxD
 | 
				
			|||||||
        Err(err)
 | 
					        Err(err)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_config(&mut self, config: &Config) {
 | 
					    pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
 | 
				
			||||||
        self.teardown_uart();
 | 
					        self.teardown_uart();
 | 
				
			||||||
        reconfigure::<T>(config)
 | 
					        reconfigure::<T>(config)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    info!("Hello World!");
 | 
					    info!("Hello World!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.USART1, p.PE1, p.PE0, Irqs, p.DMA1_CH4, NoDma, config);
 | 
					    let mut usart = Uart::new(p.USART1, p.PE1, p.PE0, Irqs, p.DMA1_CH4, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for n in 0u32.. {
 | 
					    for n in 0u32.. {
 | 
				
			||||||
        let mut s: String<128> = String::new();
 | 
					        let mut s: String<128> = String::new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ fn main() -> ! {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, NoDma, NoDma, config);
 | 
					    let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
					    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
				
			||||||
    info!("wrote Hello, starting echo");
 | 
					    info!("wrote Hello, starting echo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let mut tx_buf = [0u8; 32];
 | 
					    let mut tx_buf = [0u8; 32];
 | 
				
			||||||
    let mut rx_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);
 | 
					    let mut buf_usart = BufferedUart::new(p.USART3, Irqs, p.PD9, p.PD8, &mut tx_buf, &mut rx_buf, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
        let buf = buf_usart.fill_buf().await.unwrap();
 | 
					        let buf = buf_usart.fill_buf().await.unwrap();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    info!("Hello World!");
 | 
					    info!("Hello World!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, p.DMA1_CH3, NoDma, config);
 | 
					    let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, p.DMA1_CH3, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for n in 0u32.. {
 | 
					    for n in 0u32.. {
 | 
				
			||||||
        let mut s: String<128> = String::new();
 | 
					        let mut s: String<128> = String::new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ bind_interrupts!(struct Irqs {
 | 
				
			|||||||
async fn main(_spawner: Spawner) {
 | 
					async fn main(_spawner: Spawner) {
 | 
				
			||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, Irqs, p.DMA1_CH1, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, Irqs, p.DMA1_CH1, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for n in 0u32.. {
 | 
					    for n in 0u32.. {
 | 
				
			||||||
        let mut s: String<128> = String::new();
 | 
					        let mut s: String<128> = String::new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ async fn main_task() {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
					    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
				
			||||||
    info!("wrote Hello, starting echo");
 | 
					    info!("wrote Hello, starting echo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ async fn main_task() {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for n in 0u32.. {
 | 
					    for n in 0u32.. {
 | 
				
			||||||
        let mut s: String<128> = String::new();
 | 
					        let mut s: String<128> = String::new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ async fn main(spawner: Spawner) -> ! {
 | 
				
			|||||||
    info!("Hello World!");
 | 
					    info!("Hello World!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, p.GPDMA1_CH1, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, p.GPDMA1_CH1, config).unwrap();
 | 
				
			||||||
    unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
 | 
					    unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let (mut tx, rx) = usart.split();
 | 
					    let (mut tx, rx) = usart.split();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ async fn main_task() {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
					    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
				
			||||||
    info!("wrote Hello, starting echo");
 | 
					    info!("wrote Hello, starting echo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ async fn main_task() {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for n in 0u32.. {
 | 
					    for n in 0u32.. {
 | 
				
			||||||
        let mut s: String<128> = String::new();
 | 
					        let mut s: String<128> = String::new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ async fn main(spawner: Spawner) -> ! {
 | 
				
			|||||||
    info!("Hello World!");
 | 
					    info!("Hello World!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, p.DMA1_CH1, config);
 | 
					    let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, p.DMA1_CH1, config).unwrap();
 | 
				
			||||||
    unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
 | 
					    unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let (mut tx, rx) = usart.split();
 | 
					    let (mut tx, rx) = usart.split();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ bind_interrupts!(struct Irqs {
 | 
				
			|||||||
#[embassy_executor::main]
 | 
					#[embassy_executor::main]
 | 
				
			||||||
async fn main(_spawner: Spawner) {
 | 
					async fn main(_spawner: Spawner) {
 | 
				
			||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
    let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH2, p.DMA1_CH3, Config::default());
 | 
					    let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH2, p.DMA1_CH3, Config::default()).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    usart.write(b"Hello Embassy World!\r\n").await.unwrap();
 | 
					    usart.write(b"Hello Embassy World!\r\n").await.unwrap();
 | 
				
			||||||
    info!("wrote Hello, starting echo");
 | 
					    info!("wrote Hello, starting echo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,13 +18,11 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
    info!("Hi!");
 | 
					    info!("Hi!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static mut TX_BUFFER: [u8; 8] = [0; 8];
 | 
					 | 
				
			||||||
    static mut RX_BUFFER: [u8; 256] = [0; 256];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let mut config = Config::default();
 | 
					    let mut config = Config::default();
 | 
				
			||||||
    config.baudrate = 9600;
 | 
					    config.baudrate = 9600;
 | 
				
			||||||
 | 
					    let mut tx_buf = [0u8; 256];
 | 
				
			||||||
    let mut usart = unsafe { BufferedUart::new(p.USART2, Irqs, p.PA3, p.PA2, &mut TX_BUFFER, &mut RX_BUFFER, config) };
 | 
					    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();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    usart.write_all(b"Hello Embassy World!\r\n").await.unwrap();
 | 
					    usart.write_all(b"Hello Embassy World!\r\n").await.unwrap();
 | 
				
			||||||
    info!("wrote Hello, starting echo");
 | 
					    info!("wrote Hello, starting echo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ fn main() -> ! {
 | 
				
			|||||||
    let p = embassy_stm32::init(Default::default());
 | 
					    let p = embassy_stm32::init(Default::default());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, NoDma, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
					    unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
 | 
				
			||||||
    info!("wrote Hello, starting echo");
 | 
					    info!("wrote Hello, starting echo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    info!("Hello World!");
 | 
					    info!("Hello World!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, p.DMA1_CH3, NoDma, config);
 | 
					    let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, p.DMA1_CH3, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for n in 0u32.. {
 | 
					    for n in 0u32.. {
 | 
				
			||||||
        let mut s: String<128> = String::new();
 | 
					        let mut s: String<128> = String::new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,10 +33,10 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    config2.baudrate = 9600;
 | 
					    config2.baudrate = 9600;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //RX/TX connected to USB/UART Bridge on LoRa-E5 mini v1.0
 | 
					    //RX/TX connected to USB/UART Bridge on LoRa-E5 mini v1.0
 | 
				
			||||||
    let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH3, p.DMA1_CH4, config1);
 | 
					    let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH3, p.DMA1_CH4, config1).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //RX1/TX1 (LPUART) on LoRa-E5 mini v1.0
 | 
					    //RX1/TX1 (LPUART) on LoRa-E5 mini v1.0
 | 
				
			||||||
    let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, Irqs, p.DMA1_CH5, p.DMA1_CH6, config2);
 | 
					    let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, Irqs, p.DMA1_CH5, p.DMA1_CH6, config2).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unwrap!(usart1.write(b"Hello Embassy World!\r\n").await);
 | 
					    unwrap!(usart1.write(b"Hello Embassy World!\r\n").await);
 | 
				
			||||||
    unwrap!(usart2.write(b"Hello Embassy World!\r\n").await);
 | 
					    unwrap!(usart2.write(b"Hello Embassy World!\r\n").await);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        let config = Config::default();
 | 
					        let config = Config::default();
 | 
				
			||||||
        let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
 | 
					        let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // We can't send too many bytes, they have to fit in the FIFO.
 | 
					        // We can't send too many bytes, they have to fit in the FIFO.
 | 
				
			||||||
        // This is because we aren't sending+receiving at the same time.
 | 
					        // This is because we aren't sending+receiving at the same time.
 | 
				
			||||||
@@ -41,7 +41,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    // Test error handling with with an overflow error
 | 
					    // Test error handling with with an overflow error
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        let config = Config::default();
 | 
					        let config = Config::default();
 | 
				
			||||||
        let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
 | 
					        let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Send enough bytes to fill the RX FIFOs off all USART versions.
 | 
					        // Send enough bytes to fill the RX FIFOs off all USART versions.
 | 
				
			||||||
        let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
 | 
					        let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
 | 
				
			||||||
@@ -75,7 +75,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        let mut config = Config::default();
 | 
					        let mut config = Config::default();
 | 
				
			||||||
        config.baudrate = baudrate;
 | 
					        config.baudrate = baudrate;
 | 
				
			||||||
        let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config);
 | 
					        let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let n = (baudrate as usize / 100).max(64);
 | 
					        let n = (baudrate as usize / 100).max(64);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
 | 
				
			|||||||
    let irq = irqs!(UART);
 | 
					    let irq = irqs!(UART);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let config = Config::default();
 | 
					    let config = Config::default();
 | 
				
			||||||
    let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
 | 
					    let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const LEN: usize = 128;
 | 
					    const LEN: usize = 128;
 | 
				
			||||||
    let mut tx_buf = [0; LEN];
 | 
					    let mut tx_buf = [0; LEN];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ async fn main(spawner: Spawner) {
 | 
				
			|||||||
    config.stop_bits = StopBits::STOP1;
 | 
					    config.stop_bits = StopBits::STOP1;
 | 
				
			||||||
    config.parity = Parity::ParityNone;
 | 
					    config.parity = Parity::ParityNone;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
 | 
					    let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
 | 
				
			||||||
    let (tx, rx) = usart.split();
 | 
					    let (tx, rx) = usart.split();
 | 
				
			||||||
    static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
 | 
					    static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
 | 
				
			||||||
    let dma_buf = unsafe { DMA_BUF.as_mut() };
 | 
					    let dma_buf = unsafe { DMA_BUF.as_mut() };
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user