Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm32/usart: return error instead of panicking on bad baudrate. #1950

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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