diff options
| author | Bob McWhirter <[email protected]> | 2021-08-04 13:39:02 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-08-04 13:39:02 -0400 |
| commit | f4971fbb791e6d58cddf88aa8a39d6fe16c05b4c (patch) | |
| tree | a44e47df15285259d4c691135fdc543ac3105b20 /examples/stm32h7 | |
| parent | 4fe9114695ee20e2a4ef62b09fe4b11a1c488655 (diff) | |
Further work sharing config for example and removing duplicated code.
Diffstat (limited to 'examples/stm32h7')
| -rw-r--r-- | examples/stm32h7/src/bin/dac.rs | 16 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 39 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/spi.rs | 14 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/spi_dma.rs | 13 | ||||
| -rw-r--r-- | examples/stm32h7/src/example_common.rs | 11 |
5 files changed, 20 insertions, 73 deletions
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index 47e893aae..cc9e32574 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -14,9 +14,6 @@ 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 embassy_stm32::dac::{Channel, Dac, Value}; |
| 17 | use embassy_stm32::rcc; | ||
| 18 | use embassy_stm32::time::U32Ext; | ||
| 19 | use embassy_stm32::Config; | ||
| 20 | 17 | ||
| 21 | #[entry] | 18 | #[entry] |
| 22 | fn main() -> ! { | 19 | fn main() -> ! { |
| @@ -52,16 +49,3 @@ fn to_sine_wave(v: u8) -> u8 { | |||
| 52 | (r.sin() * 128.0 + 127.0) as u8 | 49 | (r.sin() * 128.0 + 127.0) as u8 |
| 53 | } | 50 | } |
| 54 | } | 51 | } |
| 55 | |||
| 56 | fn config() -> Config { | ||
| 57 | let mut config = Config::default(); | ||
| 58 | config.rcc = rcc_config(); | ||
| 59 | config | ||
| 60 | } | ||
| 61 | |||
| 62 | fn rcc_config() -> rcc::Config { | ||
| 63 | let mut config = rcc::Config::default(); | ||
| 64 | config.sys_ck = Some(400.mhz().into()); | ||
| 65 | config.pll1.q_ck = Some(100.mhz().into()); | ||
| 66 | config | ||
| 67 | } | ||
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 4ce2d854a..4a841405f 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -6,7 +6,9 @@ | |||
| 6 | #![feature(impl_trait_in_bindings)] | 6 | #![feature(impl_trait_in_bindings)] |
| 7 | #![feature(type_alias_impl_trait)] | 7 | #![feature(type_alias_impl_trait)] |
| 8 | 8 | ||
| 9 | use core::sync::atomic::{AtomicUsize, Ordering}; | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | ||
| 11 | use example_common::config; | ||
| 10 | 12 | ||
| 11 | use cortex_m_rt::entry; | 13 | use cortex_m_rt::entry; |
| 12 | use defmt::{info, unwrap}; | 14 | use defmt::{info, unwrap}; |
| @@ -22,22 +24,12 @@ use embassy_net::{ | |||
| 22 | use embassy_stm32::clock::{Alarm, Clock}; | 24 | use embassy_stm32::clock::{Alarm, Clock}; |
| 23 | use embassy_stm32::eth::lan8742a::LAN8742A; | 25 | use embassy_stm32::eth::lan8742a::LAN8742A; |
| 24 | use embassy_stm32::eth::{Ethernet, State}; | 26 | use embassy_stm32::eth::{Ethernet, State}; |
| 25 | use embassy_stm32::rcc::{self, Rcc}; | ||
| 26 | use embassy_stm32::rng::Random; | 27 | use embassy_stm32::rng::Random; |
| 27 | use embassy_stm32::time::U32Ext; | 28 | use embassy_stm32::{interrupt, peripherals}; |
| 28 | use embassy_stm32::{interrupt, peripherals, Config}; | ||
| 29 | use heapless::Vec; | 29 | use heapless::Vec; |
| 30 | use panic_probe as _; | 30 | use panic_probe as _; |
| 31 | use peripherals::{RNG, TIM2}; | 31 | use peripherals::{RNG, TIM2}; |
| 32 | 32 | use embassy_stm32::dbgmcu::Dbgmcu; | |
| 33 | defmt::timestamp! {"{=u64}", { | ||
| 34 | static COUNT: AtomicUsize = AtomicUsize::new(0); | ||
| 35 | // NOTE(no-CAS) `timestamps` runs with interrupts disabled | ||
| 36 | let n = COUNT.load(Ordering::Relaxed); | ||
| 37 | COUNT.store(n + 1, Ordering::Relaxed); | ||
| 38 | n as u64 | ||
| 39 | } | ||
| 40 | } | ||
| 41 | 33 | ||
| 42 | #[embassy::task] | 34 | #[embassy::task] |
| 43 | async fn main_task( | 35 | async fn main_task( |
| @@ -108,12 +100,12 @@ fn main() -> ! { | |||
| 108 | info!("Hello World!"); | 100 | info!("Hello World!"); |
| 109 | 101 | ||
| 110 | info!("Setup RCC..."); | 102 | info!("Setup RCC..."); |
| 111 | let mut p = embassy_stm32::init(config()); | ||
| 112 | 103 | ||
| 113 | // Constrain and Freeze clock | 104 | unsafe { |
| 105 | Dbgmcu::enable_all(); | ||
| 106 | } | ||
| 114 | 107 | ||
| 115 | let mut rcc = Rcc::new(&mut p.RCC, rcc::Config::default()); | 108 | let p = embassy_stm32::init(config()); |
| 116 | rcc.enable_debug_wfe(&mut p.DBGMCU, true); | ||
| 117 | 109 | ||
| 118 | let rtc_int = interrupt_take!(TIM2); | 110 | let rtc_int = interrupt_take!(TIM2); |
| 119 | let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int)); | 111 | let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int)); |
| @@ -152,16 +144,3 @@ fn main() -> ! { | |||
| 152 | unwrap!(spawner.spawn(main_task(eth, config, spawner))); | 144 | unwrap!(spawner.spawn(main_task(eth, config, spawner))); |
| 153 | }) | 145 | }) |
| 154 | } | 146 | } |
| 155 | |||
| 156 | fn config() -> Config { | ||
| 157 | let mut config = Config::default(); | ||
| 158 | config.rcc = rcc_config(); | ||
| 159 | config | ||
| 160 | } | ||
| 161 | |||
| 162 | fn rcc_config() -> rcc::Config { | ||
| 163 | let mut config = rcc::Config::default(); | ||
| 164 | config.sys_ck = Some(400.mhz().into()); | ||
| 165 | config.pll1.q_ck = Some(100.mhz().into()); | ||
| 166 | config | ||
| 167 | } | ||
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index e72211e81..ed3e369bd 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs | |||
| @@ -14,9 +14,7 @@ use embassy::executor::Executor; | |||
| 14 | use embassy::time::Clock; | 14 | use embassy::time::Clock; |
| 15 | use embassy::util::Forever; | 15 | use embassy::util::Forever; |
| 16 | use embassy_stm32::dma::NoDma; | 16 | use embassy_stm32::dma::NoDma; |
| 17 | use embassy_stm32::rcc; | ||
| 18 | use embassy_stm32::spi; | 17 | use embassy_stm32::spi; |
| 19 | use embassy_stm32::Config; | ||
| 20 | use embedded_hal::blocking::spi::Transfer; | 18 | use embedded_hal::blocking::spi::Transfer; |
| 21 | use example_common::*; | 19 | use example_common::*; |
| 22 | 20 | ||
| @@ -81,15 +79,3 @@ fn main() -> ! { | |||
| 81 | }) | 79 | }) |
| 82 | } | 80 | } |
| 83 | 81 | ||
| 84 | fn config() -> Config { | ||
| 85 | let mut config = Config::default(); | ||
| 86 | config.rcc = rcc_config(); | ||
| 87 | config | ||
| 88 | } | ||
| 89 | |||
| 90 | fn rcc_config() -> rcc::Config { | ||
| 91 | let mut config = rcc::Config::default(); | ||
| 92 | config.sys_ck = Some(400.mhz().into()); | ||
| 93 | config.pll1.q_ck = Some(100.mhz().into()); | ||
| 94 | config | ||
| 95 | } | ||
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index aa120c974..ae6fe3ca0 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs | |||
| @@ -21,9 +21,7 @@ use core::str::from_utf8; | |||
| 21 | use cortex_m_rt::entry; | 21 | use cortex_m_rt::entry; |
| 22 | use embassy_stm32::dbgmcu::Dbgmcu; | 22 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 23 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; | 23 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; |
| 24 | use embassy_stm32::rcc; | ||
| 25 | use embassy_stm32::spi; | 24 | use embassy_stm32::spi; |
| 26 | use embassy_stm32::Config; | ||
| 27 | use heapless::String; | 25 | use heapless::String; |
| 28 | 26 | ||
| 29 | #[embassy::task] | 27 | #[embassy::task] |
| @@ -77,15 +75,4 @@ fn main() -> ! { | |||
| 77 | }) | 75 | }) |
| 78 | } | 76 | } |
| 79 | 77 | ||
| 80 | fn config() -> Config { | ||
| 81 | let mut config = Config::default(); | ||
| 82 | config.rcc = rcc_config(); | ||
| 83 | config | ||
| 84 | } | ||
| 85 | 78 | ||
| 86 | fn rcc_config() -> rcc::Config { | ||
| 87 | let mut config = rcc::Config::default(); | ||
| 88 | config.sys_ck = Some(400.mhz().into()); | ||
| 89 | config.pll1.q_ck = Some(100.mhz().into()); | ||
| 90 | config | ||
| 91 | } | ||
diff --git a/examples/stm32h7/src/example_common.rs b/examples/stm32h7/src/example_common.rs index 54d633837..25d80f654 100644 --- a/examples/stm32h7/src/example_common.rs +++ b/examples/stm32h7/src/example_common.rs | |||
| @@ -6,6 +6,8 @@ use panic_probe as _; | |||
| 6 | pub use defmt::*; | 6 | pub use defmt::*; |
| 7 | 7 | ||
| 8 | use core::sync::atomic::{AtomicUsize, Ordering}; | 8 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 9 | use embassy_stm32::Config; | ||
| 10 | use embassy_stm32::time::U32Ext; | ||
| 9 | 11 | ||
| 10 | defmt::timestamp! {"{=u64}", { | 12 | defmt::timestamp! {"{=u64}", { |
| 11 | static COUNT: AtomicUsize = AtomicUsize::new(0); | 13 | static COUNT: AtomicUsize = AtomicUsize::new(0); |
| @@ -15,3 +17,12 @@ defmt::timestamp! {"{=u64}", { | |||
| 15 | n as u64 | 17 | n as u64 |
| 16 | } | 18 | } |
| 17 | } | 19 | } |
| 20 | |||
| 21 | #[allow(unused)] | ||
| 22 | pub fn config() -> Config { | ||
| 23 | let mut config = Config::default(); | ||
| 24 | config.rcc.sys_ck = Some(400.mhz().into()); | ||
| 25 | config.rcc.pll1.q_ck = Some(100.mhz().into()); | ||
| 26 | config.rcc.enable_dma1 = true; | ||
| 27 | config | ||
| 28 | } | ||
