[wifi] Enable CYW43 STA mode before scanning on RP2040

Call cyw43_arch_enable_sta_mode() in wifi_mode_() when STA is requested.
Without this, cyw43_wifi_scan() fails on initial boot because the radio
isn't initialized yet - it only got enabled later inside beginNoBlock().
This caused the state machine to skip scanning, fall through to
RETRY_HIDDEN, and do a wasteful blind SSID-only connect for non-hidden
networks.
This commit is contained in:
J. Nick Koston
2026-02-26 11:39:42 -10:00
parent 7ad44c68f7
commit 7e1d25859c

View File

@@ -24,8 +24,11 @@ static bool s_sta_had_ip = false; // NOLINT(cppcoreguidelines-avoid-non-
static size_t s_scan_result_count = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
// STA mode is enabled by WiFi.beginNoBlock() via cyw43_arch_enable_sta_mode(),
// so we don't need to call cyw43_wifi_set_up() directly for STA.
if (sta.has_value() && sta.value()) {
// Enable STA mode so scanning works before the first beginNoBlock() call.
// Without this, cyw43_wifi_scan() fails because the radio isn't initialized.
cyw43_arch_enable_sta_mode();
}
bool ap_state = false;
if (ap.has_value()) {