Skip to content

Enable DMA for USART on STM32F302 devices #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- SPI support for reclock after initialization ([#98](https://github.com/stm32-rs/stm32f3xx-hal/pull/98))
- Support for `stm32f302x6` and `stm32f302x8` devices ([#132](https://github.com/stm32-rs/stm32f3xx-hal/pull/132))
- Support for the onboard real-time clock (RTC) ([#136](https://github.com/stm32-rs/stm32f3xx-hal/pull/136))
- Enable DMA for USART on `stm32f302` devices ([#139](https://github.com/stm32-rs/stm32f3xx-hal/pull/139))

## [v0.5.0] - 2020-07-21

Expand Down
7 changes: 5 additions & 2 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,14 @@ dma!(
);

#[cfg(any(
feature = "stm32f302xb",
feature = "stm32f302xc",
feature = "stm32f302xd",
feature = "stm32f302xe",
feature = "stm32f303xb",
feature = "stm32f303xc",
feature = "stm32f303xd",
feature = "stm32f303xe"
feature = "stm32f303xe",
))]
dma!(
DMA2, dma2, dma2en,
Expand Down Expand Up @@ -527,7 +531,6 @@ macro_rules! on_channel {
};
}

#[cfg(feature = "stm32f303")]
on_channel!(dma1,
serial::Rx<pac::USART1> => C5,
serial::Tx<pac::USART1> => C4,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub use crate::pac::interrupt;
pub mod adc;
#[cfg(feature = "device-selected")]
pub mod delay;
#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
pub mod dma;
#[cfg(feature = "device-selected")]
pub mod flash;
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Prelude

#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
pub use crate::dma::DmaExt as _stm32f3xx_hal_dma_DmaExt;
pub use crate::flash::FlashExt as _stm32f3xx_hal_flash_FlashExt;
pub use crate::gpio::GpioExt as _stm32f3xx_hal_gpio_GpioExt;
Expand Down
28 changes: 6 additions & 22 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use crate::gpio::gpiod;
))]
use crate::gpio::gpioe;

#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
use crate::dma;
#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
use cortex_m::interrupt;

/// Interrupt event
Expand Down Expand Up @@ -363,7 +363,7 @@ macro_rules! hal {

impl blocking::serial::write::Default<u8> for Tx<$USARTX> {}

#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
impl Rx<$USARTX> {
/// Fill the buffer with received data using DMA.
pub fn read_exact<B, C>(
Expand All @@ -384,7 +384,7 @@ macro_rules! hal {
}
}

#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
impl Tx<$USARTX> {
/// Transmit all data in the buffer using DMA.
pub fn write_all<B, C>(
Expand All @@ -405,7 +405,7 @@ macro_rules! hal {
}
}

#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
impl dma::Target for Rx<$USARTX> {
fn enable_dma(&mut self) {
// NOTE(unsafe) critical section prevents races
Expand All @@ -424,7 +424,7 @@ macro_rules! hal {
}
}

#[cfg(feature = "stm32f303")]
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
impl dma::Target for Tx<$USARTX> {
fn enable_dma(&mut self) {
// NOTE(unsafe) critical section prevents races
Expand All @@ -446,24 +446,8 @@ macro_rules! hal {
}
}

#[cfg(any(
feature = "stm32f301",
feature = "stm32f318",
feature = "stm32f303",
feature = "stm32f373",
feature = "stm32f378",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f398"
))]
hal! {
USART1: (usart1, APB2, usart1en, usart1rst, pclk2),
USART2: (usart2, APB1, usart2en, usart2rst, pclk1),
USART3: (usart3, APB1, usart3en, usart3rst, pclk1),
}

#[cfg(any(feature = "stm32f302", feature = "stm32f334"))]
hal! {
USART1: (usart1, APB2, usart1en, usart1rst, pclk2),
USART2: (usart2, APB1, usart2en, usart2rst, pclk1),
}