diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-09-11 22:06:26 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-09-16 21:17:11 +0200 |
| commit | be0d9775e3bcc3c1bd1448e357d7c6cd67b68991 (patch) | |
| tree | 5e8c444b233a86ade113b096ab1e2934b7bbc7bd /examples/stm32h5 | |
| parent | 7648d42b7f23a2caad29ed6e16123b088ccdc8b5 (diff) | |
net: refactor to simplify lifetimes/generics.
Diffstat (limited to 'examples/stm32h5')
| -rw-r--r-- | examples/stm32h5/src/bin/eth.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index 65cfad8c9..eee1632f5 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_net::tcp::TcpSocket; | 6 | use embassy_net::tcp::TcpSocket; |
| 7 | use embassy_net::{Ipv4Address, Stack, StackResources}; | 7 | use embassy_net::{Ipv4Address, StackResources}; |
| 8 | use embassy_stm32::eth::generic_smi::GenericSMI; | 8 | use embassy_stm32::eth::generic_smi::GenericSMI; |
| 9 | use embassy_stm32::eth::{Ethernet, PacketQueue}; | 9 | use embassy_stm32::eth::{Ethernet, PacketQueue}; |
| 10 | use embassy_stm32::peripherals::ETH; | 10 | use embassy_stm32::peripherals::ETH; |
| @@ -28,8 +28,8 @@ bind_interrupts!(struct Irqs { | |||
| 28 | type Device = Ethernet<'static, ETH, GenericSMI>; | 28 | type Device = Ethernet<'static, ETH, GenericSMI>; |
| 29 | 29 | ||
| 30 | #[embassy_executor::task] | 30 | #[embassy_executor::task] |
| 31 | async fn net_task(stack: &'static Stack<Device>) -> ! { | 31 | async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { |
| 32 | stack.run().await | 32 | runner.run().await |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | #[embassy_executor::main] | 35 | #[embassy_executor::main] |
| @@ -92,12 +92,11 @@ async fn main(spawner: Spawner) -> ! { | |||
| 92 | //}); | 92 | //}); |
| 93 | 93 | ||
| 94 | // Init network stack | 94 | // Init network stack |
| 95 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); | ||
| 96 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | 95 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); |
| 97 | let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); | 96 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 98 | 97 | ||
| 99 | // Launch network task | 98 | // Launch network task |
| 100 | unwrap!(spawner.spawn(net_task(&stack))); | 99 | unwrap!(spawner.spawn(net_task(runner))); |
| 101 | 100 | ||
| 102 | // Ensure DHCP configuration is up before trying connect | 101 | // Ensure DHCP configuration is up before trying connect |
| 103 | stack.wait_config_up().await; | 102 | stack.wait_config_up().await; |
| @@ -109,7 +108,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 109 | let mut tx_buffer = [0; 1024]; | 108 | let mut tx_buffer = [0; 1024]; |
| 110 | 109 | ||
| 111 | loop { | 110 | loop { |
| 112 | let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer); | 111 | let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); |
| 113 | 112 | ||
| 114 | socket.set_timeout(Some(embassy_time::Duration::from_secs(10))); | 113 | socket.set_timeout(Some(embassy_time::Duration::from_secs(10))); |
| 115 | 114 | ||
