Struct stm32wlxx_hal::uart::LpUart
source · pub struct LpUart<RX, TX> { /* private fields */ }
Expand description
Low-power UART driver.
Implementations§
source§impl LpUart<NoRx, NoTx>
impl LpUart<NoRx, NoTx>
sourcepub fn new(
uart: LPUART,
baud: u32,
clk: Clk,
rcc: &mut RCC
) -> LpUart<NoRx, NoTx>
pub fn new( uart: LPUART, baud: u32, clk: Clk, rcc: &mut RCC ) -> LpUart<NoRx, NoTx>
Create a new LPUART driver from a LPUART peripheral.
This will enable clocks and reset the LPUART peripheral.
Panics
- Source frequency is not between 3× and 4096× the baud rate
- The derived baud rate register value is less than
0x300
Example
use stm32wlxx_hal::{
pac,
uart::{self, LpUart, NoRx, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let uart: LpUart<NoRx, NoTx> = LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC);
source§impl LpUart<NoRx, NoTx>
impl LpUart<NoRx, NoTx>
sourcepub fn enable_clock(rcc: &mut RCC)
pub fn enable_clock(rcc: &mut RCC)
sourcepub unsafe fn disable_clock(rcc: &mut RCC)
pub unsafe fn disable_clock(rcc: &mut RCC)
Disable the UART clock.
Safety
- You are responsible for ensuring the UART is in a state where the clock can be disabled without entering an error state.
- You cannot use the UART while the clock is disabled.
- You are responsible for re-enabling the clock before resuming use of the UART.
- You are responsible for setting up anything that may have lost state while the clock was disabled.
source§impl LpUart<NoRx, NoTx>
impl LpUart<NoRx, NoTx>
sourcepub unsafe fn steal() -> LpUart<NoRx, NoTx>
pub unsafe fn steal() -> LpUart<NoRx, NoTx>
Steal the UART peripheral from whatever is currently using it.
This will not initialize the peripheral (unlike new
).
Safety
- Ensure that the code stealing the UART has exclusive access to the peripheral. Singleton checks are bypassed with this method.
- You are responsible for setting up the UART correctly.
Example
use stm32wlxx_hal::{
pac,
uart::{LpUart, NoRx, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
LpUart::enable_clock(&mut dp.RCC);
// safety:
// 1. Nothing else is using the LPUART in this code.
// 2. This code performs setup for the LPUART.
unsafe { LpUart::pulse_reset(&mut dp.RCC) };
// safety:
// 1. Nothing else is using the LPUART in this code.
// 2. The LPUART has been setup, clocks are enabled and the LPUART has been reset.
let mut lpuart: LpUart<NoRx, NoTx> = unsafe { LpUart::steal() };
source§impl<RX, TX> LpUart<RX, TX>
impl<RX, TX> LpUart<RX, TX>
sourcepub fn free(self) -> LPUART
pub fn free(self) -> LPUART
Free the UART peripheral from the driver.
Example
use stm32wlxx_hal::{
pac,
uart::{self, LpUart, NoRx, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let lpuart: pac::LPUART = dp.LPUART;
let lpuart: LpUart<NoRx, NoTx> =
LpUart::new(lpuart, 115_200, uart::Clk::Hsi16, &mut dp.RCC);
// ... use LPUART
let lpuart: pac::LPUART = lpuart.free();
source§impl<RX> LpUart<RX, NoTx>
impl<RX> LpUart<RX, NoTx>
sourcepub fn enable_tx<TX: LpUart1Tx>(
self,
tx: TX,
cs: &CriticalSection
) -> LpUart<RX, TX>
pub fn enable_tx<TX: LpUart1Tx>( self, tx: TX, cs: &CriticalSection ) -> LpUart<RX, TX>
Enable the UART transmitter.
Example
use stm32wlxx_hal::{
cortex_m,
gpio::{pins, PortB},
pac,
uart::{self, LpUart, NoRx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let gpiob: PortB = PortB::split(dp.GPIOB, &mut dp.RCC);
let uart: LpUart<NoRx, pins::B11> = cortex_m::interrupt::free(|cs| {
LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC)
.enable_tx(gpiob.b11, cs)
});
source§impl<RX> LpUart<RX, NoTx>
impl<RX> LpUart<RX, NoTx>
sourcepub fn enable_tx_dma<TxPin: LpUart1Tx, TxDma: DmaCh>(
self,
tx: TxPin,
tx_dma: TxDma,
cs: &CriticalSection
) -> LpUart<RX, (TxPin, TxDma)>
pub fn enable_tx_dma<TxPin: LpUart1Tx, TxDma: DmaCh>( self, tx: TxPin, tx_dma: TxDma, cs: &CriticalSection ) -> LpUart<RX, (TxPin, TxDma)>
Enable the UART transmitter with a DMA channel.
Example
use stm32wlxx_hal::{
cortex_m,
dma::{AllDma, Dma2Ch7},
gpio::{pins, PortB},
pac,
uart::{self, LpUart, NoRx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let dma: AllDma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let gpiob: PortB = PortB::split(dp.GPIOB, &mut dp.RCC);
let uart: LpUart<NoRx, (pins::B11, Dma2Ch7)> = cortex_m::interrupt::free(|cs| {
LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC)
.enable_tx_dma(gpiob.b11, dma.d2.c7, cs)
});
source§impl<RX, TX> LpUart<RX, TX>
impl<RX, TX> LpUart<RX, TX>
sourcepub fn disable_tx(self) -> (LpUart<RX, NoTx>, TX)
pub fn disable_tx(self) -> (LpUart<RX, NoTx>, TX)
Disable the UART transmitter.
Example
use stm32wlxx_hal::{
cortex_m,
gpio::{pins, PortB},
pac,
uart::{self, LpUart, NoRx, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let gpiob: PortB = PortB::split(dp.GPIOB, &mut dp.RCC);
let uart: LpUart<NoRx, pins::B11> = cortex_m::interrupt::free(|cs| {
LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC)
.enable_tx(gpiob.b11, cs)
});
let (uart, b11): (LpUart<NoRx, NoTx>, pins::B11) = uart.disable_tx();
source§impl<TX> LpUart<NoRx, TX>
impl<TX> LpUart<NoRx, TX>
sourcepub fn enable_rx<RX: LpUart1Rx>(
self,
rx: RX,
cs: &CriticalSection
) -> LpUart<RX, TX>
pub fn enable_rx<RX: LpUart1Rx>( self, rx: RX, cs: &CriticalSection ) -> LpUart<RX, TX>
Enable the UART receiver.
Example
use stm32wlxx_hal::{
cortex_m,
gpio::{pins, PortB},
pac,
uart::{self, LpUart, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let gpiob: PortB = PortB::split(dp.GPIOB, &mut dp.RCC);
let uart: LpUart<pins::B10, NoTx> = cortex_m::interrupt::free(|cs| {
LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC)
.enable_rx(gpiob.b10, cs)
});
source§impl<TX> LpUart<NoRx, TX>
impl<TX> LpUart<NoRx, TX>
sourcepub fn enable_rx_dma<RxPin: LpUart1Rx, RxDma: DmaCh>(
self,
rx: RxPin,
rx_dma: RxDma,
cs: &CriticalSection
) -> LpUart<(RxPin, RxDma), TX>
pub fn enable_rx_dma<RxPin: LpUart1Rx, RxDma: DmaCh>( self, rx: RxPin, rx_dma: RxDma, cs: &CriticalSection ) -> LpUart<(RxPin, RxDma), TX>
Enable the UART receiver with a DMA channel.
Example
use stm32wlxx_hal::{
dma::{AllDma, Dma2Ch2},
gpio::{pins, PortB},
pac,
uart::{self, LpUart, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let dma: AllDma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let gpiob: PortB = PortB::split(dp.GPIOB, &mut dp.RCC);
let uart: LpUart<(pins::B10, Dma2Ch2), NoTx> = cortex_m::interrupt::free(|cs| {
LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC)
.enable_rx_dma(gpiob.b10, dma.d2.c2, cs)
});
source§impl<RX, TX> LpUart<RX, TX>
impl<RX, TX> LpUart<RX, TX>
sourcepub fn disable_rx(self) -> (LpUart<NoRx, TX>, RX)
pub fn disable_rx(self) -> (LpUart<NoRx, TX>, RX)
Disable the UART receiver.
Example
use stm32wlxx_hal::{
gpio::{pins, PortB},
pac,
uart::{self, LpUart, NoRx, NoTx},
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
// enable the HSI16 source clock
dp.RCC.cr.modify(|_, w| w.hsion().set_bit());
while dp.RCC.cr.read().hsirdy().is_not_ready() {}
let gpiob: PortB = PortB::split(dp.GPIOB, &mut dp.RCC);
let uart: LpUart<pins::B10, NoTx> = cortex_m::interrupt::free(|cs| {
LpUart::new(dp.LPUART, 115_200, uart::Clk::Hsi16, &mut dp.RCC)
.enable_rx(gpiob.b10, cs)
});
let (uart, b10): (LpUart<NoRx, NoTx>, pins::B10) = uart.disable_rx();
Trait Implementations§
source§impl<RX, TX> Write for LpUart<RX, TX>where
LpUart<RX, TX>: Write<u8>,
impl<RX, TX> Write for LpUart<RX, TX>where LpUart<RX, TX>: Write<u8>,
source§impl<RX, TxPin, TxDma> Write<u8> for LpUart<RX, (TxPin, TxDma)>where
TxPin: LpUart1Tx,
TxDma: DmaCh,
impl<RX, TxPin, TxDma> Write<u8> for LpUart<RX, (TxPin, TxDma)>where TxPin: LpUart1Tx, TxDma: DmaCh,
Auto Trait Implementations§
impl<RX, TX> RefUnwindSafe for LpUart<RX, TX>where RX: RefUnwindSafe, TX: RefUnwindSafe,
impl<RX, TX> Send for LpUart<RX, TX>where RX: Send, TX: Send,
impl<RX, TX> !Sync for LpUart<RX, TX>
impl<RX, TX> Unpin for LpUart<RX, TX>where RX: Unpin, TX: Unpin,
impl<RX, TX> UnwindSafe for LpUart<RX, TX>where RX: UnwindSafe, TX: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more