diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/buffered_uart.rs | 3 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 18 |
2 files changed, 10 insertions, 11 deletions
diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index c800e64fc..a78d2df44 100644 --- a/examples/nrf/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs | |||
| @@ -11,6 +11,7 @@ mod example_common; | |||
| 11 | use defmt::panic; | 11 | use defmt::panic; |
| 12 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 13 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | 13 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; |
| 14 | use embassy_nrf::buffered_uarte::State; | ||
| 14 | use embassy_nrf::gpio::NoPin; | 15 | use embassy_nrf::gpio::NoPin; |
| 15 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; | 16 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; |
| 16 | use example_common::*; | 17 | use example_common::*; |
| @@ -26,8 +27,10 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 26 | let mut rx_buffer = [0u8; 4096]; | 27 | let mut rx_buffer = [0u8; 4096]; |
| 27 | 28 | ||
| 28 | let irq = interrupt::take!(UARTE0_UART0); | 29 | let irq = interrupt::take!(UARTE0_UART0); |
| 30 | let mut state = State::new(); | ||
| 29 | let u = unsafe { | 31 | let u = unsafe { |
| 30 | BufferedUarte::new( | 32 | BufferedUarte::new( |
| 33 | &mut state, | ||
| 31 | p.UARTE0, | 34 | p.UARTE0, |
| 32 | p.TIMER0, | 35 | p.TIMER0, |
| 33 | p.PPI_CH0, | 36 | p.PPI_CH0, |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 7ae80d6e3..5cf49e82f 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,15 +134,12 @@ 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]; |
| 137 | let state = STATE.put(State::new()); | ||
| 138 | let eth = ETH.put(Ethernet::new( | 138 | let eth = ETH.put(Ethernet::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, | 139 | state, p.ETH, eth_int, p.PA1, p.PA2, p.PC1, p.PA7, p.PC4, p.PC5, p.PB12, p.PB13, p.PB11, |
| 140 | mac_addr, 1, | 140 | LAN8742A, mac_addr, 1, |
| 141 | )); | 141 | )); |
| 142 | 142 | ||
| 143 | // NOTE(unsafe) This thing is a &'static | ||
| 144 | let net_device = DEVICE.put(unsafe { Pin::new_unchecked(eth) }); | ||
| 145 | net_device.as_mut().init(); | ||
| 146 | |||
| 147 | let config = StaticConfigurator::new(NetConfig { | 143 | let config = StaticConfigurator::new(NetConfig { |
| 148 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 0, 61), 24), | 144 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 0, 61), 24), |
| 149 | dns_servers: Vec::new(), | 145 | dns_servers: Vec::new(), |
| @@ -156,6 +152,6 @@ fn main() -> ! { | |||
| 156 | executor.set_alarm(alarm); | 152 | executor.set_alarm(alarm); |
| 157 | 153 | ||
| 158 | executor.run(move |spawner| { | 154 | executor.run(move |spawner| { |
| 159 | unwrap!(spawner.spawn(main_task(net_device, config, spawner))); | 155 | unwrap!(spawner.spawn(main_task(eth, config, spawner))); |
| 160 | }) | 156 | }) |
| 161 | } | 157 | } |
