aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src/bin/eth_client.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-09-11 22:06:26 +0200
committerDario Nieuwenhuis <[email protected]>2024-09-16 21:17:11 +0200
commitbe0d9775e3bcc3c1bd1448e357d7c6cd67b68991 (patch)
tree5e8c444b233a86ade113b096ab1e2934b7bbc7bd /examples/stm32h7/src/bin/eth_client.rs
parent7648d42b7f23a2caad29ed6e16123b088ccdc8b5 (diff)
net: refactor to simplify lifetimes/generics.
Diffstat (limited to 'examples/stm32h7/src/bin/eth_client.rs')
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 274c24ab1..24983ca85 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -4,7 +4,7 @@
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_net::tcp::client::{TcpClient, TcpClientState}; 6use embassy_net::tcp::client::{TcpClient, TcpClientState};
7use embassy_net::{Stack, StackResources}; 7use embassy_net::StackResources;
8use embassy_stm32::eth::generic_smi::GenericSMI; 8use embassy_stm32::eth::generic_smi::GenericSMI;
9use embassy_stm32::eth::{Ethernet, PacketQueue}; 9use embassy_stm32::eth::{Ethernet, PacketQueue};
10use embassy_stm32::peripherals::ETH; 10use embassy_stm32::peripherals::ETH;
@@ -25,8 +25,8 @@ bind_interrupts!(struct Irqs {
25type Device = Ethernet<'static, ETH, GenericSMI>; 25type Device = Ethernet<'static, ETH, GenericSMI>;
26 26
27#[embassy_executor::task] 27#[embassy_executor::task]
28async fn net_task(stack: &'static Stack<Device>) -> ! { 28async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! {
29 stack.run().await 29 runner.run().await
30} 30}
31 31
32#[embassy_executor::main] 32#[embassy_executor::main]
@@ -91,12 +91,11 @@ async fn main(spawner: Spawner) -> ! {
91 //}); 91 //});
92 92
93 // Init network stack 93 // Init network stack
94 static STACK: StaticCell<Stack<Device>> = StaticCell::new();
95 static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); 94 static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
96 let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); 95 let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
97 96
98 // Launch network task 97 // Launch network task
99 unwrap!(spawner.spawn(net_task(stack))); 98 unwrap!(spawner.spawn(net_task(runner)));
100 99
101 // Ensure DHCP configuration is up before trying connect 100 // Ensure DHCP configuration is up before trying connect
102 stack.wait_config_up().await; 101 stack.wait_config_up().await;
@@ -104,7 +103,7 @@ async fn main(spawner: Spawner) -> ! {
104 info!("Network task initialized"); 103 info!("Network task initialized");
105 104
106 let state: TcpClientState<1, 1024, 1024> = TcpClientState::new(); 105 let state: TcpClientState<1, 1024, 1024> = TcpClientState::new();
107 let client = TcpClient::new(&stack, &state); 106 let client = TcpClient::new(stack, &state);
108 107
109 loop { 108 loop {
110 // You need to start a server on the host machine, for example: `nc -l 8000` 109 // You need to start a server on the host machine, for example: `nc -l 8000`