@@ -248,9 +248,10 @@ bool HalEsp32::wifi_init()
248248 // uninitialised buffer, crashing the TLSF heap. Give the module time to boot
249249 // and then explicitly request a transport re-sync before touching the Wi-Fi
250250 // stack.
251- constexpr TickType_t kPowerOnGuardDelay = pdMS_TO_TICKS (250 );
252- constexpr TickType_t kPostResetGuardDelay = pdMS_TO_TICKS (400 );
253- constexpr TickType_t kRetryBackoffDelay = pdMS_TO_TICKS (150 );
251+ constexpr TickType_t kPowerOnGuardDelay = pdMS_TO_TICKS (500 );
252+ constexpr TickType_t kPostResetGuardDelay = pdMS_TO_TICKS (800 );
253+ constexpr TickType_t kRetryBackoffDelay = pdMS_TO_TICKS (200 );
254+ constexpr TickType_t kPowerCycleCooldown = pdMS_TO_TICKS (100 );
254255 constexpr int kMaxTransportRetries = 3 ;
255256
256257 vTaskDelay (kPowerOnGuardDelay );
@@ -260,8 +261,25 @@ bool HalEsp32::wifi_init()
260261 bool softap_started = false ;
261262 bool softap_unsupported = false ;
262263
264+ auto power_cycle_wifi = [&]()
265+ {
266+ ESP_LOGW (TAG, " Power-cycling ESP-Hosted coprocessor" );
267+ bsp_set_wifi_power_enable (false );
268+ vTaskDelay (kPowerCycleCooldown );
269+ bsp_set_wifi_power_enable (true );
270+ vTaskDelay (kPowerOnGuardDelay );
271+ };
272+
273+ bool schedule_power_cycle = false ;
274+
263275 for (int attempt = 0 ; attempt < kMaxTransportRetries ; ++attempt)
264276 {
277+ if (schedule_power_cycle)
278+ {
279+ power_cycle_wifi ();
280+ schedule_power_cycle = false ;
281+ }
282+
265283 if (attempt > 0 )
266284 {
267285 ESP_LOGW (TAG,
@@ -279,6 +297,10 @@ bool HalEsp32::wifi_init()
279297 attempt + 1 ,
280298 kMaxTransportRetries ,
281299 esp_err_to_name (host_err));
300+ if (attempt + 1 < kMaxTransportRetries )
301+ {
302+ schedule_power_cycle = true ;
303+ }
282304 continue ;
283305 }
284306
@@ -308,6 +330,11 @@ bool HalEsp32::wifi_init()
308330 esp_wifi_stop ();
309331 esp_wifi_deinit ();
310332 }
333+
334+ if (attempt + 1 < kMaxTransportRetries )
335+ {
336+ schedule_power_cycle = true ;
337+ }
311338 }
312339
313340 if (!softap_started)
0 commit comments