Skip to content

fix(wifi): stabilize hosted softap bringup#175

Merged
baba-dev merged 3 commits into
mainfrom
codex/fix-bootloop-and-memory-issues
Sep 21, 2025
Merged

fix(wifi): stabilize hosted softap bringup#175
baba-dev merged 3 commits into
mainfrom
codex/fix-bootloop-and-memory-issues

Conversation

@baba-dev
Copy link
Copy Markdown
Owner

Summary

  • add a power-up guard time and call esp_hosted_slave_reset() before enabling the hosted SoftAP
  • bail out cleanly when the hosted transport or SoftAP start fails, logging the failure and powering down the radio
  • surface Wi-Fi bring-up errors through startWifiAp() so callers can see that provisioning is unavailable

Testing

  • bash tools/install_idf.sh
  • idf.py set-target esp32p4
  • idf.py build

https://chatgpt.com/codex/tasks/task_e_68d03a4e550483248162aad6d5b44af9

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 168 to +228
bool HalEsp32::wifi_init()
{
static bool s_wifi_task_started = false;
auto& state = wifi_state();
portMUX_TYPE& spinlock = wifi_state_spinlock();

mclog::tagInfo(TAG, "wifi init");
portENTER_CRITICAL(&spinlock);
bool already_started = state.started;
bool previously_failed = state.failed;
state.attempted = true;
portEXIT_CRITICAL(&spinlock);

esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
if (already_started)
{
return true;
}
if (previously_failed)
{
ESP_LOGW(TAG, "Skipping Wi-Fi init after previous failure");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Guard against concurrent wifi_init calls

The new runtime state tracks only started and failed, so two tasks calling startWifiAp() at the same time will both see state.started == false and enter the body of wifi_init() despite the spinlock. This results in two simultaneous calls to bsp_set_wifi_power_enable, esp_hosted_slave_reset, and start_softap, which can double‑reset the hosted coprocessor and race esp‑netif initialisation. The previous implementation offloaded the work to a single task so duplicate invocations were effectively idempotent, but the synchronous refactor makes the race far more likely and can leave the Wi‑Fi stack in an undefined state. Consider marking an “in‑progress” flag (e.g. reuse attempted) before releasing the lock so that concurrent callers bail out until the first attempt completes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex fix comments

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Testing

  • ⚠️ idf.py build (fails: command not found in Codex workspace)

View task →

@baba-dev baba-dev merged commit caaf671 into main Sep 21, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant