Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bobmcwhirter/9253d40f5ec1a513dfd4ef94f4c43f92 to your computer and use it in GitHub Desktop.
Save bobmcwhirter/9253d40f5ec1a513dfd4ef94f4c43f92 to your computer and use it in GitHub Desktop.
diff --git a/src/dma/traits.rs b/src/dma/traits.rs
index 09cf1c3..c49aca3 100644
--- a/src/dma/traits.rs
+++ b/src/dma/traits.rs
@@ -2,6 +2,7 @@ use super::*;
use crate::{
bb,
pac::{self, DMA1, DMA2, RCC},
+ serial::{Rx, Tx, RxDma, TxDma},
};
use core::ops::Deref;
@@ -195,6 +196,24 @@ macro_rules! address {
};
}
+macro_rules! split_usart_address {
+ ($(($USARTX:ty, $register:ident, $size: ty)),+ $(,)*) => {
+ $(
+ unsafe impl PeriAddress for RxDma<$USARTX> {
+ #[inline(always)]
+ fn address(&self) -> u32 {
+ let reg_block = unsafe{ &(*<$USARTX>::ptr()) };
+ let reg = &reg_block.$register;
+ let addr = reg as *const _ as u32;
+ addr
+ }
+
+ type MemSize = $size;
+ }
+ )+
+ };
+}
+
impl Sealed for DMA1 {}
impl Sealed for DMA2 {}
@@ -490,6 +509,7 @@ dma_map!(
(Stream0<DMA2>, Channel0, pac::ADC1, PeripheralToMemory), //ADC1
(Stream0<DMA2>, Channel3, pac::SPI1, PeripheralToMemory), //SPI1_RX
(Stream1<DMA2>, Channel5, pac::USART6, PeripheralToMemory), //USART6_RX
+ (Stream1<DMA2>, Channel5, RxDma<pac::USART6>, PeripheralToMemory), //USART6_RX
(Stream2<DMA2>, Channel3, pac::SPI1, PeripheralToMemory), //SPI1_RX
(Stream2<DMA2>, Channel4, pac::USART1, PeripheralToMemory), //USART1_RX
(Stream2<DMA2>, Channel5, pac::USART6, PeripheralToMemory), //USART6_RX
@@ -498,6 +518,7 @@ dma_map!(
(Stream6<DMA2>, Channel5, pac::USART6, MemoryToPeripheral), //USART6_TX
(Stream7<DMA2>, Channel4, pac::USART1, MemoryToPeripheral), //USART1_TX
(Stream7<DMA2>, Channel5, pac::USART6, MemoryToPeripheral), //USART6_TX
+ (Stream7<DMA2>, Channel5, TxDma<pac::USART6>, MemoryToPeripheral), //USART6_TX
(
Stream0<DMA2>,
Channel0,
@@ -684,6 +705,11 @@ address!(
(pac::USART6, dr, u8),
);
+split_usart_address!(
+ (pac::USART6, dr, u8),
+);
+
+
#[cfg(any(
feature = "stm32f401",
feature = "stm32f411",
diff --git a/src/serial.rs b/src/serial.rs
index 7d95f99..d366773 100644
--- a/src/serial.rs
+++ b/src/serial.rs
@@ -1386,6 +1386,16 @@ pub struct Tx<USART> {
_usart: PhantomData<USART>,
}
+/// Serial receiver
+pub struct RxDma<USART> {
+ _usart: PhantomData<USART>,
+}
+
+/// Serial transmitter
+pub struct TxDma<USART> {
+ _usart: PhantomData<USART>,
+}
+
macro_rules! halUsartImpl {
($(
$USARTX:ident: ($usartX:ident, $apbXenr:ident, $usartXen:ident, $pclkX:ident),
@@ -1516,6 +1526,14 @@ macro_rules! halUsartImpl {
}
}
+ impl Rx<$USARTX> {
+ pub fn with_dma(self) -> RxDma<$USARTX> {
+ RxDma {
+ _usart: PhantomData,
+ }
+ }
+ }
+
impl serial::Read<u8> for Rx<$USARTX> {
type Error = Error;
@@ -1567,6 +1585,14 @@ macro_rules! halUsartImpl {
}
}
+ impl Tx<$USARTX> {
+ pub fn with_dma(self) -> TxDma<$USARTX> {
+ TxDma {
+ _usart: PhantomData,
+ }
+ }
+ }
+
impl serial::Write<u8> for Tx<$USARTX> {
type Error = Error;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment