diff --git a/platforms/tab5/main/hal/components/hal_wifi.cpp b/platforms/tab5/main/hal/components/hal_wifi.cpp index 35a7ae0c..cd3e629f 100644 --- a/platforms/tab5/main/hal/components/hal_wifi.cpp +++ b/platforms/tab5/main/hal/components/hal_wifi.cpp @@ -248,9 +248,10 @@ bool HalEsp32::wifi_init() // uninitialised buffer, crashing the TLSF heap. Give the module time to boot // and then explicitly request a transport re-sync before touching the Wi-Fi // stack. - constexpr TickType_t kPowerOnGuardDelay = pdMS_TO_TICKS(250); - constexpr TickType_t kPostResetGuardDelay = pdMS_TO_TICKS(400); - constexpr TickType_t kRetryBackoffDelay = pdMS_TO_TICKS(150); + constexpr TickType_t kPowerOnGuardDelay = pdMS_TO_TICKS(500); + constexpr TickType_t kPostResetGuardDelay = pdMS_TO_TICKS(800); + constexpr TickType_t kRetryBackoffDelay = pdMS_TO_TICKS(200); + constexpr TickType_t kPowerCycleCooldown = pdMS_TO_TICKS(100); constexpr int kMaxTransportRetries = 3; vTaskDelay(kPowerOnGuardDelay); @@ -260,8 +261,25 @@ bool HalEsp32::wifi_init() bool softap_started = false; bool softap_unsupported = false; + auto power_cycle_wifi = [&]() + { + ESP_LOGW(TAG, "Power-cycling ESP-Hosted coprocessor"); + bsp_set_wifi_power_enable(false); + vTaskDelay(kPowerCycleCooldown); + bsp_set_wifi_power_enable(true); + vTaskDelay(kPowerOnGuardDelay); + }; + + bool schedule_power_cycle = false; + for (int attempt = 0; attempt < kMaxTransportRetries; ++attempt) { + if (schedule_power_cycle) + { + power_cycle_wifi(); + schedule_power_cycle = false; + } + if (attempt > 0) { ESP_LOGW(TAG, @@ -279,6 +297,10 @@ bool HalEsp32::wifi_init() attempt + 1, kMaxTransportRetries, esp_err_to_name(host_err)); + if (attempt + 1 < kMaxTransportRetries) + { + schedule_power_cycle = true; + } continue; } @@ -308,6 +330,11 @@ bool HalEsp32::wifi_init() esp_wifi_stop(); esp_wifi_deinit(); } + + if (attempt + 1 < kMaxTransportRetries) + { + schedule_power_cycle = true; + } } if (!softap_started) diff --git a/platforms/tab5/main/hal/hal_esp32.cpp b/platforms/tab5/main/hal/hal_esp32.cpp index f3bfeb54..7e97e602 100644 --- a/platforms/tab5/main/hal/hal_esp32.cpp +++ b/platforms/tab5/main/hal/hal_esp32.cpp @@ -61,6 +61,15 @@ void HalEsp32::init() i2c_master_bus_handle_t i2c_bus_handle = bsp_i2c_get_handle(); bsp_io_expander_pi4ioe_init(i2c_bus_handle); + // Bring the downstream 5 V rails up before probing peripherals that rely on + // them. The IO expanders default to the rails being disabled at power-on, + // so explicitly drive them high here to ensure the codec, RS485 transceiver + // and Wi-Fi co-processor are powered for the remainder of the HAL + // initialisation sequence. + setUsb5vEnable(true); + setExt5vEnable(true); + delay(10); + setChargeQcEnable(true); delay(50); setChargeEnable(true);