aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src/bin/eth.rs
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-08-04 13:39:02 -0400
committerBob McWhirter <[email protected]>2021-08-04 13:39:02 -0400
commitf4971fbb791e6d58cddf88aa8a39d6fe16c05b4c (patch)
treea44e47df15285259d4c691135fdc543ac3105b20 /examples/stm32h7/src/bin/eth.rs
parent4fe9114695ee20e2a4ef62b09fe4b11a1c488655 (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.rs39
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
9use core::sync::atomic::{AtomicUsize, Ordering}; 9#[path = "../example_common.rs"]
10mod example_common;
11use example_common::config;
10 12
11use cortex_m_rt::entry; 13use cortex_m_rt::entry;
12use defmt::{info, unwrap}; 14use defmt::{info, unwrap};
@@ -22,22 +24,12 @@ use embassy_net::{
22use embassy_stm32::clock::{Alarm, Clock}; 24use embassy_stm32::clock::{Alarm, Clock};
23use embassy_stm32::eth::lan8742a::LAN8742A; 25use embassy_stm32::eth::lan8742a::LAN8742A;
24use embassy_stm32::eth::{Ethernet, State}; 26use embassy_stm32::eth::{Ethernet, State};
25use embassy_stm32::rcc::{self, Rcc};
26use embassy_stm32::rng::Random; 27use embassy_stm32::rng::Random;
27use embassy_stm32::time::U32Ext; 28use embassy_stm32::{interrupt, peripherals};
28use embassy_stm32::{interrupt, peripherals, Config};
29use heapless::Vec; 29use heapless::Vec;
30use panic_probe as _; 30use panic_probe as _;
31use peripherals::{RNG, TIM2}; 31use peripherals::{RNG, TIM2};
32 32use embassy_stm32::dbgmcu::Dbgmcu;
33defmt::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]
43async fn main_task( 35async 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
156fn config() -> Config {
157 let mut config = Config::default();
158 config.rcc = rcc_config();
159 config
160}
161
162fn 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}