Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32S3: import wifi crashes circuitpython #5662

Closed
jepler opened this issue Dec 4, 2021 · 8 comments · Fixed by #5858
Closed

ESP32S3: import wifi crashes circuitpython #5662

jepler opened this issue Dec 4, 2021 · 8 comments · Fixed by #5858
Assignees
Labels
bug crash espressif applies to multiple Espressif chips network
Milestone

Comments

@jepler
Copy link
Member

jepler commented Dec 4, 2021

CircuitPython version

Adafruit CircuitPython 7.2.0-alpha.0-5-g73ee59881-dirty on 2021-12-04; ESP32-S3-DevKitC-1 with ESP32S3

Code/REPL

import wifi

Behavior

On the REPL:

Adafruit CircuitPython 7.2.0-alpha.0-5-g73ee59881-dirty on 2021-12-04; ESP32-S3-DevKitC-1 with ESP32S3
>>> import wifi

[tio 09:24:44] Disconnected

On the serial debug console (build with DEBUG=1):

I (9913) pp: pp rom version: e7ae62f
I (9923) net80211: net80211 rom version: e7ae62f
I (9933) wifi:wifi driver task: 3fce4ecc, prio:23, stack:3584, core=0
I (9933) system_api: Base MAC address is not set
I (9933) system_api: read default base MAC address from EFUSE
I (9933) wifi:wifi firmware version: f84e709
I (9943) wifi:wifi certification version: v7.0
I (9943) wifi:config NVS flash: disabled
I (9943) wifi:config nano formating: disabled
I (9953) wifi:Init data frame dynamic rx buffer num: 8
I (9953) wifi:Init management frame dynamic rx buffer num: 8
I (9963) wifi:Init management short buffer num: 32
I (9963) wifi:Init dynamic tx buffer num: 16
I (9973) wifi:Init tx cache buffer num: 16
I (9973) wifi:Init static tx FG buffer num: 2
I (9973) wifi:Init static rx buffer size: 1600
I (9983) wifi:Init static rx buffer num: 4
I (9983) wifi:Init dynamic rx buffer num: 8
I (9993) wifi_init: rx ba win: 6
I (9993) wifi_init: tcpip mbox: 32
I (9993) wifi_init: udp mbox: 6
I (10003) wifi_init: tcp mbox: 6
I (10003) wifi_init: tcp tx win: 2880
I (10013) wifi_init: tcp rx win: 2880
I (10013) wifi_init: tcp mss: 1440
I (10013) wifi_init: WiFi IRAM OP enabled
I (10023) wifi_init: WiFi RX IRAM OP enabled
I (10033) phy_init: phy_version 302,ede2b68,Oct 20 2021,19:34:11
E (10033) phy_init: esp_phy_load_cal_data_from_nvs: NVS has not been initialized. Call nvs_flash_init before starting WiFi/BT.
W (10043) phy_init: failed to load RF calibration data (0x1101), falling back to full calibration
I (10093) wifi:set rx active PTI: 0, rx ack PTI: 0, and default PTI: 0
I (10093) wifi:mode : sta (7c:df:a1:e0:73:d8)
I (10093) wifi:enable tsf
W (10093) wifi: sta start

Description

As also reported by discord user "wgp", wifi doesn't seem to work at all with the esp32-s3

Additional information

No response

@dhalbert
Copy link
Collaborator

dhalbert commented Dec 5, 2021

Reproduced on ESP32-S3 Box as well.

@tannewt tannewt added crash espressif applies to multiple Espressif chips network labels Dec 6, 2021
@tannewt tannewt modified the milestones: 7.x.x, 7.2.0 Dec 20, 2021
@RetiredWizard
Copy link

RetiredWizard commented Jan 4, 2022

I'm seeing the same thing on an ESP32-S3-DevKitC-1:

Adafruit CircuitPython 7.2.0-alpha.1-16-gf2f38c7df-dirty on 2022-01-03; ESP32-S3-DevKitC-1 with ESP32S3

Has been working fine on my ESP32-S2 feather builds.

@RetiredWizard
Copy link

This clearly isn't surprising but I've traced the hang to line 98 of Radio.c in port/espressif/common-hal/wifi/.

        ESP_ERROR_CHECK(esp_wifi_start());

I've built the example fast_scan from the ESP-IDE and so far have been unable to recreate the crash.

@RetiredWizard
Copy link

RetiredWizard commented Jan 7, 2022

The S3 Dev Kit I'm using has two micro USB connectors, one shows up as /dev/ttyUSB0 and the other as /dev/ttyACM0. CircuitPython grabs the ACM0 port for the REPL and the DEBUG=1 output goes to the USB0 port.

After placing some mp_printf statements that go to the USB0 port and some ESP_LOGW statements that go to the ACM0 port, it looks to me like the micro controller is not hanging, it's just reseting the /dev/ttyACM0 port. The device disappears from linux but the USB0 port is still there and continues to print debug information out until it has nothing more to do.

I've placed print statements to both ports before and after the esp_wifi_start statement and here are the results:

/dev/ttyACM0

     Adafruit CircuitPython 7.2.0-alpha.1-39-g513a954d9-dirty on 2022-01-07; ESP32-S3-DevKitC3
     >>> import wifi
     Before esp_wifi_start

/dev/ttyUSB0

     I (19045) wifi_init: udp mbox: 6
     I (19045) wifi_init: tcp mbox: 6
     I (19055) wifi_init: tcp tx win: 2880
     I (19055) wifi_init: tcp rx win: 2880
     I (19065) wifi_init: tcp mss: 1440
     I (19065) wifi_init: WiFi IRAM OP enabled
     I (19065) wifi_init: WiFi RX IRAM OP enabled
     W (19075) myRadio: Before esp_wifi_start
     I (19075) phy_init: phy_version 302,3ddfab3,Dec  3 2021,14:39:12
     E (19085) phy_init: esp_phy_load_cal_data_from_nvs: NVS has not been initialized. Call nvs_flash_init before starting WiFi/BT.
     W (19095) phy_init: failed to load RF calibration data (0x1101), falling back to full calibration
     I (19145) wifi:mode : sta (7c:df:a1:e0:71:34)
     I (19145) wifi:enable tsf
     W (19145) wifi: sta start
     W (19145) myRadio: After esp_wifi_start

From the DEBUG=1 messages it looks to me like the esp_wifi_start completed and program control continued. The REPL interface was somehow reset though so the user is disconnected from the microcontroller.

The 'git diff' from the build that generated the above output:

        diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c
        index 9e4b7165a..839b9f4e1 100644
        --- a/ports/espressif/common-hal/wifi/Radio.c
        +++ b/ports/espressif/common-hal/wifi/Radio.c
        @@ -41,8 +41,12 @@
         #include "components/esp_wifi/include/esp_wifi.h"
         #include "components/lwip/include/apps/ping/ping_sock.h"
        
        +#include "components/log/include/esp_log.h"
        +
         #define MAC_ADDRESS_LENGTH 6
        
        +static const char *TAG = "myRadio";
        +
         static void set_mode_station(wifi_radio_obj_t *self, bool state) {
             wifi_mode_t next_mode;
             if (state) {
        @@ -95,7 +99,11 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
                 return;
             }
             if (!self->started && enabled) {
        +        mp_printf(&mp_plat_print, "Before esp_wifi_start\n");
        +        ESP_LOGW(TAG, "Before esp_wifi_start");
                 ESP_ERROR_CHECK(esp_wifi_start());
        +        mp_printf(&mp_plat_print, "After esp_wifi_start\n");
        +        ESP_LOGW(TAG, "After esp_wifi_start");
                 self->started = true;
                 return;
             }

@RetiredWizard
Copy link

Just for kicks, I modified an rgbblink program so that along with blinking the neopixel it manipulated a gpio pin in a way that the DEBUG output was updated and then added an "import wifi" statement.

When I imported the updated rgbblink from the REPL, the REPL froze up, but the neopixel kept blinking and the debug output continued to display updates for the GPIO pin updates.

@tannewt
Copy link
Member

tannewt commented Jan 7, 2022

@hathach Sounds like this could be a USB issue.

@hathach
Copy link
Member

hathach commented Jan 10, 2022

tinyuf2 seems to work on S3 as well on S2. Maybe there is some conflict, I will try to test this out tomorrow and see if I could spot anything.

@casainho
Copy link

casainho commented Jul 6, 2023

Please reopen this issue, as I have it on ESP32-S3 DevKitC N8R2, with CP 8.2.0.

I did apply this PR #5858 on CP 8.2.x and it solved my issue!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash espressif applies to multiple Espressif chips network
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants