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/src/bin/eth.rs | |
| parent | 4fe9114695ee20e2a4ef62b09fe4b11a1c488655 (diff) | |
Further work sharing config for example and removing duplicated code.
Diffstat (limited to 'examples/stm32h7/src/bin/eth.rs')
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 39 |
1 files changed, 9 insertions, 30 deletions
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 | } | ||
