Skip to content

Commit

Permalink
Merge pull request #1950 from embassy-rs/stm32-test-cleanup
Browse files Browse the repository at this point in the history
stm32/usart: return error instead of panicking on bad baudrate.
  • Loading branch information
Dirbaio authored Sep 25, 2023
2 parents c79a84a + 5d8817d commit e8587e2
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 75 deletions.
26 changes: 13 additions & 13 deletions embassy-stm32/src/usart/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> {
type Config = Config;

fn set_config(&mut self, config: &Self::Config) {
self.set_config(config)
unwrap!(self.set_config(config))
}
}

impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> {
type Config = Config;

fn set_config(&mut self, config: &Self::Config) {
self.set_config(config)
unwrap!(self.set_config(config))
}
}

impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> {
type Config = Config;

fn set_config(&mut self, config: &Self::Config) {
self.set_config(config)
unwrap!(self.set_config(config))
}
}

Expand All @@ -147,7 +147,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
tx_buffer: &'d mut [u8],
rx_buffer: &'d mut [u8],
config: Config,
) -> BufferedUart<'d, T> {
) -> Result<Self, ConfigError> {
// UartRx and UartTx have one refcount ea.
T::enable();
T::enable();
Expand All @@ -166,7 +166,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
tx_buffer: &'d mut [u8],
rx_buffer: &'d mut [u8],
config: Config,
) -> BufferedUart<'d, T> {
) -> Result<Self, ConfigError> {
into_ref!(cts, rts);

// UartRx and UartTx have one refcount ea.
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
tx_buffer: &'d mut [u8],
rx_buffer: &'d mut [u8],
config: Config,
) -> BufferedUart<'d, T> {
) -> Result<Self, ConfigError> {
into_ref!(de);

// UartRx and UartTx have one refcount ea.
Expand All @@ -217,7 +217,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
tx_buffer: &'d mut [u8],
rx_buffer: &'d mut [u8],
config: Config,
) -> BufferedUart<'d, T> {
) -> Result<Self, ConfigError> {
into_ref!(_peri, rx, tx);

let state = T::buffered_state();
Expand All @@ -230,7 +230,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
rx.set_as_af(rx.af_num(), AFType::Input);
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| {
#[cfg(lpuart_v2)]
Expand All @@ -243,17 +243,17 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
T::Interrupt::unpend();
unsafe { T::Interrupt::enable() };

Self {
Ok(Self {
rx: BufferedUartRx { phantom: PhantomData },
tx: BufferedUartTx { phantom: PhantomData },
}
})
}

pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) {
(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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
Loading

0 comments on commit e8587e2

Please sign in to comment.