Skip to content

Commit 39e8e4d

Browse files
authored
Merge pull request #182 from baba-dev/codex/fix-tab5-boot-loop-errors
fix: harden Tab5 wifi init and power rails
2 parents dd3cb8c + eb83235 commit 39e8e4d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

platforms/tab5/main/hal/components/hal_wifi.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

platforms/tab5/main/hal/hal_esp32.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ void HalEsp32::init()
6161
i2c_master_bus_handle_t i2c_bus_handle = bsp_i2c_get_handle();
6262
bsp_io_expander_pi4ioe_init(i2c_bus_handle);
6363

64+
// Bring the downstream 5 V rails up before probing peripherals that rely on
65+
// them. The IO expanders default to the rails being disabled at power-on,
66+
// so explicitly drive them high here to ensure the codec, RS485 transceiver
67+
// and Wi-Fi co-processor are powered for the remainder of the HAL
68+
// initialisation sequence.
69+
setUsb5vEnable(true);
70+
setExt5vEnable(true);
71+
delay(10);
72+
6473
setChargeQcEnable(true);
6574
delay(50);
6675
setChargeEnable(true);

0 commit comments

Comments
 (0)