Skip to content

Commit d6bc34a

Browse files
committed
esp32: Add a small delay before leaving wlan.active().
The delay is 1 ms. It avoids the crashes reported by the issues adafruit#8289, adafruit#8792 and adafruit#9236 with esp-idf versions >= 4.2, but does not solve an underlying problem in the esp-idf.
1 parent 30db33d commit d6bc34a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ports/esp32/network_wlan.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "py/objlist.h"
3737
#include "py/runtime.h"
38+
#include "py/mphal.h"
3839
#include "modnetwork.h"
3940

4041
#include "esp_wifi.h"
@@ -210,6 +211,12 @@ STATIC mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) {
210211
wifi_started = true;
211212
}
212213
}
214+
// This delay is a band-aid patch for issues #8289, #8792 and #9236,
215+
// allowing the esp data structures to settle. It looks like some
216+
// kind of race condition, which is not yet found. But at least
217+
// this small delay seems not hurt much, since wlan.active() is
218+
// usually not called in a time critical part of the code.
219+
mp_hal_delay_ms(1);
213220
}
214221

215222
return (mode & bit) ? mp_const_true : mp_const_false;

0 commit comments

Comments
 (0)