1818#include < nvs_flash.h>
1919
2020#include " hal/hal_esp32.h"
21+ #include " integration/wifi/hosted_safe.h"
2122
2223#define TAG " wifi"
2324
@@ -260,6 +261,7 @@ bool HalEsp32::wifi_init()
260261 esp_err_t softap_err = ESP_FAIL;
261262 bool softap_started = false ;
262263 bool softap_unsupported = false ;
264+ bool hosted_initialised = false ;
263265
264266 auto power_cycle_wifi = [&]()
265267 {
@@ -289,6 +291,18 @@ bool HalEsp32::wifi_init()
289291 vTaskDelay (kRetryBackoffDelay * static_cast <TickType_t>(attempt));
290292 }
291293
294+ if (!custom::integration::wifi::HostedSafeStart ())
295+ {
296+ host_err = ESP_FAIL;
297+ if (attempt + 1 < kMaxTransportRetries )
298+ {
299+ schedule_power_cycle = true ;
300+ }
301+ continue ;
302+ }
303+
304+ hosted_initialised = true ;
305+
292306 host_err = esp_hosted_slave_reset ();
293307 if (host_err != ESP_OK)
294308 {
@@ -297,6 +311,7 @@ bool HalEsp32::wifi_init()
297311 attempt + 1 ,
298312 kMaxTransportRetries ,
299313 esp_err_to_name (host_err));
314+ esp_hosted_deinit ();
300315 if (attempt + 1 < kMaxTransportRetries )
301316 {
302317 schedule_power_cycle = true ;
@@ -331,6 +346,8 @@ bool HalEsp32::wifi_init()
331346 esp_wifi_deinit ();
332347 }
333348
349+ esp_hosted_deinit ();
350+
334351 if (attempt + 1 < kMaxTransportRetries )
335352 {
336353 schedule_power_cycle = true ;
@@ -342,9 +359,14 @@ bool HalEsp32::wifi_init()
342359 portENTER_CRITICAL (&spinlock);
343360 state.failed = true ;
344361 portEXIT_CRITICAL (&spinlock);
362+ esp_hosted_deinit ();
345363 bsp_set_wifi_power_enable (false );
346364
347- if (softap_unsupported)
365+ if (!hosted_initialised)
366+ {
367+ ESP_LOGW (TAG, " Hosted init failed; Wi-Fi disabled" );
368+ }
369+ else if (softap_unsupported)
348370 {
349371 ESP_LOGW (TAG, " SoftAP unsupported on hosted slave; Wi-Fi will stay disabled" );
350372 }
0 commit comments