Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions platforms/tab5/main/hal/components/hal_wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions platforms/tab5/main/hal/hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading