Skip to content

Commit 6128ea7

Browse files
authored
Merge pull request #179 from baba-dev/codex/fix-boot-loop-issue-and-test
Fix Tab5 preflight for IDF 5.4.2 compatibility
2 parents f07c925 + bca4938 commit 6128ea7

8 files changed

Lines changed: 98 additions & 22 deletions

File tree

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

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -242,42 +242,99 @@ bool HalEsp32::wifi_init()
242242

243243
bsp_set_wifi_power_enable(true);
244244

245-
// The hosted C6 coprocessor requires a short guard time after power up before it
245+
// The hosted C6 coprocessor requires a guard time after power up before it
246246
// responds to the transport reset sequence. Without the delay the first RPC
247247
// request races the SDIO link initialisation and the transport driver frees an
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-
vTaskDelay(pdMS_TO_TICKS(200));
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);
254+
constexpr int kMaxTransportRetries = 3;
252255

253-
esp_err_t host_err = esp_hosted_slave_reset();
254-
if (host_err != ESP_OK)
255-
{
256-
ESP_LOGE(TAG, "Failed to bring ESP-Hosted transport up: %s", esp_err_to_name(host_err));
257-
portENTER_CRITICAL(&spinlock);
258-
state.failed = true;
259-
portEXIT_CRITICAL(&spinlock);
260-
bsp_set_wifi_power_enable(false);
261-
return false;
262-
}
256+
vTaskDelay(kPowerOnGuardDelay);
257+
258+
esp_err_t host_err = ESP_FAIL;
259+
esp_err_t softap_err = ESP_FAIL;
260+
bool softap_started = false;
261+
bool softap_unsupported = false;
263262

264-
esp_err_t err = start_softap();
265-
if (err == ESP_ERR_NOT_SUPPORTED)
263+
for (int attempt = 0; attempt < kMaxTransportRetries; ++attempt)
266264
{
267-
ESP_LOGW(TAG, "SoftAP unsupported on hosted slave; Wi-Fi will stay disabled");
268-
portENTER_CRITICAL(&spinlock);
269-
state.failed = true;
270-
portEXIT_CRITICAL(&spinlock);
271-
bsp_set_wifi_power_enable(false);
272-
return false;
265+
if (attempt > 0)
266+
{
267+
ESP_LOGW(TAG,
268+
"Retrying ESP-Hosted transport bring-up (%d/%d)",
269+
attempt + 1,
270+
kMaxTransportRetries);
271+
vTaskDelay(kRetryBackoffDelay * static_cast<TickType_t>(attempt));
272+
}
273+
274+
host_err = esp_hosted_slave_reset();
275+
if (host_err != ESP_OK)
276+
{
277+
ESP_LOGE(TAG,
278+
"ESP-Hosted reset failed on attempt %d/%d: %s",
279+
attempt + 1,
280+
kMaxTransportRetries,
281+
esp_err_to_name(host_err));
282+
continue;
283+
}
284+
285+
vTaskDelay(kPostResetGuardDelay);
286+
287+
softap_err = start_softap();
288+
if (softap_err == ESP_OK)
289+
{
290+
softap_started = true;
291+
break;
292+
}
293+
294+
if (softap_err == ESP_ERR_NOT_SUPPORTED)
295+
{
296+
softap_unsupported = true;
297+
break;
298+
}
299+
300+
ESP_LOGE(TAG,
301+
"SoftAP start failed on attempt %d/%d: %s",
302+
attempt + 1,
303+
kMaxTransportRetries,
304+
esp_err_to_name(softap_err));
305+
306+
if (softap_err == ESP_ERR_TIMEOUT || softap_err == ESP_FAIL)
307+
{
308+
esp_wifi_stop();
309+
esp_wifi_deinit();
310+
}
273311
}
274-
if (err != ESP_OK)
312+
313+
if (!softap_started)
275314
{
276-
ESP_LOGE(TAG, "Failed to start Wi-Fi: %s", esp_err_to_name(err));
277315
portENTER_CRITICAL(&spinlock);
278316
state.failed = true;
279317
portEXIT_CRITICAL(&spinlock);
280318
bsp_set_wifi_power_enable(false);
319+
320+
if (softap_unsupported)
321+
{
322+
ESP_LOGW(TAG, "SoftAP unsupported on hosted slave; Wi-Fi will stay disabled");
323+
}
324+
else if (host_err != ESP_OK)
325+
{
326+
ESP_LOGE(TAG,
327+
"Failed to bring ESP-Hosted transport up after %d attempts: %s",
328+
kMaxTransportRetries,
329+
esp_err_to_name(host_err));
330+
}
331+
else
332+
{
333+
ESP_LOGE(TAG,
334+
"Failed to start Wi-Fi after %d attempts: %s",
335+
kMaxTransportRetries,
336+
esp_err_to_name(softap_err));
337+
}
281338
return false;
282339
}
283340

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "../idf_v5.4/Kconfig.slave_select.in"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "../idf_v5.4/Kconfig.soc_wifi_caps.in"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "../idf_v5.4/Kconfig.wifi.in"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "../idf_v5.4/Kconfig.slave_select.in"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "../idf_v5.4/Kconfig.soc_wifi_caps.in"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "../idf_v5.4/Kconfig.wifi.in"

scripts/preflight.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ cd "$ROOT_DIR"
77
echo "[preflight] Using repo installer to setup ESP-IDF..."
88
bash tools/install_idf.sh
99

10+
# Ensure the ESP-IDF environment is active for the remainder of the script.
11+
ESP_IDF_VERSION=${ESP_IDF_VERSION:-v5.4.2}
12+
ESP_IDF_ROOT=${ESP_IDF_ROOT:-$HOME/.espressif}
13+
IDF_PATH="${ESP_IDF_ROOT}/esp-idf-${ESP_IDF_VERSION}"
14+
15+
if [ ! -d "${IDF_PATH}" ]; then
16+
echo "::error::Expected ESP-IDF at ${IDF_PATH}, but it was not found"
17+
exit 1
18+
fi
19+
20+
# shellcheck disable=SC1090
21+
source "${IDF_PATH}/export.sh"
22+
1023
echo "[preflight] Fetching external components..."
1124
python ./fetch_repos.py
1225

0 commit comments

Comments
 (0)