Skip to content

Commit 40bd00d

Browse files
bors[bot]Bob McWhirter
andauthored
Merge #193
193: Allow DMA on both halves of a split Serial<USART> separately. r=therealprof a=bobmcwhirter Based upon and dependent upon #186 Co-authored-by: Bob McWhirter <[email protected]>
2 parents 956e345 + 81f90cd commit 40bd00d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/dma/traits.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::*;
22
use crate::{
33
bb,
44
pac::{self, DMA1, DMA2, RCC},
5+
serial::{Rx, Tx},
56
};
67
use core::ops::Deref;
78

@@ -485,19 +486,28 @@ dma_map!(
485486
(Stream4<DMA1>, Channel0, pac::SPI2, MemoryToPeripheral), //SPI2_TX
486487
(Stream5<DMA1>, Channel1, pac::I2C1, PeripheralToMemory), //I2C1_RX
487488
(Stream5<DMA1>, Channel4, pac::USART2, PeripheralToMemory), //USART2_RX
489+
(Stream5<DMA1>, Channel4, Rx<pac::USART2>, PeripheralToMemory), //USART2_RX
488490
(Stream6<DMA1>, Channel4, pac::USART2, MemoryToPeripheral), //USART2_TX
491+
(Stream6<DMA1>, Channel4, Tx<pac::USART2>, MemoryToPeripheral), //USART2_TX
489492
(Stream7<DMA1>, Channel7, pac::I2C2, MemoryToPeripheral), //I2C2_TX
490493
(Stream0<DMA2>, Channel0, pac::ADC1, PeripheralToMemory), //ADC1
491494
(Stream0<DMA2>, Channel3, pac::SPI1, PeripheralToMemory), //SPI1_RX
492495
(Stream1<DMA2>, Channel5, pac::USART6, PeripheralToMemory), //USART6_RX
496+
(Stream1<DMA2>, Channel5, Rx<pac::USART6>, PeripheralToMemory), //USART6_RX
493497
(Stream2<DMA2>, Channel3, pac::SPI1, PeripheralToMemory), //SPI1_RX
494498
(Stream2<DMA2>, Channel4, pac::USART1, PeripheralToMemory), //USART1_RX
499+
(Stream2<DMA2>, Channel4, Rx<pac::USART1>, PeripheralToMemory), //USART1_RX
495500
(Stream2<DMA2>, Channel5, pac::USART6, PeripheralToMemory), //USART6_RX
501+
(Stream2<DMA2>, Channel5, Rx<pac::USART6>, PeripheralToMemory), //USART6_RX
496502
(Stream4<DMA2>, Channel0, pac::ADC1, PeripheralToMemory), //ADC1
497503
(Stream5<DMA2>, Channel4, pac::USART1, PeripheralToMemory), //USART1_RX
504+
(Stream5<DMA2>, Channel4, Rx<pac::USART1>, PeripheralToMemory), //USART1_RX
498505
(Stream6<DMA2>, Channel5, pac::USART6, MemoryToPeripheral), //USART6_TX
506+
(Stream6<DMA2>, Channel5, Tx<pac::USART6>, MemoryToPeripheral), //USART6_TX
499507
(Stream7<DMA2>, Channel4, pac::USART1, MemoryToPeripheral), //USART1_TX
508+
(Stream7<DMA2>, Channel4, Tx<pac::USART1>, MemoryToPeripheral), //USART1_TX
500509
(Stream7<DMA2>, Channel5, pac::USART6, MemoryToPeripheral), //USART6_TX
510+
(Stream7<DMA2>, Channel5, Tx<pac::USART6>, MemoryToPeripheral), //USART6_TX
501511
(
502512
Stream0<DMA2>,
503513
Channel0,

src/serial.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ use crate::gpio::AF11;
374374
use crate::gpio::{Alternate, AF7, AF8};
375375
use crate::rcc::Clocks;
376376

377+
use crate::dma::traits::PeriAddress;
378+
377379
/// Serial error
378380
#[derive(Debug)]
379381
pub enum Error {
@@ -425,11 +427,19 @@ pub mod config {
425427
STOP1P5,
426428
}
427429

430+
pub enum DmaConfig {
431+
None,
432+
Tx,
433+
Rx,
434+
TxRx,
435+
}
436+
428437
pub struct Config {
429438
pub baudrate: Bps,
430439
pub wordlength: WordLength,
431440
pub parity: Parity,
432441
pub stopbits: StopBits,
442+
pub dma: DmaConfig,
433443
}
434444

435445
impl Config {
@@ -480,6 +490,7 @@ pub mod config {
480490
wordlength: WordLength::DataBits8,
481491
parity: Parity::ParityNone,
482492
stopbits: StopBits::STOP1,
493+
dma: DmaConfig::None,
483494
}
484495
}
485496
}
@@ -1442,6 +1453,27 @@ macro_rules! halUsartImpl {
14421453
})
14431454
});
14441455

1456+
match config.dma {
1457+
DmaConfig::Tx => {
1458+
usart.cr3.write(|w| {
1459+
w.dmat().enabled()
1460+
})
1461+
}
1462+
DmaConfig::Rx => {
1463+
usart.cr3.write(|w| {
1464+
w.dmar().enabled()
1465+
})
1466+
}
1467+
DmaConfig::TxRx => {
1468+
usart.cr3.write(|w| {
1469+
w
1470+
.dmar().enabled()
1471+
.dmat().enabled()
1472+
})
1473+
}
1474+
DmaConfig::None => {}
1475+
}
1476+
14451477
Ok(Serial { usart, pins }.config_stop(config))
14461478
}
14471479

@@ -1549,6 +1581,15 @@ macro_rules! halUsartImpl {
15491581
}
15501582
}
15511583

1584+
unsafe impl PeriAddress for Rx<$USARTX> {
1585+
#[inline(always)]
1586+
fn address(&self) -> u32 {
1587+
&(unsafe{ &(*$USARTX::ptr()) }.dr) as *const _ as u32
1588+
}
1589+
1590+
type MemSize = u8;
1591+
}
1592+
15521593
impl<PINS> serial::Write<u8> for Serial<$USARTX, PINS> {
15531594
type Error = Error;
15541595

@@ -1567,6 +1608,15 @@ macro_rules! halUsartImpl {
15671608
}
15681609
}
15691610

1611+
unsafe impl PeriAddress for Tx<$USARTX> {
1612+
#[inline(always)]
1613+
fn address(&self) -> u32 {
1614+
&(unsafe{ &(*$USARTX::ptr()) }.dr) as *const _ as u32
1615+
}
1616+
1617+
type MemSize = u8;
1618+
}
1619+
15701620
impl serial::Write<u8> for Tx<$USARTX> {
15711621
type Error = Error;
15721622

0 commit comments

Comments
 (0)