Skip to content

Commit

Permalink
Use correct PACs for stm32f318 and stm32f378
Browse files Browse the repository at this point in the history
According to the "Supported Devices" table in the stm32f3 crate's README
(https://crates.io/crates/stm32f3) we were using the wrong PAC module
(`stm32f3x8`) for both smt32f318 and stm32f378. Because of that we also
supported some peripherals for these devices that are not actually
available for them.

This commit adds the correct PAC modules for the two devices in question
and fixes up the HAL code to use the correct peripherals.
  • Loading branch information
teskje committed Jul 18, 2020
1 parent 59f2221 commit 3103adf
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 107 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ let clocks = rcc
- Split up `stm32f302` into sub-targets `stm32f302xb`,`stm32f302xc`,`stm32f302xd`,`stm32f302xe`
- Bump `stm32f3` dependency to `0.11.0` ([#97](https://github.com/stm32-rs/stm32f3xx-hal/pull/97))
- The `stm32f3` reexport is now renamed from `stm32` to `pac` ([#101](https://github.com/stm32-rs/stm32f3xx-hal/pull/101))
- The correct `stm32f3` modules are now used for the `stm32f318` and `stm32f738`
targets. As a result, some previously (wrongly) supported peripherals have
been removed from these targets.

## [v0.4.3] - 2020-04-11

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ direct-call-deprecated = []
rt = ["stm32f3/rt"]
# Any Changes here should be mirrored in README.md and src/lib.rs
stm32f301 = ["stm32f3/stm32f301", "device-selected"]
stm32f318 = ["stm32f3/stm32f3x8", "device-selected"]
stm32f318 = ["stm32f3/stm32f301", "device-selected"]
stm32f302 = ["stm32f3/stm32f302", "direct-call-deprecated"]
stm32f302xb = ["stm32f302", "device-selected"]
stm32f302xc = ["stm32f302", "device-selected"]
Expand All @@ -71,7 +71,7 @@ stm32f303xe = ["stm32f303", "stm32-usbd/ram_access_2x16", "device-selected"]
stm32f303x6 = ["stm32f303", "device-selected"]
stm32f303x8 = ["stm32f303", "device-selected"]
stm32f373 = ["stm32f3/stm32f373", "device-selected"]
stm32f378 = ["stm32f3/stm32f3x8", "device-selected"]
stm32f378 = ["stm32f3/stm32f373", "device-selected"]
stm32f334 = ["stm32f3/stm32f3x4", "device-selected"]
stm32f328 = ["stm32f3/stm32f3x8", "device-selected"]
stm32f358 = ["stm32f3/stm32f3x8", "device-selected"]
Expand Down
115 changes: 45 additions & 70 deletions src/gpio.rs

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::gpio::gpiob::{PB6, PB7, PB8, PB9};
feature = "stm32f303xc",
feature = "stm32f303xd",
feature = "stm32f303xe",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f398",
Expand Down Expand Up @@ -61,7 +60,6 @@ unsafe impl SclPin<I2C2> for PF1<AF4> {}
feature = "stm32f303xc",
feature = "stm32f303xd",
feature = "stm32f303xe",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f398",
Expand Down
12 changes: 3 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub use embedded_hal as hal;
pub use nb;
pub use nb::block;

#[cfg(feature = "stm32f301")]
#[cfg(any(feature = "stm32f301", feature = "stm32f318"))]
pub use stm32f3::stm32f301 as pac;

#[cfg(feature = "stm32f302")]
Expand All @@ -91,19 +91,13 @@ pub use stm32f3::stm32f302 as pac;
#[cfg(feature = "stm32f303")]
pub use stm32f3::stm32f303 as pac;

#[cfg(feature = "stm32f373")]
#[cfg(any(feature = "stm32f373", feature = "stm32f378"))]
pub use stm32f3::stm32f373 as pac;

#[cfg(feature = "stm32f334")]
pub use stm32f3::stm32f3x4 as pac;

#[cfg(any(
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398"
))]
#[cfg(any(feature = "stm32f328", feature = "stm32f358", feature = "stm32f398"))]
pub use stm32f3::stm32f3x8 as pac;

#[cfg(feature = "device-selected")]
Expand Down
3 changes: 1 addition & 2 deletions src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl APB2 {
const HSI: u32 = 8_000_000; // Hz

// some microcontrollers do not have USB
#[cfg(any(feature = "stm32f301", feature = "stm32f334",))]
#[cfg(any(feature = "stm32f301", feature = "stm32f318", feature = "stm32f334",))]
mod usb_clocking {
use crate::rcc::PllConfig;

Expand All @@ -116,7 +116,6 @@ mod usb_clocking {
}

#[cfg(any(
feature = "stm32f318",
feature = "stm32f302",
feature = "stm32f303",
feature = "stm32f373",
Expand Down
6 changes: 1 addition & 5 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::gpio::gpioa::{PA5, PA6, PA7};
feature = "stm32f328",
feature = "stm32f334",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398"
))]
use crate::gpio::gpiob::PB13;
Expand All @@ -38,7 +37,6 @@ use crate::rcc::APB1;
#[cfg(any(
feature = "stm32f302",
feature = "stm32f303",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f334",
feature = "stm32f358",
Expand Down Expand Up @@ -83,7 +81,6 @@ unsafe impl SckPin<SPI1> for PA5<AF5> {}
feature = "stm32f328",
feature = "stm32f334",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398"
))]
unsafe impl SckPin<SPI2> for PB13<AF5> {}
Expand Down Expand Up @@ -255,7 +252,7 @@ hal! {
SPI1: (spi1, APB2, spi1en, spi1rst, pclk2),
}

#[cfg(feature = "stm32f301")]
#[cfg(any(feature = "stm32f301", feature = "stm32f318"))]
hal! {
SPI2: (spi2, APB1, spi2en, spi2rst, pclk1),
SPI3: (spi3, APB1, spi3en, spi3rst, pclk1),
Expand All @@ -264,7 +261,6 @@ hal! {
#[cfg(any(
feature = "stm32f302",
feature = "stm32f303",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f373",
Expand Down
26 changes: 9 additions & 17 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@
use crate::hal::timer::{CountDown, Periodic};
#[cfg(any(
feature = "stm32f301",
feature = "stm32f302",
feature = "stm32f303",
feature = "stm32f334",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398",
))]
use crate::pac::TIM1;
#[cfg(any(
feature = "stm32f303",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398"
))]
use crate::pac::TIM20;
#[cfg(any(
feature = "stm32f303",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f373",
Expand All @@ -33,19 +30,16 @@ use crate::pac::TIM20;
use crate::pac::TIM4;
#[cfg(any(
feature = "stm32f303",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398",
))]
use crate::pac::TIM8;
#[cfg(feature = "stm32f373")]
#[cfg(any(feature = "stm32f373", feature = "stm32f378"))]
use crate::pac::{TIM12, TIM13, TIM14, TIM18, TIM19, TIM5};
use crate::pac::{TIM15, TIM16, TIM17, TIM2, TIM6};
#[cfg(any(
feature = "stm32f303",
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f334",
feature = "stm32f358",
Expand Down Expand Up @@ -189,8 +183,12 @@ macro_rules! hal {
}
}

#[cfg(feature = "stm32f301")]
#[cfg(any(feature = "stm32f301", feature = "stm32f318"))]
hal! {
{
TIM1: (tim1, tim1en, tim1rst),
APB2: (apb2, pclk2),
},
{
TIM2: (tim2, tim2en, tim2rst),
APB1: (apb1, pclk1),
Expand Down Expand Up @@ -325,7 +323,7 @@ hal! {
},
}

#[cfg(feature = "stm32f373")]
#[cfg(any(feature = "stm32f373", feature = "stm32f378"))]
hal! {
{
TIM2: (tim2, tim2en, tim2rst),
Expand Down Expand Up @@ -385,13 +383,7 @@ hal! {
},
}

#[cfg(any(
feature = "stm32f318",
feature = "stm32f328",
feature = "stm32f358",
feature = "stm32f378",
feature = "stm32f398"
))]
#[cfg(any(feature = "stm32f328", feature = "stm32f358", feature = "stm32f398"))]
hal! {
{
TIM1: (tim1, tim1en, tim1rst),
Expand Down

0 comments on commit 3103adf

Please sign in to comment.