From 5b6ba4e6c8883f95ec0d2b6bd6d0ec25cc37042a Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Tue, 1 Sep 2020 15:16:48 +0800 Subject: [PATCH 01/10] enable dma module for stm32f302xx --- src/dma.rs | 6 +++++- src/lib.rs | 2 +- src/prelude.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dma.rs b/src/dma.rs index 9523c3ced..4a02f0731 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index f20697460..775ff2fa9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 = "stm32f303", feature = "stm32f302"))] pub mod dma; #[cfg(feature = "device-selected")] pub mod flash; diff --git a/src/prelude.rs b/src/prelude.rs index fa17f9449..6722f4007 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,6 +1,6 @@ //! Prelude -#[cfg(feature = "stm32f303")] +#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] 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; From 6b60fcc478c9d1b03b7cbe36d67e4bbb2d82a46a Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Tue, 1 Sep 2020 15:27:22 +0800 Subject: [PATCH 02/10] enable dma in serial for stm32f302xx --- src/serial.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/serial.rs b/src/serial.rs index 3597c1e27..774e0e2ea 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -37,9 +37,9 @@ use crate::gpio::gpiod; ))] use crate::gpio::gpioe; -#[cfg(feature = "stm32f303")] +#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] use crate::dma; -#[cfg(feature = "stm32f303")] +#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] use cortex_m::interrupt; /// Interrupt event @@ -363,7 +363,7 @@ macro_rules! hal { impl blocking::serial::write::Default for Tx<$USARTX> {} - #[cfg(feature = "stm32f303")] + #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] impl Rx<$USARTX> { /// Fill the buffer with received data using DMA. pub fn read_exact( @@ -384,7 +384,7 @@ macro_rules! hal { } } - #[cfg(feature = "stm32f303")] + #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] impl Tx<$USARTX> { /// Transmit all data in the buffer using DMA. pub fn write_all( @@ -405,7 +405,7 @@ macro_rules! hal { } } - #[cfg(feature = "stm32f303")] + #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] impl dma::Target for Rx<$USARTX> { fn enable_dma(&mut self) { // NOTE(unsafe) critical section prevents races @@ -424,7 +424,7 @@ macro_rules! hal { } } - #[cfg(feature = "stm32f303")] + #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] impl dma::Target for Tx<$USARTX> { fn enable_dma(&mut self) { // NOTE(unsafe) critical section prevents races From 9655ed920b4616f3713fa8654c47c0347c9428e0 Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Tue, 1 Sep 2020 15:46:16 +0800 Subject: [PATCH 03/10] enable DMA for usart4 --- src/dma.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/dma.rs b/src/dma.rs index 4a02f0731..eef79881f 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -531,7 +531,7 @@ macro_rules! on_channel { }; } -#[cfg(feature = "stm32f303")] +#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] on_channel!(dma1, serial::Rx => C5, serial::Tx => C4, @@ -540,3 +540,18 @@ on_channel!(dma1, serial::Rx => C3, serial::Tx => C2, ); + +#[cfg(any( + feature = "stm32f302xb", + feature = "stm32f302xc", + feature = "stm32f302xd", + feature = "stm32f302xe", + feature = "stm32f303xb", + feature = "stm32f303xc", + feature = "stm32f303xd", + feature = "stm32f303xe", +))] +on_channel!(dma2, + serial::Rx => C3, + serial::Tx => C5, +); From 1de0666ab571555297839f148ce0c08ee99e627d Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Tue, 1 Sep 2020 16:06:03 +0800 Subject: [PATCH 04/10] enable USART4 for stm32f302xb/c/d/e and stm32f303xb/c/d/e --- src/serial.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/serial.rs b/src/serial.rs index 774e0e2ea..02347d5ec 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -447,12 +447,14 @@ macro_rules! hal { } #[cfg(any( + feature = "stm32f302", feature = "stm32f301", feature = "stm32f318", feature = "stm32f303", feature = "stm32f373", feature = "stm32f378", feature = "stm32f328", + feature = "stm32f334", feature = "stm32f358", feature = "stm32f398" ))] @@ -462,8 +464,16 @@ hal! { USART3: (usart3, APB1, usart3en, usart3rst, pclk1), } -#[cfg(any(feature = "stm32f302", feature = "stm32f334"))] +#[cfg(any( + feature = "stm32f302xb", + feature = "stm32f302xc", + feature = "stm32f302xd", + feature = "stm32f302xe", + feature = "stm32f303xb", + feature = "stm32f303xc", + feature = "stm32f303xd", + feature = "stm32f303xe", +))] hal! { - USART1: (usart1, APB2, usart1en, usart1rst, pclk2), - USART2: (usart2, APB1, usart2en, usart2rst, pclk1), + USART4: (usart4, APB1, usart4en, usart4rst, pclk2), } From 233e8871637e597f87b2f456a57a9abbfc3b9bf1 Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Wed, 2 Sep 2020 00:09:43 +0800 Subject: [PATCH 05/10] added usart5, added features for 358/398 --- src/serial.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/serial.rs b/src/serial.rs index 02347d5ec..848035e41 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -473,7 +473,10 @@ hal! { feature = "stm32f303xc", feature = "stm32f303xd", feature = "stm32f303xe", + feature = "stm32f358", + feature = "stm32f398" ))] hal! { USART4: (usart4, APB1, usart4en, usart4rst, pclk2), + USART5: (usart5, APB1, usart5en, usart5rst, pclk2), } From 5684aaa33c428d3b8fbc7f107ad7f76e1c292bfa Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Wed, 2 Sep 2020 00:16:08 +0800 Subject: [PATCH 06/10] fix clock for usart4/5 --- src/serial.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/serial.rs b/src/serial.rs index 848035e41..9060c8ab2 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -477,6 +477,6 @@ hal! { feature = "stm32f398" ))] hal! { - USART4: (usart4, APB1, usart4en, usart4rst, pclk2), - USART5: (usart5, APB1, usart5en, usart5rst, pclk2), + USART4: (usart4, APB1, usart4en, usart4rst, pclk1), + USART5: (usart5, APB1, usart5en, usart5rst, pclk1), } From da2ded9e53a5eaf820f9e0b3efd6139d0dc26233 Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Sat, 5 Sep 2020 16:28:55 +0800 Subject: [PATCH 07/10] remove USART4/5 should be UART4/5, and missing implementation --- src/dma.rs | 15 --------------- src/serial.rs | 17 ----------------- 2 files changed, 32 deletions(-) diff --git a/src/dma.rs b/src/dma.rs index eef79881f..cf2a307df 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -540,18 +540,3 @@ on_channel!(dma1, serial::Rx => C3, serial::Tx => C2, ); - -#[cfg(any( - feature = "stm32f302xb", - feature = "stm32f302xc", - feature = "stm32f302xd", - feature = "stm32f302xe", - feature = "stm32f303xb", - feature = "stm32f303xc", - feature = "stm32f303xd", - feature = "stm32f303xe", -))] -on_channel!(dma2, - serial::Rx => C3, - serial::Tx => C5, -); diff --git a/src/serial.rs b/src/serial.rs index 9060c8ab2..7096b84c5 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -463,20 +463,3 @@ hal! { USART2: (usart2, APB1, usart2en, usart2rst, pclk1), USART3: (usart3, APB1, usart3en, usart3rst, pclk1), } - -#[cfg(any( - feature = "stm32f302xb", - feature = "stm32f302xc", - feature = "stm32f302xd", - feature = "stm32f302xe", - feature = "stm32f303xb", - feature = "stm32f303xc", - feature = "stm32f303xd", - feature = "stm32f303xe", - feature = "stm32f358", - feature = "stm32f398" -))] -hal! { - USART4: (usart4, APB1, usart4en, usart4rst, pclk1), - USART5: (usart5, APB1, usart5en, usart5rst, pclk1), -} From 64ad4c90949658797f5cdbccf881c84bf8ee4a79 Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Thu, 10 Sep 2020 10:48:05 +0800 Subject: [PATCH 08/10] fix style issues --- src/dma.rs | 1 - src/lib.rs | 2 +- src/prelude.rs | 2 +- src/serial.rs | 12 ++++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/dma.rs b/src/dma.rs index cf2a307df..15ce3621d 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -531,7 +531,6 @@ macro_rules! on_channel { }; } -#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] on_channel!(dma1, serial::Rx => C5, serial::Tx => C4, diff --git a/src/lib.rs b/src/lib.rs index 775ff2fa9..07b3250ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,7 +116,7 @@ pub use crate::pac::interrupt; pub mod adc; #[cfg(feature = "device-selected")] pub mod delay; -#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] +#[cfg(any(feature = "stm32f302", feature = "stm32f303"))] pub mod dma; #[cfg(feature = "device-selected")] pub mod flash; diff --git a/src/prelude.rs b/src/prelude.rs index 6722f4007..02ca404ab 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,6 +1,6 @@ //! Prelude -#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] +#[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; diff --git a/src/serial.rs b/src/serial.rs index 7096b84c5..d0a8d2cb4 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -37,9 +37,9 @@ use crate::gpio::gpiod; ))] use crate::gpio::gpioe; -#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] +#[cfg(any(feature = "stm32f302", feature = "stm32f303"))] use crate::dma; -#[cfg(any(feature = "stm32f303", feature = "stm32f302"))] +#[cfg(any(feature = "stm32f302", feature = "stm32f303"))] use cortex_m::interrupt; /// Interrupt event @@ -363,7 +363,7 @@ macro_rules! hal { impl blocking::serial::write::Default for Tx<$USARTX> {} - #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] + #[cfg(any(feature = "stm32f302", feature = "stm32f303"))] impl Rx<$USARTX> { /// Fill the buffer with received data using DMA. pub fn read_exact( @@ -384,7 +384,7 @@ macro_rules! hal { } } - #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] + #[cfg(any(feature = "stm32f302", feature = "stm32f303"))] impl Tx<$USARTX> { /// Transmit all data in the buffer using DMA. pub fn write_all( @@ -405,7 +405,7 @@ macro_rules! hal { } } - #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] + #[cfg(any(feature = "stm32f302", feature = "stm32f303"))] impl dma::Target for Rx<$USARTX> { fn enable_dma(&mut self) { // NOTE(unsafe) critical section prevents races @@ -424,7 +424,7 @@ macro_rules! hal { } } - #[cfg(any(feature = "stm32f303", feature = "stm32f302"))] + #[cfg(any(feature = "stm32f302", feature = "stm32f303"))] impl dma::Target for Tx<$USARTX> { fn enable_dma(&mut self) { // NOTE(unsafe) critical section prevents races From 7966975e0835a4f84feffd3292d1f4c125238f99 Mon Sep 17 00:00:00 2001 From: Jan Teske Date: Fri, 11 Sep 2020 12:32:49 +0200 Subject: [PATCH 09/10] Remove unnecessary USART cfg gate --- src/serial.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/serial.rs b/src/serial.rs index d0a8d2cb4..6f0740677 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -446,18 +446,6 @@ macro_rules! hal { } } -#[cfg(any( - feature = "stm32f302", - feature = "stm32f301", - feature = "stm32f318", - feature = "stm32f303", - feature = "stm32f373", - feature = "stm32f378", - feature = "stm32f328", - feature = "stm32f334", - feature = "stm32f358", - feature = "stm32f398" -))] hal! { USART1: (usart1, APB2, usart1en, usart1rst, pclk2), USART2: (usart2, APB1, usart2en, usart2rst, pclk1), From e246a3e66864684d2de251b939fb47df5619b2b4 Mon Sep 17 00:00:00 2001 From: Jan Teske Date: Fri, 11 Sep 2020 12:36:04 +0200 Subject: [PATCH 10/10] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5b17252..23f11071a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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