diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-08-02 20:28:54 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-02 20:28:54 +0200 |
| commit | 9ca43752eb121cc6614f456fc6c8753deae3fa62 (patch) | |
| tree | da16008285a54746a07bdf7881a4fce4cbf8d23e /examples/stm32h7/src | |
| parent | de207764aee0dd9c23bd02f92b55a55babd47b1a (diff) | |
| parent | 3f28bb6c77de3d8ecbb6d401f107586f24e416a4 (diff) | |
Merge pull request #327 from embassy-rs/remove-pin
PeripheralMutex: Remove Pin
Diffstat (limited to 'examples/stm32h7/src')
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 7ae80d6e3..e49a101bf 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -6,7 +6,6 @@ | |||
| 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::pin::Pin; | ||
| 10 | use core::sync::atomic::{AtomicUsize, Ordering}; | 9 | use core::sync::atomic::{AtomicUsize, Ordering}; |
| 11 | 10 | ||
| 12 | use cortex_m_rt::entry; | 11 | use cortex_m_rt::entry; |
| @@ -22,7 +21,7 @@ use embassy_net::{ | |||
| 22 | }; | 21 | }; |
| 23 | use embassy_stm32::clock::{Alarm, Clock}; | 22 | use embassy_stm32::clock::{Alarm, Clock}; |
| 24 | use embassy_stm32::eth::lan8742a::LAN8742A; | 23 | use embassy_stm32::eth::lan8742a::LAN8742A; |
| 25 | use embassy_stm32::eth::Ethernet; | 24 | use embassy_stm32::eth::{Ethernet, State}; |
| 26 | use embassy_stm32::rcc::{Config as RccConfig, Rcc}; | 25 | use embassy_stm32::rcc::{Config as RccConfig, Rcc}; |
| 27 | use embassy_stm32::rng::Random; | 26 | use embassy_stm32::rng::Random; |
| 28 | use embassy_stm32::time::Hertz; | 27 | use embassy_stm32::time::Hertz; |
| @@ -42,7 +41,7 @@ defmt::timestamp! {"{=u64}", { | |||
| 42 | 41 | ||
| 43 | #[embassy::task] | 42 | #[embassy::task] |
| 44 | async fn main_task( | 43 | async fn main_task( |
| 45 | device: &'static mut Pin<&'static mut Ethernet<'static, LAN8742A, 4, 4>>, | 44 | device: &'static mut Ethernet<'static, LAN8742A, 4, 4>, |
| 46 | config: &'static mut StaticConfigurator, | 45 | config: &'static mut StaticConfigurator, |
| 47 | spawner: Spawner, | 46 | spawner: Spawner, |
| 48 | ) { | 47 | ) { |
| @@ -99,8 +98,8 @@ static mut RNG_INST: Option<Random<RNG>> = None; | |||
| 99 | static EXECUTOR: Forever<Executor> = Forever::new(); | 98 | static EXECUTOR: Forever<Executor> = Forever::new(); |
| 100 | static TIMER_RTC: Forever<Clock<TIM2>> = Forever::new(); | 99 | static TIMER_RTC: Forever<Clock<TIM2>> = Forever::new(); |
| 101 | static ALARM: Forever<Alarm<TIM2>> = Forever::new(); | 100 | static ALARM: Forever<Alarm<TIM2>> = Forever::new(); |
| 101 | static STATE: Forever<State<'static, 4, 4>> = Forever::new(); | ||
| 102 | static ETH: Forever<Ethernet<'static, LAN8742A, 4, 4>> = Forever::new(); | 102 | static ETH: Forever<Ethernet<'static, LAN8742A, 4, 4>> = Forever::new(); |
| 103 | static DEVICE: Forever<Pin<&'static mut Ethernet<'static, LAN8742A, 4, 4>>> = Forever::new(); | ||
| 104 | static CONFIG: Forever<StaticConfigurator> = Forever::new(); | 103 | static CONFIG: Forever<StaticConfigurator> = Forever::new(); |
| 105 | static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); | 104 | static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); |
| 106 | 105 | ||
| @@ -135,14 +134,13 @@ fn main() -> ! { | |||
| 135 | 134 | ||
| 136 | let eth_int = interrupt_take!(ETH); | 135 | let eth_int = interrupt_take!(ETH); |
| 137 | let mac_addr = [0x10; 6]; | 136 | let mac_addr = [0x10; 6]; |
| 138 | let eth = ETH.put(Ethernet::new( | 137 | let state = STATE.put(State::new()); |
| 139 | p.ETH, eth_int, p.PA1, p.PA2, p.PC1, p.PA7, p.PC4, p.PC5, p.PB12, p.PB13, p.PB11, LAN8742A, | 138 | let eth = unsafe { |
| 140 | mac_addr, 1, | 139 | ETH.put(Ethernet::new( |
| 141 | )); | 140 | state, p.ETH, eth_int, p.PA1, p.PA2, p.PC1, p.PA7, p.PC4, p.PC5, p.PB12, p.PB13, |
| 142 | 141 | p.PB11, LAN8742A, mac_addr, 1, | |
| 143 | // NOTE(unsafe) This thing is a &'static | 142 | )) |
| 144 | let net_device = DEVICE.put(unsafe { Pin::new_unchecked(eth) }); | 143 | }; |
| 145 | net_device.as_mut().init(); | ||
| 146 | 144 | ||
| 147 | let config = StaticConfigurator::new(NetConfig { | 145 | let config = StaticConfigurator::new(NetConfig { |
| 148 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 0, 61), 24), | 146 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 0, 61), 24), |
| @@ -156,6 +154,6 @@ fn main() -> ! { | |||
| 156 | executor.set_alarm(alarm); | 154 | executor.set_alarm(alarm); |
| 157 | 155 | ||
| 158 | executor.run(move |spawner| { | 156 | executor.run(move |spawner| { |
| 159 | unwrap!(spawner.spawn(main_task(net_device, config, spawner))); | 157 | unwrap!(spawner.spawn(main_task(eth, config, spawner))); |
| 160 | }) | 158 | }) |
| 161 | } | 159 | } |
