Struct stm32_hal2::usart::Usart
source · pub struct Usart<R> {
pub regs: R,
/* private fields */
}
Expand description
Represents the USART peripheral, for serial communications.
Fields§
§regs: R
Implementations§
source§impl<R> Usart<R>where
R: Deref<Target = RegisterBlock> + RccPeriph + BaudPeriph,
impl<R> Usart<R>where
R: Deref<Target = RegisterBlock> + RccPeriph + BaudPeriph,
sourcepub fn new(regs: R, baud: u32, config: UsartConfig, clock_cfg: &Clocks) -> Self
pub fn new(regs: R, baud: u32, config: UsartConfig, clock_cfg: &Clocks) -> Self
Initialize a U[s]ART peripheral, including configuration register writes, and enabling and
resetting its RCC peripheral clock. baud
is the baud rate, in bytes-per-second.
sourcepub fn set_baud(
&mut self,
baud: u32,
clock_cfg: &Clocks
) -> Result<(), UartError>
pub fn set_baud( &mut self, baud: u32, clock_cfg: &Clocks ) -> Result<(), UartError>
Set the BAUD rate. Called during init, and can be called later to change BAUD during program execution.
sourcepub fn write(&mut self, data: &[u8]) -> Result<(), UartError>
pub fn write(&mut self, data: &[u8]) -> Result<(), UartError>
Transmit data, as a sequence of u8. See L44 RM, section 38.5.2: “Character transmission procedure”
sourcepub fn write_one(&mut self, word: u8)
pub fn write_one(&mut self, word: u8)
Write a single word, without waiting until ready for the next. Compared to the write()
function, this
does not block.
sourcepub fn read(&mut self, buf: &mut [u8]) -> Result<(), UartError>
pub fn read(&mut self, buf: &mut [u8]) -> Result<(), UartError>
Receive data into a u8 buffer. See L44 RM, section 38.5.3: “Character reception procedure”
sourcepub fn read_one(&mut self) -> u8
pub fn read_one(&mut self) -> u8
Read a single word, without waiting until ready for the next. Compared to the read()
function, this
does not block.
sourcepub unsafe fn write_dma(
&mut self,
buf: &[u8],
channel: DmaChannel,
channel_cfg: ChannelCfg,
dma_periph: DmaPeriph
)
pub unsafe fn write_dma( &mut self, buf: &[u8], channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )
Transmit data using DMA. (L44 RM, section 38.5.15)
Note that the channel
argument is unused on F3 and L4, since it is hard-coded,
and can’t be configured using the DMAMUX peripheral. (dma::mux()
fn).
sourcepub unsafe fn read_dma(
&mut self,
buf: &mut [u8],
channel: DmaChannel,
channel_cfg: ChannelCfg,
dma_periph: DmaPeriph
)
pub unsafe fn read_dma( &mut self, buf: &mut [u8], channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )
Receive data using DMA. (L44 RM, section 38.5.15; G4 RM section 37.5.19.
Note that the channel
argument is unused on F3 and L4, since it is hard-coded,
and can’t be configured using the DMAMUX peripheral. (dma::mux()
fn).
sourcepub fn enable_interrupt(&mut self, interrupt: UsartInterrupt)
pub fn enable_interrupt(&mut self, interrupt: UsartInterrupt)
Enable a specific type of interrupt. See G4 RM, Table 349: USART interrupt requests.
If Some
, the inner value of CharDetect
sets the address of the char to match.
If None
, the interrupt is enabled without changing the char to match.
sourcepub fn disable_interrupt(&mut self, interrupt: UsartInterrupt)
pub fn disable_interrupt(&mut self, interrupt: UsartInterrupt)
Disable a specific type of interrupt. See G4 RM, Table 349: USART interrupt requests.
Note that the inner value of CharDetect
doesn’t do anything here.
sourcepub fn read_status(&self) -> u32
pub fn read_status(&self) -> u32
Print the (raw) contents of the status register.
sourcepub fn clear_interrupt(&mut self, interrupt: UsartInterrupt)
pub fn clear_interrupt(&mut self, interrupt: UsartInterrupt)
Clears the interrupt pending flag for a specific type of interrupt. Note that
it can also clear error flags, like Overrun and framing errors. See G4 RM,
Table 349: USART interrupt requests.
Note that the inner value of CharDetect
doesn’t do anything here.
sourcepub fn check_status_flag(&mut self, flag: UsartInterrupt) -> bool
pub fn check_status_flag(&mut self, flag: UsartInterrupt) -> bool
Checks if a given status flag is set. Returns true
if the status flag is set. Note that this preforms
a read each time called. If checking multiple flags, this isn’t optimal.