diff options
| author | Timo Kröger <[email protected]> | 2021-07-23 14:24:38 +0200 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2021-07-23 17:54:13 +0200 |
| commit | 5ac91933ff0e4643823c77b357d90e82007fc9fb (patch) | |
| tree | 5f252cde081a002f09659059bf746bf2896a3d16 /examples/stm32l4 | |
| parent | ec5d44333ab6c0711424699efb2e782baf0124c7 (diff) | |
stm32: No need to enable GPIO clocks manually
Diffstat (limited to 'examples/stm32l4')
| -rw-r--r-- | examples/stm32l4/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/adc.rs | 40 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/blinky.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/button.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/button_exti.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/dac.rs | 40 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/spi.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/usart.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/usart_dma.rs | 9 |
9 files changed, 25 insertions, 110 deletions
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 069c1434d..41c189c69 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -21,7 +21,6 @@ embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "def | |||
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi"] } |
| 23 | embassy-extras = {version = "0.1.0", path = "../../embassy-extras" } | 23 | embassy-extras = {version = "0.1.0", path = "../../embassy-extras" } |
| 24 | stm32l4 = { version = "0.13", features = ["stm32l4x5" ] } | ||
| 25 | stm32l4xx-hal = { version = "0.6.0", features = ["stm32l4x5"] } | 24 | stm32l4xx-hal = { version = "0.6.0", features = ["stm32l4x5"] } |
| 26 | 25 | ||
| 27 | defmt = "0.2.0" | 26 | defmt = "0.2.0" |
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index a3c44d3c1..6894d664a 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs | |||
| @@ -11,11 +11,10 @@ mod example_common; | |||
| 11 | 11 | ||
| 12 | use example_common::*; | 12 | use example_common::*; |
| 13 | 13 | ||
| 14 | use cortex_m_rt::entry; | ||
| 15 | //use stm32f4::stm32f429 as pac; | ||
| 16 | use cortex_m::delay::Delay; | 14 | use cortex_m::delay::Delay; |
| 15 | use cortex_m_rt::entry; | ||
| 17 | use embassy_stm32::adc::{Adc, Resolution}; | 16 | use embassy_stm32::adc::{Adc, Resolution}; |
| 18 | use stm32l4::stm32l4x5 as pac; | 17 | use embassy_stm32::pac; |
| 19 | use stm32l4xx_hal::prelude::*; | 18 | use stm32l4xx_hal::prelude::*; |
| 20 | use stm32l4xx_hal::rcc::PllSource; | 19 | use stm32l4xx_hal::rcc::PllSource; |
| 21 | 20 | ||
| @@ -40,31 +39,16 @@ fn main() -> ! { | |||
| 40 | .pll_source(PllSource::HSI16) | 39 | .pll_source(PllSource::HSI16) |
| 41 | .freeze(&mut flash.acr, &mut pwr); | 40 | .freeze(&mut flash.acr, &mut pwr); |
| 42 | 41 | ||
| 43 | let pp = unsafe { pac::Peripherals::steal() }; | 42 | unsafe { |
| 44 | 43 | pac::RCC.ccipr().modify(|w| { | |
| 45 | pp.RCC.ccipr.modify(|_, w| { | 44 | w.set_adcsel(0b11); |
| 46 | unsafe { | 45 | }); |
| 47 | w.adcsel().bits(0b11); | 46 | pac::DBGMCU.cr().modify(|w| { |
| 48 | } | 47 | w.set_dbg_sleep(true); |
| 49 | w | 48 | w.set_dbg_standby(true); |
| 50 | }); | 49 | w.set_dbg_stop(true); |
| 51 | 50 | }); | |
| 52 | pp.DBGMCU.cr.modify(|_, w| { | 51 | } |
| 53 | w.dbg_sleep().set_bit(); | ||
| 54 | w.dbg_standby().set_bit(); | ||
| 55 | w.dbg_stop().set_bit() | ||
| 56 | }); | ||
| 57 | |||
| 58 | pp.RCC.ahb2enr.modify(|_, w| { | ||
| 59 | w.adcen().set_bit(); | ||
| 60 | w.gpioaen().set_bit(); | ||
| 61 | w.gpioben().set_bit(); | ||
| 62 | w.gpiocen().set_bit(); | ||
| 63 | w.gpioden().set_bit(); | ||
| 64 | w.gpioeen().set_bit(); | ||
| 65 | w.gpiofen().set_bit(); | ||
| 66 | w | ||
| 67 | }); | ||
| 68 | 52 | ||
| 69 | let p = embassy_stm32::init(Default::default()); | 53 | let p = embassy_stm32::init(Default::default()); |
| 70 | 54 | ||
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index 0af16867f..ba271b9ee 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs | |||
| @@ -24,15 +24,6 @@ fn main() -> ! { | |||
| 24 | w.set_dbg_standby(true); | 24 | w.set_dbg_standby(true); |
| 25 | w.set_dbg_stop(true); | 25 | w.set_dbg_stop(true); |
| 26 | }); | 26 | }); |
| 27 | |||
| 28 | pac::RCC.ahb2enr().modify(|w| { | ||
| 29 | w.set_gpioaen(true); | ||
| 30 | w.set_gpioben(true); | ||
| 31 | w.set_gpiocen(true); | ||
| 32 | w.set_gpioden(true); | ||
| 33 | w.set_gpioeen(true); | ||
| 34 | w.set_gpiofen(true); | ||
| 35 | }); | ||
| 36 | } | 27 | } |
| 37 | 28 | ||
| 38 | let p = embassy_stm32::init(Default::default()); | 29 | let p = embassy_stm32::init(Default::default()); |
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index c72463605..9d2fc2f21 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs | |||
| @@ -28,15 +28,6 @@ fn main() -> ! { | |||
| 28 | pac::RCC.apb2enr().modify(|w| { | 28 | pac::RCC.apb2enr().modify(|w| { |
| 29 | w.set_syscfgen(true); | 29 | w.set_syscfgen(true); |
| 30 | }); | 30 | }); |
| 31 | |||
| 32 | pac::RCC.ahb2enr().modify(|w| { | ||
| 33 | w.set_gpioaen(true); | ||
| 34 | w.set_gpioben(true); | ||
| 35 | w.set_gpiocen(true); | ||
| 36 | w.set_gpioden(true); | ||
| 37 | w.set_gpioeen(true); | ||
| 38 | w.set_gpiofen(true); | ||
| 39 | }); | ||
| 40 | } | 31 | } |
| 41 | 32 | ||
| 42 | let p = embassy_stm32::init(Default::default()); | 33 | let p = embassy_stm32::init(Default::default()); |
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index 6a06e4370..83537d92e 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs | |||
| @@ -59,15 +59,6 @@ fn main() -> ! { | |||
| 59 | pac::RCC.apb2enr().modify(|w| { | 59 | pac::RCC.apb2enr().modify(|w| { |
| 60 | w.set_syscfgen(true); | 60 | w.set_syscfgen(true); |
| 61 | }); | 61 | }); |
| 62 | |||
| 63 | pac::RCC.ahb2enr().modify(|w| { | ||
| 64 | w.set_gpioaen(true); | ||
| 65 | w.set_gpioben(true); | ||
| 66 | w.set_gpiocen(true); | ||
| 67 | w.set_gpioden(true); | ||
| 68 | w.set_gpioeen(true); | ||
| 69 | w.set_gpiofen(true); | ||
| 70 | }); | ||
| 71 | } | 62 | } |
| 72 | 63 | ||
| 73 | unsafe { embassy::time::set_clock(&ZeroClock) }; | 64 | unsafe { embassy::time::set_clock(&ZeroClock) }; |
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index 5317ac35f..1f7f8d46a 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs | |||
| @@ -13,11 +13,10 @@ use embassy_stm32::gpio::NoPin; | |||
| 13 | use example_common::*; | 13 | use example_common::*; |
| 14 | 14 | ||
| 15 | use cortex_m_rt::entry; | 15 | use cortex_m_rt::entry; |
| 16 | //use stm32f4::stm32f429 as pac; | ||
| 17 | use embassy_stm32::dac::{Channel, Dac, Value}; | 16 | use embassy_stm32::dac::{Channel, Dac, Value}; |
| 18 | use stm32l4::stm32l4x5 as pac; | 17 | use embassy_stm32::pac; |
| 18 | use stm32l4xx_hal::prelude::*; | ||
| 19 | use stm32l4xx_hal::rcc::PllSource; | 19 | use stm32l4xx_hal::rcc::PllSource; |
| 20 | use stm32l4xx_hal::{prelude::*}; | ||
| 21 | 20 | ||
| 22 | #[entry] | 21 | #[entry] |
| 23 | fn main() -> ! { | 22 | fn main() -> ! { |
| @@ -30,36 +29,23 @@ fn main() -> ! { | |||
| 30 | 29 | ||
| 31 | // TRY the other clock configuration | 30 | // TRY the other clock configuration |
| 32 | // let clocks = rcc.cfgr.freeze(&mut flash.acr); | 31 | // let clocks = rcc.cfgr.freeze(&mut flash.acr); |
| 33 | rcc | 32 | rcc.cfgr |
| 34 | .cfgr | ||
| 35 | .sysclk(80.mhz()) | 33 | .sysclk(80.mhz()) |
| 36 | .pclk1(80.mhz()) | 34 | .pclk1(80.mhz()) |
| 37 | .pclk2(80.mhz()) | 35 | .pclk2(80.mhz()) |
| 38 | .pll_source(PllSource::HSI16) | 36 | .pll_source(PllSource::HSI16) |
| 39 | .freeze(&mut flash.acr, &mut pwr); | 37 | .freeze(&mut flash.acr, &mut pwr); |
| 40 | 38 | ||
| 41 | let pp = unsafe { pac::Peripherals::steal() }; | 39 | unsafe { |
| 42 | 40 | pac::DBGMCU.cr().modify(|w| { | |
| 43 | pp.DBGMCU.cr.modify(|_, w| { | 41 | w.set_dbg_sleep(true); |
| 44 | w.dbg_sleep().set_bit(); | 42 | w.set_dbg_standby(true); |
| 45 | w.dbg_standby().set_bit(); | 43 | w.set_dbg_stop(true); |
| 46 | w.dbg_stop().set_bit() | 44 | }); |
| 47 | }); | 45 | pac::RCC.apb1enr1().modify(|w| { |
| 48 | 46 | w.set_dac1en(true); | |
| 49 | pp.RCC.apb1enr1.modify(|_, w| { | 47 | }); |
| 50 | w.dac1en().set_bit(); | 48 | } |
| 51 | w | ||
| 52 | }); | ||
| 53 | |||
| 54 | pp.RCC.ahb2enr.modify(|_, w| { | ||
| 55 | w.gpioaen().set_bit(); | ||
| 56 | w.gpioben().set_bit(); | ||
| 57 | w.gpiocen().set_bit(); | ||
| 58 | w.gpioden().set_bit(); | ||
| 59 | w.gpioeen().set_bit(); | ||
| 60 | w.gpiofen().set_bit(); | ||
| 61 | w | ||
| 62 | }); | ||
| 63 | 49 | ||
| 64 | let p = embassy_stm32::init(Default::default()); | 50 | let p = embassy_stm32::init(Default::default()); |
| 65 | 51 | ||
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs index 7cac01fd4..8702fe0cc 100644 --- a/examples/stm32l4/src/bin/spi.rs +++ b/examples/stm32l4/src/bin/spi.rs | |||
| @@ -32,15 +32,6 @@ fn main() -> ! { | |||
| 32 | pac::RCC.apb2enr().modify(|w| { | 32 | pac::RCC.apb2enr().modify(|w| { |
| 33 | w.set_syscfgen(true); | 33 | w.set_syscfgen(true); |
| 34 | }); | 34 | }); |
| 35 | |||
| 36 | pac::RCC.ahb2enr().modify(|w| { | ||
| 37 | w.set_gpioaen(true); | ||
| 38 | w.set_gpioben(true); | ||
| 39 | w.set_gpiocen(true); | ||
| 40 | w.set_gpioden(true); | ||
| 41 | w.set_gpioeen(true); | ||
| 42 | w.set_gpiofen(true); | ||
| 43 | }); | ||
| 44 | } | 35 | } |
| 45 | 36 | ||
| 46 | let p = embassy_stm32::init(Default::default()); | 37 | let p = embassy_stm32::init(Default::default()); |
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index f572b1eff..1c2a861e2 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs | |||
| @@ -60,15 +60,6 @@ fn main() -> ! { | |||
| 60 | w.set_dma1en(true); | 60 | w.set_dma1en(true); |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | pac::RCC.ahb2enr().modify(|w| { | ||
| 64 | w.set_gpioaen(true); | ||
| 65 | w.set_gpioben(true); | ||
| 66 | w.set_gpiocen(true); | ||
| 67 | w.set_gpioden(true); | ||
| 68 | w.set_gpioeen(true); | ||
| 69 | w.set_gpiofen(true); | ||
| 70 | }); | ||
| 71 | |||
| 72 | pac::RCC.apb1enr1().modify(|w| { | 63 | pac::RCC.apb1enr1().modify(|w| { |
| 73 | w.set_uart4en(true); | 64 | w.set_uart4en(true); |
| 74 | }); | 65 | }); |
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index e325e3da3..b51699acf 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs | |||
| @@ -67,15 +67,6 @@ fn main() -> ! { | |||
| 67 | w.set_dma1en(true); | 67 | w.set_dma1en(true); |
| 68 | w.set_dma2en(true); | 68 | w.set_dma2en(true); |
| 69 | }); | 69 | }); |
| 70 | |||
| 71 | pac::RCC.ahb2enr().modify(|w| { | ||
| 72 | w.set_gpioaen(true); | ||
| 73 | w.set_gpioben(true); | ||
| 74 | w.set_gpiocen(true); | ||
| 75 | w.set_gpioden(true); | ||
| 76 | w.set_gpioeen(true); | ||
| 77 | w.set_gpiofen(true); | ||
| 78 | }); | ||
| 79 | } | 70 | } |
| 80 | 71 | ||
| 81 | unsafe { embassy::time::set_clock(&ZeroClock) }; | 72 | unsafe { embassy::time::set_clock(&ZeroClock) }; |
