Workaround for using wifi module on S2 with USB-CDC console.
This commit is contained in:
parent
eba58124bc
commit
2053549689
|
@ -34,6 +34,7 @@
|
|||
#include "lauxlib.h"
|
||||
#include "lextra.h"
|
||||
#include "wifi_common.h"
|
||||
#include "task/task.h"
|
||||
|
||||
static int wifi_getmode (lua_State *L)
|
||||
{
|
||||
|
@ -92,7 +93,21 @@ static int wifi_stop (lua_State *L)
|
|||
0 : luaL_error (L, "failed to stop wifi, code %d", err);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ESP_CONSOLE_USB_CDC)
|
||||
// For some unknown reason, on an S2 with USB CDC console enabled, if we allow
|
||||
// the esp_wifi_init() to run during initial startup, something Bad(tm)
|
||||
// happens and the S2 fails to enumerate on the USB bus. However, if we defer
|
||||
// the wifi initialisation, it starts up fine. This is an ugly workaround, but
|
||||
// I'm out of ideas at this point. If I use a UART console, I see no errors
|
||||
// even with the immediate init.
|
||||
static task_handle_t th;
|
||||
#endif
|
||||
|
||||
static void do_esp_wifi_init(task_param_t p, task_prio_t)
|
||||
{
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init (&cfg));
|
||||
}
|
||||
|
||||
extern void wifi_ap_init (void);
|
||||
extern void wifi_sta_init (void);
|
||||
|
@ -101,10 +116,13 @@ static int wifi_init (lua_State *L)
|
|||
wifi_ap_init ();
|
||||
wifi_sta_init ();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_err_t err = esp_wifi_init (&cfg);
|
||||
return (err == ESP_OK) ?
|
||||
0 : luaL_error (L, "failed to init wifi, code %d", err);
|
||||
#if defined(CONFIG_ESP_CONSOLE_USB_CDC)
|
||||
th = task_get_id(do_esp_wifi_init);
|
||||
task_post_low(th, 0);
|
||||
#else
|
||||
do_esp_wifi_init(0, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue