From e6db427c09e5c95c72647cae3fee6c3f253f0327 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Wed, 9 Jan 2019 22:14:29 -0800 Subject: [PATCH] Add support for stm32f031 --- Cargo.toml | 3 ++- src/adc.rs | 21 ++++++++++++++++++--- src/gpio.rs | 10 ++++++++-- src/i2c.rs | 10 ++++++++-- src/lib.rs | 2 +- src/serial.rs | 9 +++++++-- src/timers.rs | 7 ++++++- 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5cf3bbe..75bfa6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,12 +46,13 @@ panic-halt = "0.2.0" [features] device-selected = [] rt = ["stm32f0/rt"] -stm32f042 = ["stm32f0/stm32f0x2", "device-selected"] stm32f030 = ["stm32f0/stm32f0x0", "device-selected"] stm32f030x4 = ["stm32f030x6"] stm32f030x6 = ["stm32f030"] stm32f030x8 = ["stm32f030"] stm32f030xc = ["stm32f030"] +stm32f031 = ["stm32f0/stm32f0x1", "device-selected"] +stm32f042 = ["stm32f0/stm32f0x2", "device-selected"] stm32f070 = ["stm32f0/stm32f0x0", "device-selected"] stm32f070x6 = ["stm32f070"] stm32f070xb = ["stm32f070"] diff --git a/src/adc.rs b/src/adc.rs index cdc7aa5..7bd4085 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -350,17 +350,32 @@ impl VRef { } } -#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))] +#[cfg(any( + feature = "stm32f031", + feature = "stm32f042", + feature = "stm32f072", + feature = "stm32f091", +))] #[derive(Debug, Default)] /// Battery reference voltage (ADC Channel 18) pub struct VBat; -#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))] +#[cfg(any( + feature = "stm32f031", + feature = "stm32f042", + feature = "stm32f072", + feature = "stm32f091", +))] adc_pins!( VBat => 18_u8, ); -#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))] +#[cfg(any( + feature = "stm32f031", + feature = "stm32f042", + feature = "stm32f072", + feature = "stm32f091", +))] impl VBat { /// Init a new VBat pub fn new() -> Self { diff --git a/src/gpio.rs b/src/gpio.rs index f8c40a6..59ee0f4 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -654,8 +654,14 @@ gpio!(GPIOF, gpiof, iopfen, PF, [ PF1: (pf1, 1, Input), PF4: (pf4, 4, Input), PF5: (pf5, 5, Input), - PF6: (pf6, 5, Input), - PF7: (pf7, 5, Input), + PF6: (pf6, 6, Input), + PF7: (pf7, 7, Input), +]); + +#[cfg(feature = "stm32f031")] +gpio!(GPIOF, gpiof, iopfen, PF, [ + PF6: (pf6, 6, Input), + PF7: (pf7, 7, Input), ]); #[cfg(feature = "stm32f070")] diff --git a/src/i2c.rs b/src/i2c.rs index bba521e..217e29c 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -43,6 +43,7 @@ i2c_pins! { #[cfg(any( feature = "stm32f030x6", feature = "stm32f030xc", + feature = "stm32f031", feature = "stm32f042", feature = "stm32f091", ))] @@ -52,7 +53,7 @@ i2c_pins! { sda => [gpioa::PA10>], } } -#[cfg(any(feature = "stm32f042", feature = "stm32f030x6"))] +#[cfg(any(feature = "stm32f031", feature = "stm32f042", feature = "stm32f030x6"))] i2c_pins! { I2C1 => { scl => [gpiob::PB10>], @@ -66,7 +67,12 @@ i2c_pins! { sda => [gpiob::PB14>, gpiof::PF0>], } } -#[cfg(any(feature = "stm32f070", feature = "stm32f072", feature = "stm32f091"))] +#[cfg(any( + feature = "stm32f031", + feature = "stm32f070", + feature = "stm32f072", + feature = "stm32f091", +))] i2c_pins! { I2C1 => { scl => [gpiob::PB6>, gpiob::PB8>], diff --git a/src/lib.rs b/src/lib.rs index abc82b6..0010368 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ pub use stm32f0; #[cfg(any(feature = "stm32f030", feature = "stm32f070"))] pub use stm32f0::stm32f0x0 as stm32; -#[cfg(feature = "stm32f091")] +#[cfg(any(feature = "stm32f031", feature = "stm32f091"))] pub use stm32f0::stm32f0x1 as stm32; #[cfg(any(feature = "stm32f042", feature = "stm32f072"))] diff --git a/src/serial.rs b/src/serial.rs index 1e8fbb1..70dc65f 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -92,14 +92,19 @@ usart_pins! { rx => [gpioa::PA10>, gpiob::PB6>], } } -#[cfg(feature = "stm32f030x6")] +#[cfg(any(feature = "stm32f031", feature = "stm32f030x6"))] usart_pins! { USART1 => { tx => [gpioa::PA2>, gpioa::PA14>], rx => [gpioa::PA3>, gpioa::PA15>], } } -#[cfg(any(feature = "stm32f070", feature = "stm32f072", feature = "stm32f091"))] +#[cfg(any( + feature = "stm32f031", + feature = "stm32f070", + feature = "stm32f072", + feature = "stm32f091", +))] usart_pins! { USART1 => { tx => [gpioa::PA9>, gpiob::PB6>], diff --git a/src/timers.rs b/src/timers.rs index 42c9c6e..c4d2029 100644 --- a/src/timers.rs +++ b/src/timers.rs @@ -244,7 +244,12 @@ timers! { TIM7: (tim7, tim7en, tim7rst, apb1enr, apb1rstr), } -#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))] +#[cfg(any( + feature = "stm32f031", + feature = "stm32f042", + feature = "stm32f072", + feature = "stm32f091", +))] timers! { TIM2: (tim2, tim2en, tim2rst, apb1enr, apb1rstr), }