Fixes to make 5.3.1 run without crashing.

This commit is contained in:
Jade Mattsson 2024-10-14 18:59:31 +11:00
parent d483fd94d8
commit 2814b8c624
3 changed files with 23 additions and 20 deletions

View File

@ -21,6 +21,7 @@
#include "esp_netif.h" #include "esp_netif.h"
#include "esp_vfs_dev.h" #include "esp_vfs_dev.h"
#include "esp_vfs_cdcacm.h" #include "esp_vfs_cdcacm.h"
#include "esp_vfs_console.h"
#include "esp_vfs_usb_serial_jtag.h" #include "esp_vfs_usb_serial_jtag.h"
#include "driver/uart_vfs.h" #include "driver/uart_vfs.h"
#include "driver/usb_serial_jtag.h" #include "driver/usb_serial_jtag.h"
@ -218,6 +219,8 @@ static void console_task(void *)
static void console_init(void) static void console_init(void)
{ {
esp_vfs_console_register();
fflush(stdout); fflush(stdout);
fsync(fileno(stdout)); fsync(fileno(stdout));

View File

@ -323,6 +323,17 @@ menu "NodeMCU modules"
help help
Includes the WiFi module (recommended). Includes the WiFi module (recommended).
config NODEMCU_CMODULE_WIFI_STARTUP_DELAY
depends on ESP_CONSOLE_USB_CDC
int "WiFi start-up delay (ms)"
default 500
help
For some unknown reason there is an issue with allowing the
WiFi stack to initialise immediately when using a USB CDC
console (at least on the ESP32-S2). The workaround is to
delay the initialisation sequence by enough that whatever
else is needing to run gets to run first.
config NODEMCU_CMODULE_WS2812 config NODEMCU_CMODULE_WS2812
bool "WS2812 module" bool "WS2812 module"
default "n" default "n"

View File

@ -93,22 +93,6 @@ static int wifi_stop (lua_State *L)
0 : luaL_error (L, "failed to stop wifi, code %d", err); 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_ap_init (void);
extern void wifi_sta_init (void); extern void wifi_sta_init (void);
static int wifi_init (lua_State *L) static int wifi_init (lua_State *L)
@ -117,11 +101,16 @@ static int wifi_init (lua_State *L)
wifi_sta_init (); wifi_sta_init ();
#if defined(CONFIG_ESP_CONSOLE_USB_CDC) #if defined(CONFIG_ESP_CONSOLE_USB_CDC)
th = task_get_id(do_esp_wifi_init); // For some unknown reason, on an S2 with USB CDC console enabled, if we allow
task_post_low(th, 0); // the esp_wifi_init() to run during initial startup, something Bad(tm)
#else // happens and the S2 fails to enumerate on the USB bus. However, if we defer
do_esp_wifi_init(0, 0); // it by half a second or so, everything works. This is an ugly workaround,
// but I'm out of ideas at this point.
vTaskDelay(CONFIG_NODEMCU_CMODULE_WIFI_STARTUP_DELAY / portTICK_PERIOD_MS);
#endif #endif
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init (&cfg));
return 0; return 0;
} }