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/stm32h7 | |
| parent | ec5d44333ab6c0711424699efb2e782baf0124c7 (diff) | |
stm32: No need to enable GPIO clocks manually
Diffstat (limited to 'examples/stm32h7')
| -rw-r--r-- | examples/stm32h7/src/bin/blinky.rs | 13 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/dac.rs | 24 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 12 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/usart.rs | 10 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/usart_dma.rs | 7 |
5 files changed, 10 insertions, 56 deletions
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs index c41cc789d..54e139e79 100644 --- a/examples/stm32h7/src/bin/blinky.rs +++ b/examples/stm32h7/src/bin/blinky.rs | |||
| @@ -28,8 +28,7 @@ fn main() -> ! { | |||
| 28 | 28 | ||
| 29 | let rcc = pp.RCC.constrain(); | 29 | let rcc = pp.RCC.constrain(); |
| 30 | 30 | ||
| 31 | rcc | 31 | rcc.sys_ck(96.mhz()) |
| 32 | .sys_ck(96.mhz()) | ||
| 33 | .pclk1(48.mhz()) | 32 | .pclk1(48.mhz()) |
| 34 | .pclk2(48.mhz()) | 33 | .pclk2(48.mhz()) |
| 35 | .pclk3(48.mhz()) | 34 | .pclk3(48.mhz()) |
| @@ -47,16 +46,6 @@ fn main() -> ! { | |||
| 47 | w | 46 | w |
| 48 | }); | 47 | }); |
| 49 | 48 | ||
| 50 | pp.RCC.ahb4enr.modify(|_, w| { | ||
| 51 | w.gpioaen().set_bit(); | ||
| 52 | w.gpioben().set_bit(); | ||
| 53 | w.gpiocen().set_bit(); | ||
| 54 | w.gpioden().set_bit(); | ||
| 55 | w.gpioeen().set_bit(); | ||
| 56 | w.gpiofen().set_bit(); | ||
| 57 | w | ||
| 58 | }); | ||
| 59 | |||
| 60 | let p = embassy_stm32::init(Default::default()); | 49 | let p = embassy_stm32::init(Default::default()); |
| 61 | 50 | ||
| 62 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); | 51 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); |
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index 121956755..330f69aa1 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -13,9 +13,9 @@ 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 embassy_stm32::dac::{Channel, Dac, Value}; | ||
| 16 | use stm32h7::stm32h743 as pac; | 17 | use stm32h7::stm32h743 as pac; |
| 17 | use stm32h7xx_hal::prelude::*; | 18 | use stm32h7xx_hal::prelude::*; |
| 18 | use embassy_stm32::dac::{Dac, Value, Channel}; | ||
| 19 | 19 | ||
| 20 | #[entry] | 20 | #[entry] |
| 21 | fn main() -> ! { | 21 | fn main() -> ! { |
| @@ -23,13 +23,11 @@ fn main() -> ! { | |||
| 23 | 23 | ||
| 24 | let pp = pac::Peripherals::take().unwrap(); | 24 | let pp = pac::Peripherals::take().unwrap(); |
| 25 | 25 | ||
| 26 | let pwrcfg = pp.PWR.constrain() | 26 | let pwrcfg = pp.PWR.constrain().freeze(); |
| 27 | .freeze(); | ||
| 28 | 27 | ||
| 29 | let rcc = pp.RCC.constrain(); | 28 | let rcc = pp.RCC.constrain(); |
| 30 | 29 | ||
| 31 | rcc | 30 | rcc.sys_ck(96.mhz()) |
| 32 | .sys_ck(96.mhz()) | ||
| 33 | .pclk1(48.mhz()) | 31 | .pclk1(48.mhz()) |
| 34 | .pclk2(48.mhz()) | 32 | .pclk2(48.mhz()) |
| 35 | .pclk3(48.mhz()) | 33 | .pclk3(48.mhz()) |
| @@ -47,21 +45,11 @@ fn main() -> ! { | |||
| 47 | w | 45 | w |
| 48 | }); | 46 | }); |
| 49 | 47 | ||
| 50 | pp.RCC.apb1lenr.modify(|_, w|{ | 48 | pp.RCC.apb1lenr.modify(|_, w| { |
| 51 | w.dac12en().set_bit(); | 49 | w.dac12en().set_bit(); |
| 52 | w | 50 | w |
| 53 | }); | 51 | }); |
| 54 | 52 | ||
| 55 | pp.RCC.ahb4enr.modify(|_, w| { | ||
| 56 | w.gpioaen().set_bit(); | ||
| 57 | w.gpioben().set_bit(); | ||
| 58 | w.gpiocen().set_bit(); | ||
| 59 | w.gpioden().set_bit(); | ||
| 60 | w.gpioeen().set_bit(); | ||
| 61 | w.gpiofen().set_bit(); | ||
| 62 | w | ||
| 63 | }); | ||
| 64 | |||
| 65 | let p = embassy_stm32::init(Default::default()); | 53 | let p = embassy_stm32::init(Default::default()); |
| 66 | 54 | ||
| 67 | let mut dac = Dac::new(p.DAC1, p.PA4, NoPin); | 55 | let mut dac = Dac::new(p.DAC1, p.PA4, NoPin); |
| @@ -79,11 +67,11 @@ use micromath::F32Ext; | |||
| 79 | fn to_sine_wave(v: u8) -> u8 { | 67 | fn to_sine_wave(v: u8) -> u8 { |
| 80 | if v >= 128 { | 68 | if v >= 128 { |
| 81 | // top half | 69 | // top half |
| 82 | let r = 3.14 * ( (v-128) as f32/ 128.0) ; | 70 | let r = 3.14 * ((v - 128) as f32 / 128.0); |
| 83 | (r.sin() * 128.0 + 127.0) as u8 | 71 | (r.sin() * 128.0 + 127.0) as u8 |
| 84 | } else { | 72 | } else { |
| 85 | // bottom half | 73 | // bottom half |
| 86 | let r = 3.14 + 3.14 * (v as f32/ 128.0); | 74 | let r = 3.14 + 3.14 * (v as f32 / 128.0); |
| 87 | (r.sin() * 128.0 + 127.0) as u8 | 75 | (r.sin() * 128.0 + 127.0) as u8 |
| 88 | } | 76 | } |
| 89 | } | 77 | } |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 7dc02a75a..7ae80d6e3 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -106,8 +106,6 @@ static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); | |||
| 106 | 106 | ||
| 107 | #[entry] | 107 | #[entry] |
| 108 | fn main() -> ! { | 108 | fn main() -> ! { |
| 109 | use stm32_metapac::RCC; | ||
| 110 | |||
| 111 | info!("Hello World!"); | 109 | info!("Hello World!"); |
| 112 | 110 | ||
| 113 | info!("Setup RCC..."); | 111 | info!("Setup RCC..."); |
| @@ -123,16 +121,6 @@ fn main() -> ! { | |||
| 123 | let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default()); | 121 | let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default()); |
| 124 | rcc.enable_debug_wfe(&mut p.DBGMCU, true); | 122 | rcc.enable_debug_wfe(&mut p.DBGMCU, true); |
| 125 | 123 | ||
| 126 | unsafe { | ||
| 127 | RCC.ahb4enr().modify(|w| { | ||
| 128 | w.set_gpioaen(true); | ||
| 129 | w.set_gpioben(true); | ||
| 130 | w.set_gpiocen(true); | ||
| 131 | w.set_gpioden(true); | ||
| 132 | w.set_gpioien(true); | ||
| 133 | }); | ||
| 134 | } | ||
| 135 | |||
| 136 | let rtc_int = interrupt_take!(TIM2); | 124 | let rtc_int = interrupt_take!(TIM2); |
| 137 | let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int)); | 125 | let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int)); |
| 138 | rtc.start(); | 126 | rtc.start(); |
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index 143f94491..11e04f33c 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs | |||
| @@ -77,16 +77,6 @@ fn main() -> ! { | |||
| 77 | w | 77 | w |
| 78 | }); | 78 | }); |
| 79 | 79 | ||
| 80 | pp.RCC.ahb4enr.modify(|_, w| { | ||
| 81 | w.gpioaen().set_bit(); | ||
| 82 | w.gpioben().set_bit(); | ||
| 83 | w.gpiocen().set_bit(); | ||
| 84 | w.gpioden().set_bit(); | ||
| 85 | w.gpioeen().set_bit(); | ||
| 86 | w.gpiofen().set_bit(); | ||
| 87 | w | ||
| 88 | }); | ||
| 89 | |||
| 90 | unsafe { embassy::time::set_clock(&ZeroClock) }; | 80 | unsafe { embassy::time::set_clock(&ZeroClock) }; |
| 91 | 81 | ||
| 92 | let executor = EXECUTOR.put(Executor::new()); | 82 | let executor = EXECUTOR.put(Executor::new()); |
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index 907356500..fe59a2162 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs | |||
| @@ -12,18 +12,18 @@ use core::fmt::Write; | |||
| 12 | use embassy::executor::Executor; | 12 | use embassy::executor::Executor; |
| 13 | use embassy::time::Clock; | 13 | use embassy::time::Clock; |
| 14 | use embassy::util::Forever; | 14 | use embassy::util::Forever; |
| 15 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 15 | use embassy_stm32::dma::NoDma; | 16 | use embassy_stm32::dma::NoDma; |
| 16 | use embassy_stm32::usart::{Config, Uart}; | 17 | use embassy_stm32::usart::{Config, Uart}; |
| 17 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 18 | use example_common::*; | ||
| 19 | use embassy_traits::uart::Write as _Write; | 18 | use embassy_traits::uart::Write as _Write; |
| 19 | use example_common::*; | ||
| 20 | 20 | ||
| 21 | use hal::prelude::*; | 21 | use hal::prelude::*; |
| 22 | use stm32h7xx_hal as hal; | 22 | use stm32h7xx_hal as hal; |
| 23 | 23 | ||
| 24 | use cortex_m_rt::entry; | 24 | use cortex_m_rt::entry; |
| 25 | use stm32h7::stm32h743 as pac; | ||
| 26 | use heapless::String; | 25 | use heapless::String; |
| 26 | use stm32h7::stm32h743 as pac; | ||
| 27 | 27 | ||
| 28 | #[embassy::task] | 28 | #[embassy::task] |
| 29 | async fn main_task() { | 29 | async fn main_task() { |
| @@ -40,7 +40,6 @@ async fn main_task() { | |||
| 40 | 40 | ||
| 41 | info!("wrote DMA"); | 41 | info!("wrote DMA"); |
| 42 | } | 42 | } |
| 43 | |||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | struct ZeroClock; | 45 | struct ZeroClock; |
