Skip to content

Commit 8954107

Browse files
author
Mathias Gottschlag
committed
Unlike STM32G0, STM32G4 supports FIFOs for all UARTs, including the LPUART.
This code modifies the configuration structs accordingly and removes the Config type parameter, as it did not have any real use anyways.
1 parent 0bc46f9 commit 8954107

File tree

3 files changed

+139
-93
lines changed

3 files changed

+139
-93
lines changed

src/serial/config.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ impl FifoThreshold {
5555
}
5656
}
5757
#[derive(PartialEq, PartialOrd, Clone, Copy)]
58-
pub struct BasicConfig {
58+
pub struct LowPowerConfig {
5959
pub(crate) baudrate: Bps,
6060
pub(crate) wordlength: WordLength,
6161
pub(crate) parity: Parity,
6262
pub(crate) stopbits: StopBits,
6363
pub(crate) swap: bool,
64+
pub(crate) fifo_enable: bool,
65+
pub(crate) tx_fifo_threshold: FifoThreshold,
66+
pub(crate) rx_fifo_threshold: FifoThreshold,
67+
pub(crate) tx_fifo_interrupt: bool,
68+
pub(crate) rx_fifo_interrupt: bool,
6469
}
6570

6671
#[derive(PartialEq, PartialOrd, Clone, Copy)]
@@ -79,7 +84,7 @@ pub struct FullConfig {
7984
pub(crate) receiver_timeout: Option<u32>,
8085
}
8186

82-
impl BasicConfig {
87+
impl LowPowerConfig {
8388
pub fn baudrate(mut self, baudrate: Bps) -> Self {
8489
self.baudrate = baudrate;
8590
self
@@ -122,6 +127,31 @@ impl BasicConfig {
122127
self.swap = true;
123128
self
124129
}
130+
131+
pub fn fifo_enable(mut self) -> Self {
132+
self.fifo_enable = true;
133+
self
134+
}
135+
136+
pub fn tx_fifo_threshold(mut self, threshold: FifoThreshold) -> Self {
137+
self.tx_fifo_threshold = threshold;
138+
self
139+
}
140+
141+
pub fn rx_fifo_threshold(mut self, threshold: FifoThreshold) -> Self {
142+
self.rx_fifo_threshold = threshold;
143+
self
144+
}
145+
146+
pub fn tx_fifo_enable_interrupt(mut self) -> Self {
147+
self.tx_fifo_interrupt = true;
148+
self
149+
}
150+
151+
pub fn rx_fifo_enable_interrupt(mut self) -> Self {
152+
self.rx_fifo_interrupt = true;
153+
self
154+
}
125155
}
126156

127157
impl FullConfig {
@@ -204,15 +234,20 @@ impl FullConfig {
204234
#[derive(Debug)]
205235
pub struct InvalidConfig;
206236

207-
impl Default for BasicConfig {
208-
fn default() -> BasicConfig {
237+
impl Default for LowPowerConfig {
238+
fn default() -> LowPowerConfig {
209239
let baudrate = 19_200.bps();
210-
BasicConfig {
240+
LowPowerConfig {
211241
baudrate,
212242
wordlength: WordLength::DataBits8,
213243
parity: Parity::ParityNone,
214244
stopbits: StopBits::STOP1,
215245
swap: false,
246+
fifo_enable: false,
247+
tx_fifo_threshold: FifoThreshold::FIFO_8_BYTES,
248+
rx_fifo_threshold: FifoThreshold::FIFO_8_BYTES,
249+
tx_fifo_interrupt: false,
250+
rx_fifo_interrupt: false,
216251
}
217252
}
218253
}

src/serial/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//! UART serial port support.
2+
//!
3+
//! This module provides support for asynchronous communication using UARTs/USARTs/LPUARTs in
4+
//! configurations without hardware flow control. Correct usage is shown by the `uart`,
5+
//! `uart-fifo`, and `uart-dma` examples.
6+
//!
7+
//! **Note that the APB clock needs to be at least 16 times faster than the UART baud rate for all
8+
//! UARTs except for the LPUART.** The latter contains an internal 256x clock multiplier.
9+
//!
10+
//! Most of this code was originally taken from `stm32g0xx-hal`.
111
pub mod config;
212
pub mod usart;
313

0 commit comments

Comments
 (0)