aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOscar Aurin <[email protected]>2025-07-13 23:41:17 +0200
committerOscar Aurin <[email protected]>2025-07-27 23:05:59 +0200
commit21566666b852e38641ef8ccb3d2b988dfd5a34c5 (patch)
treea821d749be82a3712bf1bd5a729a363a46513943
parent77a8bc27e9c34e363f321132ebb9e8d8ff684a9f (diff)
examples: fix RP2040 link establishing logic
-rw-r--r--examples/rp/src/bin/wifi_tcp_server.rs27
-rw-r--r--examples/rp/src/bin/wifi_webrequest.rs33
2 files changed, 21 insertions, 39 deletions
diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs
index fbc957e0e..ed1a03fcf 100644
--- a/examples/rp/src/bin/wifi_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_tcp_server.rs
@@ -18,7 +18,7 @@ use embassy_rp::clocks::RoscRng;
18use embassy_rp::gpio::{Level, Output}; 18use embassy_rp::gpio::{Level, Output};
19use embassy_rp::peripherals::{DMA_CH0, PIO0}; 19use embassy_rp::peripherals::{DMA_CH0, PIO0};
20use embassy_rp::pio::{InterruptHandler, Pio}; 20use embassy_rp::pio::{InterruptHandler, Pio};
21use embassy_time::{Duration, Timer}; 21use embassy_time::Duration;
22use embedded_io_async::Write; 22use embedded_io_async::Write;
23use static_cell::StaticCell; 23use static_cell::StaticCell;
24use {defmt_rtt as _, panic_probe as _}; 24use {defmt_rtt as _, panic_probe as _};
@@ -97,26 +97,21 @@ async fn main(spawner: Spawner) {
97 97
98 unwrap!(spawner.spawn(net_task(runner))); 98 unwrap!(spawner.spawn(net_task(runner)));
99 99
100 loop { 100 while let Err(err) = control
101 match control 101 .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes()))
102 .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes())) 102 .await
103 .await 103 {
104 { 104 info!("join failed with status={}", err.status);
105 Ok(_) => break,
106 Err(err) => {
107 info!("join failed with status={}", err.status);
108 }
109 }
110 } 105 }
111 106
112 // Wait for DHCP, not necessary when using static IP 107 info!("waiting for link...");
108 stack.wait_link_up().await;
109
113 info!("waiting for DHCP..."); 110 info!("waiting for DHCP...");
114 while !stack.is_config_up() { 111 stack.wait_config_up().await;
115 Timer::after_millis(100).await;
116 }
117 info!("DHCP is now up!");
118 112
119 // And now we can use it! 113 // And now we can use it!
114 info!("Stack is up!");
120 115
121 let mut rx_buffer = [0; 4096]; 116 let mut rx_buffer = [0; 4096];
122 let mut tx_buffer = [0; 4096]; 117 let mut tx_buffer = [0; 4096];
diff --git a/examples/rp/src/bin/wifi_webrequest.rs b/examples/rp/src/bin/wifi_webrequest.rs
index 1efd1cd28..a75253bb0 100644
--- a/examples/rp/src/bin/wifi_webrequest.rs
+++ b/examples/rp/src/bin/wifi_webrequest.rs
@@ -100,33 +100,20 @@ async fn main(spawner: Spawner) {
100 100
101 unwrap!(spawner.spawn(net_task(runner))); 101 unwrap!(spawner.spawn(net_task(runner)));
102 102
103 loop { 103 while let Err(err) = control
104 match control 104 .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes()))
105 .join(WIFI_NETWORK, JoinOptions::new(WIFI_PASSWORD.as_bytes())) 105 .await
106 .await 106 {
107 { 107 info!("join failed with status={}", err.status);
108 Ok(_) => break,
109 Err(err) => {
110 info!("join failed with status={}", err.status);
111 }
112 }
113 }
114
115 // Wait for DHCP, not necessary when using static IP
116 info!("waiting for DHCP...");
117 while !stack.is_config_up() {
118 Timer::after_millis(100).await;
119 } 108 }
120 info!("DHCP is now up!");
121 109
122 info!("waiting for link up..."); 110 info!("waiting for link...");
123 while !stack.is_link_up() { 111 stack.wait_link_up().await;
124 Timer::after_millis(500).await;
125 }
126 info!("Link is up!");
127 112
128 info!("waiting for stack to be up..."); 113 info!("waiting for DHCP...");
129 stack.wait_config_up().await; 114 stack.wait_config_up().await;
115
116 // And now we can use it!
130 info!("Stack is up!"); 117 info!("Stack is up!");
131 118
132 // And now we can use it! 119 // And now we can use it!