esp-idf-svc icon indicating copy to clipboard operation
esp-idf-svc copied to clipboard

ESP32-C3-DevKitM-1: Boot loop when scanning for wifi APs

Open cdata opened this issue 3 years ago • 23 comments

Hello, I am following along with the instructions to run https://github.com/ivmarkov/rust-esp32-std-hello on my ESP32-C3-DevKitM-1.

I was able to build and flash the demo application to my board.

Unfortunately, it appears to boot loop when scanning for access points. Here is the full output from a single loop iteration:

ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x403842e6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x14
load:0x3fcd6114,len:0x17dc
load:0x403ce000,len:0x86c
load:0x403d0000,len:0x29b4
entry 0x403ce000
I (31) boot: ESP-IDF qa-test-v4.3-20201113-876-gd6a9 2nd stage bootloader
I (31) boot: compile time 19:39:33
I (32) boot: chip revision: 0
I (41) boot.esp32c3: SPI Speed      : 80MHz
I (41) boot.esp32c3: SPI Mode       : DIO
I (45) boot.esp32c3: SPI Flash Size : 4MB
I (50) boot: Enabling RNG early entropy source...
W (55) bootloader_random: RNG for ESP32-C3 not currently supported
I (62) boot: Partition Table:
I (65) boot: ## Label            Usage          Type ST Offset   Length
I (73) boot:  0 sec_cert         unknown          3f 00 0000d000 00003000
I (80) boot:  1 nvs              WiFi data        01 02 00010000 00006000
I (88) boot:  2 otadata          OTA data         01 00 00016000 00002000
I (95) boot:  3 phy_init         RF data          01 01 00018000 00001000
I (103) boot:  4 ota_0            OTA app          00 10 00020000 00190000
I (110) boot:  5 ota_1            OTA app          00 11 001b0000 00190000
I (118) boot:  6 fctry            WiFi data        01 02 00340000 00006000
I (125) boot:  7 coredump         Unknown data     01 03 00350000 00010000
I (133) boot: End of partition table
I (137) esp_image: segment 0: paddr=0x00020020 vaddr=0x3c0c0020 size=0x296b8 (169656) map
I (174) esp_image: segment 1: paddr=0x000496e0 vaddr=0x3fc8e200 size=0x03500 ( 13568) load
I (177) esp_image: segment 2: paddr=0x0004cbe8 vaddr=0x40380000 size=0x03430 ( 13360) load
I (183) esp_image: segment 3: paddr=0x00050020 vaddr=0x42000020 size=0xb3a90 (735888) map
I (311) esp_image: segment 4: paddr=0x00103ab8 vaddr=0x40383430 size=0x0ad2c ( 44332) load
I (321) esp_image: segment 5: paddr=0x0010e7ec vaddr=0x50000000 size=0x00010 (    16) load
I (326) boot: Loaded app from partition at offset 0x20000
I (326) boot: Disabling RNG early entropy source...
W (330) bootloader_random: RNG for ESP32-C3 not currently supported
I (348) cpu_start: Pro cpu up.
I (360) cpu_start: Pro cpu start user code
I (360) cpu_start: cpu freq: 160000000
I (360) cpu_start: Application information:
I (363) cpu_start: Project name:     esp-idf
I (368) cpu_start: App version:      29b6481-dirty
I (374) cpu_start: Compile time:     Aug 24 2021 13:13:42
I (380) cpu_start: ELF file SHA256:  0000000000000000...
I (386) cpu_start: ESP-IDF:          4.3.0
I (390) heap_init: Initializing. RAM available for dynamic allocation:
I (398) heap_init: At 3FC96300 len 00029D00 (167 KiB): DRAM
I (404) heap_init: At 3FCC0000 len 0001F260 (124 KiB): STACK/DRAM
I (411) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM
I (417) spi_flash: detected chip: generic
I (422) spi_flash: flash io: dio
I (426) sleep: Configure to isolate all GPIO pins in sleep state
I (432) sleep: Enable automatic switching of GPIO sleep configuration
I (440) cpu_start: Starting scheduler.
Hello, world from Rust!
More complex print ["foo", "bar"]
Result: 0, 1
Rust main thread: Thread { id: ThreadId(1), name: Some("main"), .. }
This is thread number 0, Thread { id: ThreadId(2), name: None, .. }
This is thread number 1, Thread { id: ThreadId(3), name: None, .. }
This is thread number 2, Thread { id: ThreadId(4), name: None, .. }
This is thread number 3, Thread { id: ThreadId(5), name: None, .. }
This is thread number 4, Thread { id: ThreadId(6), name: None, .. }
About to join the threads. If ESP-IDF was patched successfully, joining will NOT crash
Joins were successful.
I (2556) pp: pp rom version: 8459080
I (2556) net80211: net80211 rom version: 8459080
I (2566) wifi:wifi driver task: 3fc9ff30, prio:23, stack:6656, core=0
I (2566) system_api: Base MAC address is not set
I (2566) system_api: read default base MAC address from EFUSE
I (2566) wifi:wifi firmware version: c7d0450
I (2576) wifi:wifi certification version: v7.0
I (2576) wifi:config NVS flash: disabled
I (2576) wifi:config nano formating: disabled
I (2586) wifi:Init data frame dynamic rx buffer num: 32
I (2586) wifi:Init management frame dynamic rx buffer num: 32
I (2596) wifi:Init management short buffer num: 32
I (2596) wifi:Init dynamic tx buffer num: 32
I (2606) wifi:Init static tx FG buffer num: 2
I (2606) wifi:Init static rx buffer size: 1600
I (2616) wifi:Init static rx buffer num: 10
I (2616) wifi:Init dynamic rx buffer num: 32
I (2616) wifi_init: rx ba win: 6
I (2626) wifi_init: tcpip mbox: 32
I (2626) wifi_init: udp mbox: 6
I (2636) wifi_init: tcp mbox: 6
I (2636) wifi_init: tcp tx win: 5744
I (2636) wifi_init: tcp rx win: 5744
I (2646) wifi_init: tcp mss: 1440
I (2646) wifi_init: WiFi IRAM OP enabled
I (2656) wifi_init: WiFi RX IRAM OP enabled
I (2656) esp_idf_svc::wifi: Driver initialized
I (2666) esp_idf_svc::wifi: Event handlers registered
I (2666) esp_idf_svc::wifi: Initialization complete
I (2676) rust_esp32_std_hello: Wifi created, about to scan
I (2676) esp_idf_svc::wifi: About to scan for access points
I (2686) esp_idf_svc::wifi: Stopping
I (2686) esp_idf_svc::wifi: Disconnect requested
I (2696) esp_idf_svc::wifi: Stop requested
I (2696) esp_idf_svc::wifi: About to wait for status
I (2706) esp_idf_svc::wifi: Providing status: Status(Stopped, Stopped)
I (2716) esp_idf_svc::wifi: Waiting for status done - success
I (2716) esp_idf_svc::wifi: Stopped
I (2726) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08
Guru Meditation Error: Core  0 panic'ed (Illegal instruction). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x40001be4  RA      : 0x42091c7c  SP      : 0x3fc9fd10  GP      : 0x3fc8ea00
TP      : 0x3fc76868  T0      : 0x40057fa6  T1      : 0x0000000f  T2      : 0xffffffff
S0/FP   : 0x3fc955b4  S1      : 0x3fc955b0  A0      : 0x3fc8f684  A1      : 0x40001a8c
A2      : 0x3fc8f000  A3      : 0x400019f0  A4      : 0x40001964  A5      : 0x3fcdf4f8
A6      : 0x42052ca0  A7      : 0x0000000a  S2      : 0x3fc955b0  S3      : 0x00000002
S4      : 0x3fc92ee0  S5      : 0x3fce0000  S6      : 0x3fce0000  S7      : 0x3fce0000
S8      : 0x3ff1b000  S9      : 0x3fce0000  S10     : 0x3fcdf8d4  S11     : 0x00000000
T3      : 0x00000000  T4      : 0xffffffff  T5      : 0xffffffff  T6      : 0xffffffff
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000002  MTVAL   : 0x00000000
MHARTID : 0x00000000

Stack memory:
3fc9fd10: 0x3c0d1f60 0x3fca5284 0x3fca5284 0x42092540 0x50500000 0x484c4c50 0x4448484c 0x4246464a
3fc9fd30: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd50: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd70: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd90: 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc90eec 0x3fce0000 0x3fc92ee0 0x3fc93000
3fc9fdb0: 0x00000000 0x3fc92ee0 0x3fca5284 0x42028664 0xffffffff 0x3fc92ee0 0x3fce0000 0x42028732
3fc9fdd0: 0x00000000 0x3fc92ee0 0x3fc92ee0 0x420744ce 0x00000002 0x00000000 0x3fc92ee0 0x00000001
3fc9fdf0: 0x00000001 0x00000000 0x3fc92ee0 0x420745e2 0x3fca5214 0x00000000 0x00000000 0x3fc8e8e0
3fc9fe10: 0x3fca5214 0x00000008 0x00000001 0x42071764 0x00000000 0x3fcdf918 0x3fce0000 0x3ff1b594
3fc9fe30: 0x00000000 0x3fcdf918 0x3fce0000 0x4003fe8a 0x00000000 0x00000000 0x00000006 0x3fca5214
3fc9fe50: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fe70: 0x00000000 0x00000000 0x00000000 0x4038967a 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fe90: 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x27146414 0x00000000 0x00000000 0x01010107
3fc9feb0: 0x00000001 0x00000000 0xffffffff 0x7fefffff 0x00000000 0x3fc00000 0x00000000 0x40300000
3fc9fed0: 0x00000000 0x3fe00000 0x00000000 0x3ff80000 0x636f4361 0x3fd287a7 0x8b60c8b3 0x3fc68a28
3fc9fef0: 0x509f79fb 0x3fd34413 0x00000000 0x3ff00000 0x00000000 0x40240000 0x00000000 0x401c0000
3fc9ff10: 0x00000000 0x40140000 0x00000000 0x43500000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000154
3fc9ff30: 0x3fc9fd60 0x3fc96314 0x3fc91f24 0x3fc91f24 0x3fc9ff30 0x3fc91f1c 0x00000002 0x3fc9de68
3fc9ff50: 0x3fc9de68 0x3fc9ff30 0x00000000 0x00000017 0x3fc9e52c 0x69666977 0x5f1a5600 0xc88e8184
3fc9ff70: 0x00212e8e 0x00000000 0x3fc9ff20 0x00000017 0x00000001 0x00000000 0x00000000 0x00000000
3fc9ff90: 0x3fc96b2c 0x3fc96b94 0x3fc96bfc 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000
3fc9ffb0: 0x00000000 0x42099f0c 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9ffd0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fff0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0010: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0030: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0050: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0070: 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc90000 0x00000054 0x3fca0088 0x3fca0088
3fca0090: 0x3fca0088 0x3fca0088 0x00000000 0x3fca00a0 0xffffffff 0x3fca00a0 0x3fca00a0 0x00000000
3fca00b0: 0x3fca00b4 0xffffffff 0x3fca00b4 0x3fca00b4 0x00000000 0x00000001 0x00000000 0xf400ffff
3fca00d0: 0x00000000 0x6d5a935a 0x3fca0080 0x00000054 0x00000000 0x3fca00e0 0x00000000 0x00000000
3fca00f0: 0x00000000 0x3fca00f8 0xffffffff 0x3fca00f8 0x3fca00f8 0x00000000 0x3fca010c 0xffffffff



ELF file SHA256: 0000000000000000

Rebooting...

Any insight into what could be going on would be appreciated. I am able to provide any further details if it is helpful.

cdata avatar Aug 24 '21 21:08 cdata

I dug a little deeper; the panic is happening during the invocation of esp_wifi_start here:

https://github.com/esp-rs/esp-idf-svc/blob/5b487fc045af6440b317836afba81c6a19f5de2f/src/wifi.rs#L604-L609

I tried patching the code so that I could observe an error, but I guess the panic is occurring deeper in the call stack, so I wasn't able to observe anything.

cdata avatar Aug 25 '21 18:08 cdata

I know you've probably done that but still: can you please:

  • git pull the rust-esp32-std-hello project
  • cargo update the rust-esp32-std-hello project
  • cargo clean and then cargo build

There was a recent regression in how EspMutex from esp-idf-sys was implemented (used in the wifi code). The chance that this is causing the problem is extremely low, but let's try that first.

ivmarkov avatar Aug 26 '21 08:08 ivmarkov

Thank you for the fast response! I tried updating and rebuilding as you suggested and unfortunately I'm still seeing the same issue. Below are the results of some of the commands at the time of my attempt to follow your suggestion:

git pull:

Already up to date

cargo update:

    Updating crates.io index
    Updating git repository `https://github.com/ivmarkov/ili9341-rs`
    Updating cargo_toml v0.9.2 -> v0.9.3
    Updating clang-sys v1.2.0 -> v1.2.1
    Updating libc v0.2.100 -> v0.2.101

cdata avatar Aug 26 '21 16:08 cdata

One more thing then:

  • Please install/update cargo-pio: cargo install cargo-pio
  • Use the following brand new ESP monitor (just implemented!): cargo pio espidf monitor /dev/ttyUSB0 (need to run this from within the rust-esp32-std-hello project, so that the Elf file is captured for stacktrace decoding)

This one starts slowly, but is capable of decoding stack traces, including on the ESP32C3. It might not tell us something we don't know yet, but good to see its output just in case.

ivmarkov avatar Aug 26 '21 16:08 ivmarkov

I tried it out. Unfortunately, this didn't seem to actually decode the stack trace. The output is almost the same as what I got with screen:

Found compatible PlatformIO Core 5.1.1 -> /home/cdata/.platformio/penv/bin/platformio
platformio.ini not found in /home/cdata/repositories/github.com/ivmarkov/rust-esp32-std-hello, assuming a Cargo-first project
Found /home/cdata/repositories/github.com/ivmarkov/rust-esp32-std-hello/.cargo/config.toml
Using pre-configured target riscv32imc-esp-espidf
Configuring MCU 'ESP32C3' derived from the build target 'riscv32imc-esp-espidf'
Configuring board 'esp32-c3-devkitm-1' which supports configured platform 'espressif32', MCU 'ESP32C3' and configured frameworks [espidf]
Resolved platform: 'espressif32', MCU: 'ESP32C3', board: 'esp32-c3-devkitm-1', frameworks: [espidf]
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
Esp32ExceptionDecoder: firmware at /tmp/.tmpI3JKEN/proj/.pio/build/debug/firmware.elf does not exist, rebuild the project?
--- Miniterm on /dev/ttyUSB0  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Joins were successful.
I (2556) pp: pp rom version: 8459080
I (2556) net80211: net80211 rom version: 8459080
I (2566) wifi:wifi driver task: 3fc9ff30, prio:23, stack:6656, core=0
I (2566) system_api: Base MAC address is not set
I (2566) system_api: read default base MAC address from EFUSE
I (2566) wifi:wifi firmware version: c7d0450
I (2576) wifi:wifi certification version: v7.0
I (2576) wifi:config NVS flash: disabled
I (2576) wifi:config nano formating: disabled
I (2586) wifi:Init data frame dynamic rx buffer num: 32
I (2586) wifi:Init management frame dynamic rx buffer num: 32
I (2596) wifi:Init management short buffer num: 32
I (2596) wifi:Init dynamic tx buffer num: 32
I (2606) wifi:Init static tx FG buffer num: 2
I (2606) wifi:Init static rx buffer size: 1600
I (2616) wifi:Init static rx buffer num: 10
I (2616) wifi:Init dynamic rx buffer num: 32
I (2616) wifi_init: rx ba win: 6
I (2626) wifi_init: tcpip mbox: 32
I (2626) wifi_init: udp mbox: 6
I (2636) wifi_init: tcp mbox: 6
I (2636) wifi_init: tcp tx win: 5744
I (2636) wifi_init: tcp rx win: 5744
I (2646) wifi_init: tcp mss: 1440
I (2646) wifi_init: WiFi IRAM OP enabled
I (2656) wifi_init: WiFi RX IRAM OP enabled
I (2656) esp_idf_svc::wifi: Driver initialized
I (2666) esp_idf_svc::wifi: Event handlers registered
I (2666) esp_idf_svc::wifi: Initialization complete
I (2676) rust_esp32_std_hello: Wifi created, about to scan
I (2676) esp_idf_svc::wifi: About to scan for access points
I (2686) esp_idf_svc::wifi: Stopping
I (2686) esp_idf_svc::wifi: Disconnect requested
I (2696) esp_idf_svc::wifi: Stop requested
I (2696) esp_idf_svc::wifi: About to wait for status
I (2706) esp_idf_svc::wifi: Providing status: Status(Stopped, Stopped)
I (2716) esp_idf_svc::wifi: Waiting for status done - success
I (2716) esp_idf_svc::wifi: Stopped
I (2726) esp_idf_svc::wifi: esp_wifi_set_mode
I (2726) esp_idf_svc::wifi: esp_wifi_start
I (2736) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08
Guru Meditation Error: Core  0 panic'ed (Illegal instruction). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x40001be4  RA      : 0x42091be8  SP      : 0x3fc9fd10  GP      : 0x3fc8ea00
TP      : 0x3fc765d8  T0      : 0x40057fa6  T1      : 0x0000000f  T2      : 0xffffffff
S0/FP   : 0x3fc955b4  S1      : 0x3fc955b0  A0      : 0x3fc8f684  A1      : 0x40001a8c
A2      : 0x3fc8f000  A3      : 0x400019f0  A4      : 0x40001964  A5      : 0x3fcdf4f8
A6      : 0x42052c0c  A7      : 0x0000000a  S2      : 0x3fc955b0  S3      : 0x00000002
S4      : 0x3fc92ee0  S5      : 0x3fce0000  S6      : 0x3fce0000  S7      : 0x3fce0000
S8      : 0x3ff1b000  S9      : 0x3fce0000  S10     : 0x3fcdf8d4  S11     : 0x00000000
T3      : 0x00000000  T4      : 0xffffffff  T5      : 0xffffffff  T6      : 0xffffffff
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000002  MTVAL   : 0x00000000
MHARTID : 0x00000000

Stack memory:
3fc9fd10: 0x3c0d21f0 0x3fca5284 0x3fca5284 0x420924ac 0x50500000 0x484c4c50 0x4448484c 0x4246464a
3fc9fd30: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd50: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd70: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd90: 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc90eec 0x3fce0000 0x3fc92ee0 0x3fc93000
3fc9fdb0: 0x00000000 0x3fc92ee0 0x3fca5284 0x420285d0 0xffffffff 0x3fc92ee0 0x3fce0000 0x4202869e
3fc9fdd0: 0x00000000 0x3fc92ee0 0x3fc92ee0 0x4207443a 0x00000002 0x00000000 0x3fc92ee0 0x00000001
3fc9fdf0: 0x00000001 0x00000000 0x3fc92ee0 0x4207454e 0x3fca5214 0x00000000 0x00000000 0x3fc8e8e0
3fc9fe10: 0x3fca5214 0x00000008 0x00000001 0x420716d0 0x00000000 0x3fcdf918 0x3fce0000 0x3ff1b594
3fc9fe30: 0x00000000 0x3fcdf918 0x3fce0000 0x4003fe8a 0x00000000 0x00000000 0x00000006 0x3fca5214
3fc9fe50: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fe70: 0x00000000 0x00000000 0x00000000 0x4038967a 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fe90: 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x27146414 0x00000000 0x00000000 0x01010107
3fc9feb0: 0x00000001 0x00000000 0xffffffff 0x7fefffff 0x0000000...

The output does indicate that esp32_exception_decoder is an available filter, but the link sends me to documentation for the PlatformIO monitor (the --filter flag isn't recognized by cargo-pio).

cdata avatar Aug 26 '21 16:08 cdata

Oh, it's right in front of me!

Esp32ExceptionDecoder: firmware at /tmp/.tmpI3JKEN/proj/.pio/build/debug/firmware.elf does not exist, rebuild the project?

Trying again...

cdata avatar Aug 26 '21 16:08 cdata

Yes, that's the crux of the issue: it does not detect the ELF file in your /target directory.

Here's something you can check: can you go to ~/.platformio/platforms/espressif32/monitor. There's a .py file in there. Can you paste its contents? I suspect the cargo pio espidf monitor fails to patch it on your PC, for whatever reason.

ivmarkov avatar Aug 26 '21 16:08 ivmarkov

~/.platformio/platforms/espressif32/monitor/filter_exception_decoder.py:

# Copyright (c) 2014-present PlatformIO <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import subprocess
import sys

from platformio.compat import path_to_unicode, WINDOWS, PY2
from platformio.project.exception import PlatformioException
from platformio.project.helpers import load_project_ide_data
from platformio.commands.device import DeviceMonitorFilter

# By design, __init__ is called inside miniterm and we can't pass context to it.
# pylint: disable=attribute-defined-outside-init


class Esp32ExceptionDecoder(DeviceMonitorFilter):
    NAME = "esp32_exception_decoder"

    def __call__(self):
        self.buffer = ""
        self.backtrace_re = re.compile(
            r"^Backtrace: ?((0x[0-9a-fA-F]+:0x[0-9a-fA-F]+ ?)+)\s*"
        )

        self.firmware_path = None
        self.addr2line_path = None
        self.enabled = self.setup_paths()

        if self.config.get("env:" + self.environment, "build_type") != "debug":
            print(
                """
Please build project in debug configuration to get more details about an exception.
See https://docs.platformio.org/page/projectconf/build_configurations.html

"""
            )

        return self

    def setup_paths(self):
        self.project_dir = path_to_unicode(os.path.abspath(self.project_dir))
        try:
            data = load_project_ide_data(self.project_dir, self.environment)
            self.firmware_path = data["prog_path"]
            if not os.path.isfile(self.firmware_path):
                sys.stderr.write(
                    "%s: firmware at %s does not exist, rebuild the project?\n"
                    % (self.__class__.__name__, self.firmware_path)
                )
                return False

            cc_path = data.get("cc_path", "")
            if "-gcc" in cc_path:
                path = cc_path.replace("-gcc", "-addr2line")
                if os.path.isfile(path):
                    self.addr2line_path = path
                    return True
        except PlatformioException as e:
            sys.stderr.write(
                "%s: disabling, exception while looking for addr2line: %s\n"
                % (self.__class__.__name__, e)
            )
            return False
        sys.stderr.write(
            "%s: disabling, failed to find addr2line.\n" % self.__class__.__name__
        )
        return False

    def rx(self, text):
        if not self.enabled:
            return text

        last = 0
        while True:
            idx = text.find("\n", last)
            if idx == -1:
                if len(self.buffer) < 4096:
                    self.buffer += text[last:]
                break

            line = text[last:idx]
            if self.buffer:
                line = self.buffer + line
                self.buffer = ""
            last = idx + 1

            m = self.backtrace_re.match(line)
            if m is None:
                continue

            trace = self.get_backtrace(m)
            if len(trace) != "":
                text = text[: idx + 1] + trace + text[idx + 1 :]
                last += len(trace)
        return text

    def get_backtrace(self, match):
        trace = ""
        enc = "mbcs" if WINDOWS else "utf-8"
        args = [self.addr2line_path, u"-fipC", u"-e", self.firmware_path]
        if PY2:
            args = [a.encode(enc) for a in args]
        try:
            for i, addr in enumerate(match.group(1).split()):
                if PY2:
                    addr = addr.encode(enc)
                output = (
                    subprocess.check_output(args + [addr])
                    .decode(enc)
                    .strip()
                )
                output = output.replace(
                    "\n", "\n     "
                )  # newlines happen with inlined methods
                output = self.strip_project_dir(output)
                trace += "  #%-2d %s in %s\n" % (i, addr, output)
        except subprocess.CalledProcessError as e:
            sys.stderr.write(
                "%s: failed to call %s: %s\n"
                % (self.__class__.__name__, self.addr2line_path, e)
            )
        return trace

    def strip_project_dir(self, trace):
        while True:
            idx = trace.find(self.project_dir)
            if idx == -1:
                break
            trace = trace[:idx] + trace[idx + len(self.project_dir) + 1 :]
        return trace

cdata avatar Aug 26 '21 17:08 cdata

Yep. This is not patched at all. In ~/.platformio/platforms/espressif32 (one directory up) there should at least be a long filename named filter_exception_decoder_esp32c3_external_conf_fix.diff.applied. Is it present on your PC?

ivmarkov avatar Aug 26 '21 17:08 ivmarkov

Yes, I see it there :+1:

cdata avatar Aug 26 '21 17:08 cdata

OK so it attempted to patch and silently failed. Go figure. Hold on... Oh, you do have git on your $path right?

ivmarkov avatar Aug 26 '21 17:08 ivmarkov

Yes, git is on my $PATH :+1:

cdata avatar Aug 26 '21 17:08 cdata

Super-strange. If I take the .py file you've pasted it and use it, it is patched correctly... I'm a bit at a loss...

OK, here's a quick hack: take the file content below and paste it in the filter_exception_decoder.py file you have there. Manual patching so to say. Then re-run the monitor:

# Copyright (c) 2014-present PlatformIO <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import subprocess
import sys

from platformio.compat import path_to_unicode, WINDOWS, PY2
from platformio.project.exception import PlatformioException
from platformio.project.helpers import load_project_ide_data
from platformio.commands.device import DeviceMonitorFilter

# By design, __init__ is called inside miniterm and we can't pass context to it.
# pylint: disable=attribute-defined-outside-init


class Esp32ExceptionDecoder(DeviceMonitorFilter):
    NAME = "esp32_exception_decoder"

    def __call__(self):
        self.buffer = ""
        # regex matches potential PC value (0x4xxxxxxx)
        # Logic identical to https://github.com/espressif/esp-idf/blob/master/tools/idf_monitor_base/constants.py#L56
        self.pcaddr_re = re.compile(r'0x4[0-9a-f]{7}', re.IGNORECASE)

        self.firmware_path = None
        self.addr2line_path = None
        self.enabled = self.setup_paths()

        return self

    def setup_paths(self):
        self.project_dir = path_to_unicode(os.path.abspath(self.project_dir))

        self.project_strip_dir = os.environ.get("esp32_exception_decoder_project_strip_dir")
        self.firmware_path = os.environ.get("esp32_exception_decoder_firmware_path")
        self.addr2line_path = os.environ.get("esp32_exception_decoder_addr2line_path")

        if self.project_strip_dir is None:
            self.project_strip_dir = self.project_dir

        try:
            if self.firmware_path is None or self.addr2line_path is None:
                # Only load if necessary, as the call is expensive
                data = load_project_ide_data(self.project_dir, self.environment)

            if self.firmware_path is None:
                # Only do this check when the firmware path is not externally provided
                if self.config.get("env:" + self.environment, "build_type") != "debug":
                    print(
                """
Please build project in debug configuration to get more details about an exception.
See https://docs.platformio.org/page/projectconf/build_configurations.html

"""
                    )
                self.firmware_path = data["prog_path"]

            if not os.path.isfile(self.firmware_path):
                sys.stderr.write(
                    "%s: disabling, firmware at %s does not exist, rebuild the project?\n"
                    % (self.__class__.__name__, self.firmware_path)
                )
                return False

            if self.addr2line_path is None:
                cc_path = data.get("cc_path", "")
                if "-gcc" in cc_path:
                    self.addr2line_path = cc_path.replace("-gcc", "-addr2line")
                else:
                    sys.stderr.write(
                        "%s: disabling, failed to find addr2line.\n" % self.__class__.__name__
                    )
                    return False

            if not os.path.isfile(self.addr2line_path):
                sys.stderr.write(
                    "%s: disabling, addr2line at %s does not exist\n"
                    % (self.__class__.__name__, self.addr2line_path)
                )
                return False

            return True
        except PlatformioException as e:
            sys.stderr.write(
                "%s: disabling, exception while looking for addr2line: %s\n"
                % (self.__class__.__name__, e)
            )
            return False

    def rx(self, text):
        if not self.enabled:
            return text

        last = 0
        while True:
            idx = text.find("\n", last)
            if idx == -1:
                if len(self.buffer) < 4096:
                    self.buffer += text[last:]
                break

            line = text[last:idx]
            if self.buffer:
                line = self.buffer + line
                self.buffer = ""
            last = idx + 1

            # Output each trace on a separate line below ours
            # Logic identical to https://github.com/espressif/esp-idf/blob/master/tools/idf_monitor_base/logger.py#L131
            for m in re.finditer(self.pcaddr_re, line):
                if m is None:
                    continue

                trace = self.get_backtrace(m)
                if len(trace) != "":
                    text = text[: last] + trace + text[last :]
                    last += len(trace)

        return text

    def get_backtrace(self, match):
        trace = ""
        enc = "mbcs" if WINDOWS else "utf-8"
        args = [self.addr2line_path, u"-fipC", u"-e", self.firmware_path]
        if PY2:
            args = [a.encode(enc) for a in args]
        try:
            addr = match.group()
            if PY2:
                addr = addr.encode(enc)
            output = (
                subprocess.check_output(args + [addr])
                .decode(enc)
                .strip()
            )
            output = output.replace(
                "\n", "\n     "
            )  # newlines happen with inlined methods
            output = self.strip_project_dir(output)
            # Output the trace in yellow color so that it is easier to spot
            trace += "\033[33m=> %s: %s\033[0m\n" % (addr, output)
        except subprocess.CalledProcessError as e:
            sys.stderr.write(
                "%s: failed to call %s: %s\n"
                % (self.__class__.__name__, self.addr2line_path, e)
            )
        return trace

    def strip_project_dir(self, trace):
        while True:
            idx = trace.find(self.project_strip_dir)
            if idx == -1:
                break
            trace = trace[:idx] + trace[idx + len(self.project_strip_dir) + 1 :]
        return trace

ivmarkov avatar Aug 26 '21 17:08 ivmarkov

We have a stack trace! Here is a full boot loop of output:

Rebooting...
��ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x403842e6
=> 0x403842e6: esp_restart_noos at /home/cdata/.platformio/packages/framework-espidf/components/esp32c3/system_api_esp32c3.c:137 (discriminator 1)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x14
load:0x3fcd6114,len:0x17dc
load:0x403ce000,len:0x86c
=> 0x403ce000: ?? ??:0
load:0x403d0000,len:0x29b4
=> 0x403d0000: ?? ??:0
entry 0x403ce000
=> 0x403ce000: ?? ??:0
I (31) boot: ESP-IDF qa-test-v4.3-20201113-876-gd6a9 2nd stage bootloader
I (31) boot: compile time 19:39:33
I (32) boot: chip revision: 0
I (36) boot.esp32c3: SPI Speed      : 80MHz
I (40) boot.esp32c3: SPI Mode       : DIO
I (45) boot.esp32c3: SPI Flash Size : 4MB
I (50) boot: Enabling RNG early entropy source...
W (55) bootloader_random: RNG for ESP32-C3 not currently supported
I (62) boot: Partition Table:
I (65) boot: ## Label            Usage          Type ST Offset   Length
I (73) boot:  0 sec_cert         unknown          3f 00 0000d000 00003000
I (80) boot:  1 nvs              WiFi data        01 02 00010000 00006000
I (88) boot:  2 otadata          OTA data         01 00 00016000 00002000
I (95) boot:  3 phy_init         RF data          01 01 00018000 00001000
I (103) boot:  4 ota_0            OTA app          00 10 00020000 00190000
I (110) boot:  5 ota_1            OTA app          00 11 001b0000 00190000
I (118) boot:  6 fctry            WiFi data        01 02 00340000 00006000
I (125) boot:  7 coredump         Unknown data     01 03 00350000 00010000
I (133) boot: End of partition table
I (137) esp_image: segment 0: paddr=0x00020020 vaddr=0x3c0c0020 size=0x29948 (170312) map
I (174) esp_image: segment 1: paddr=0x00049970 vaddr=0x3fc8e200 size=0x03500 ( 13568) load
I (177) esp_image: segment 2: paddr=0x0004ce78 vaddr=0x40380000 size=0x031a0 ( 12704) load
=> 0x40380000: _vector_table at ??:?
I (183) esp_image: segment 3: paddr=0x00050020 vaddr=0x42000020 size=0xb39fc (735740) map
=> 0x42000020: <alloc::vec::Vec<T,A> as core::fmt::Debug>::fmt at /home/cdata/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:2771
I (312) esp_image: segment 4: paddr=0x00103a24 vaddr=0x403831a0 size=0x0afbc ( 44988) load
=> 0x403831a0: ram_temp_to_power at ??:?
I (321) esp_image: segment 5: paddr=0x0010e9e8 vaddr=0x50000000 size=0x00010 (    16) load
I (326) boot: Loaded app from partition at offset 0x20000
I (326) boot: Disabling RNG early entropy source...
W (330) bootloader_random: RNG for ESP32-C3 not currently supported
I (348) cpu_start: Pro cpu up.
I (361) cpu_start: Pro cpu start user code
I (361) cpu_start: cpu freq: 160000000
I (361) cpu_start: Application information:
I (363) cpu_start: Project name:     esp-idf
I (368) cpu_start: App version:      29b6481-dirty
I (374) cpu_start: Compile time:     Aug 26 2021 09:57:30
I (380) cpu_start: ELF file SHA256:  0000000000000000...
I (386) cpu_start: ESP-IDF:          4.3.0
I (391) heap_init: Initializing. RAM available for dynamic allocation:
I (398) heap_init: At 3FC96300 len 00029D00 (167 KiB): DRAM
I (404) heap_init: At 3FCC0000 len 0001F260 (124 KiB): STACK/DRAM
I (411) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM
I (418) spi_flash: detected chip: generic
I (422) spi_flash: flash io: dio
I (426) sleep: Configure to isolate all GPIO pins in sleep state
I (433) sleep: Enable automatic switching of GPIO sleep configuration
I (440) cpu_start: Starting scheduler.
Hello, world from Rust!
More complex print ["foo", "bar"]
Result: 0, 1
Rust main thread: Thread { id: ThreadId(1), name: Some("main"), .. }
This is thread number 0, Thread { id: ThreadId(2), name: None, .. }
This is thread number 1, Thread { id: ThreadId(3), name: None, .. }
This is thread number 2, Thread { id: ThreadId(4), name: None, .. }
This is thread number 3, Thread { id: ThreadId(5), name: None, .. }
This is thread number 4, Thread { id: ThreadId(6), name: None, .. }
About to join the threads. If ESP-IDF was patched successfully, joining will NOT crash
Joins were successful.
I (2556) pp: pp rom version: 8459080
I (2556) net80211: net80211 rom version: 8459080
I (2566) wifi:wifi driver task: 3fc9ff30, prio:23, stack:6656, core=0
I (2566) system_api: Base MAC address is not set
I (2566) system_api: read default base MAC address from EFUSE
I (2566) wifi:wifi firmware version: c7d0450
I (2576) wifi:wifi certification version: v7.0
I (2576) wifi:config NVS flash: disabled
I (2576) wifi:config nano formating: disabled
I (2586) wifi:Init data frame dynamic rx buffer num: 32
I (2586) wifi:Init management frame dynamic rx buffer num: 32
I (2596) wifi:Init management short buffer num: 32
I (2596) wifi:Init dynamic tx buffer num: 32
I (2606) wifi:Init static tx FG buffer num: 2
I (2606) wifi:Init static rx buffer size: 1600
I (2616) wifi:Init static rx buffer num: 10
I (2616) wifi:Init dynamic rx buffer num: 32
I (2616) wifi_init: rx ba win: 6
I (2626) wifi_init: tcpip mbox: 32
I (2626) wifi_init: udp mbox: 6
I (2636) wifi_init: tcp mbox: 6
I (2636) wifi_init: tcp tx win: 5744
I (2636) wifi_init: tcp rx win: 5744
I (2646) wifi_init: tcp mss: 1440
I (2646) wifi_init: WiFi IRAM OP enabled
I (2656) wifi_init: WiFi RX IRAM OP enabled
I (2656) esp_idf_svc::wifi: Driver initialized
I (2666) esp_idf_svc::wifi: Event handlers registered
I (2666) esp_idf_svc::wifi: Initialization complete
I (2676) rust_esp32_std_hello: Wifi created, about to scan
I (2676) esp_idf_svc::wifi: About to scan for access points
I (2686) esp_idf_svc::wifi: Stopping
I (2686) esp_idf_svc::wifi: Disconnect requested
I (2696) esp_idf_svc::wifi: Stop requested
I (2696) esp_idf_svc::wifi: About to wait for status
I (2706) esp_idf_svc::wifi: Providing status: Status(Stopped, Stopped)
I (2716) esp_idf_svc::wifi: Waiting for status done - success
I (2716) esp_idf_svc::wifi: Stopped
I (2726) esp_idf_svc::wifi: esp_wifi_set_mode
I (2726) esp_idf_svc::wifi: esp_wifi_start
I (2736) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08
Guru Meditation Error: Core  0 panic'ed (Illegal instruction). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x40001be4  RA      : 0x42091be8  SP      : 0x3fc9fd10  GP      : 0x3fc8ea00
=> 0x40001be4: ?? ??:0
=> 0x42091be8: phy_get_romfunc_addr at ??:?
TP      : 0x3fc765d8  T0      : 0x40057fa6  T1      : 0x0000000f  T2      : 0xffffffff
=> 0x40057fa6: ?? ??:0
S0/FP   : 0x3fc955b4  S1      : 0x3fc955b0  A0      : 0x3fc8f684  A1      : 0x40001a8c
=> 0x40001a8c: ?? ??:0
A2      : 0x3fc8f000  A3      : 0x400019f0  A4      : 0x40001964  A5      : 0x3fcdf4f8
=> 0x400019f0: ?? ??:0
=> 0x40001964: ?? ??:0
A6      : 0x42052c0c  A7      : 0x0000000a  S2      : 0x3fc955b0  S3      : 0x00000002
=> 0x42052c0c: uart_write at /home/cdata/.platformio/packages/framework-espidf/components/vfs/vfs_uart.c:201
S4      : 0x3fc92ee0  S5      : 0x3fce0000  S6      : 0x3fce0000  S7      : 0x3fce0000
S8      : 0x3ff1b000  S9      : 0x3fce0000  S10     : 0x3fcdf8d4  S11     : 0x00000000
T3      : 0x00000000  T4      : 0xffffffff  T5      : 0xffffffff  T6      : 0xffffffff
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000002  MTVAL   : 0x00000000
=> 0x40380001: _vector_table at ??:?
MHARTID : 0x00000000

Stack memory:
3fc9fd10: 0x3c0d21f0 0x3fca5284 0x3fca5284 0x420924ac 0x50500000 0x484c4c50 0x4448484c 0x4246464a
=> 0x420924ac: register_chipv7_phy at ??:?
=> 0x484c4c50: ?? ??:0
=> 0x4448484c: ?? ??:0
=> 0x4246464a: ?? ??:0
3fc9fd30: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd50: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd70: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fd90: 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc90eec 0x3fce0000 0x3fc92ee0 0x3fc93000
3fc9fdb0: 0x00000000 0x3fc92ee0 0x3fca5284 0x420285d0 0xffffffff 0x3fc92ee0 0x3fce0000 0x4202869e
=> 0x420285d0: esp_phy_load_cal_and_init at /home/cdata/.platformio/packages/framework-espidf/components/esp_wifi/src/phy_init.c:629
=> 0x4202869e: esp_phy_enable at /home/cdata/.platformio/packages/framework-espidf/components/esp_wifi/src/phy_init.c:237
3fc9fdd0: 0x00000000 0x3fc92ee0 0x3fc92ee0 0x4207443a 0x00000002 0x00000000 0x3fc92ee0 0x00000001
=> 0x4207443a: wifi_hw_start at ??:?
3fc9fdf0: 0x00000001 0x00000000 0x3fc92ee0 0x4207454e 0x3fca5214 0x00000000 0x00000000 0x3fc8e8e0
=> 0x4207454e: wifi_start_process at ??:?
3fc9fe10: 0x3fca5214 0x00000008 0x00000001 0x420716d0 0x00000000 0x3fcdf918 0x3fce0000 0x3ff1b594
=> 0x420716d0: ieee80211_ioctl_process at ??:?
3fc9fe30: 0x00000000 0x3fcdf918 0x3fce0000 0x4003fe8a 0x00000000 0x00000000 0x00000006 0x3fca5214
=> 0x4003fe8a: ?? ??:0
3fc9fe50: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fe70: 0x00000000 0x00000000 0x00000000 0x4038967a 0x00000000 0x00000000 0x00000000 0x00000000
=> 0x4038967a: prvTaskExitError at /home/cdata/.platformio/packages/framework-espidf/components/freertos/port/riscv/port.c:165
3fc9fe90: 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x27146414 0x00000000 0x00000000 0x01010107
3fc9feb0: 0x00000001 0x00000000 0xffffffff 0x7fefffff 0x00000000 0x3fc00000 0x00000000 0x40300000
=> 0x40300000: ?? ??:0
3fc9fed0: 0x00000000 0x3fe00000 0x00000000 0x3ff80000 0x636f4361 0x3fd287a7 0x8b60c8b3 0x3fc68a28
3fc9fef0: 0x509f79fb 0x3fd34413 0x00000000 0x3ff00000 0x00000000 0x40240000 0x00000000 0x401c0000
=> 0x40240000: ?? ??:0
=> 0x401c0000: ?? ??:0
3fc9ff10: 0x00000000 0x40140000 0x00000000 0x43500000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000154
=> 0x40140000: ?? ??:0
=> 0x43500000: ?? ??:0
3fc9ff30: 0x3fc9fd60 0x3fc96314 0x3fc91f24 0x3fc91f24 0x3fc9ff30 0x3fc91f1c 0x00000002 0x3fc9de68
3fc9ff50: 0x3fc9de68 0x3fc9ff30 0x00000000 0x00000017 0x3fc9e52c 0x69666977 0xdf3a5600 0xc88a81a4
3fc9ff70: 0x00292eae 0x00000000 0x3fc9ff20 0x00000017 0x00000001 0x00000000 0x00000000 0x00000000
3fc9ff90: 0x3fc96b2c 0x3fc96b94 0x3fc96bfc 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000
3fc9ffb0: 0x00000000 0x42099e78 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
=> 0x42099e78: _cleanup_r at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/findfp.c:229
3fc9ffd0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc9fff0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0010: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0030: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0050: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca0070: 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc90000 0x00000054 0x3fca0088 0x3fca0088
3fca0090: 0x3fca0088 0x3fca0088 0x00000000 0x3fca00a0 0xffffffff 0x3fca00a0 0x3fca00a0 0x00000000
3fca00b0: 0x3fca00b4 0xffffffff 0x3fca00b4 0x3fca00b4 0x00000000 0x00000001 0x00000000 0xf400ffff
3fca00d0: 0x00000000 0x6d5a835a 0x3fca0080 0x00000054 0x00000000 0x3fca00e0 0x00000000 0x00000000
3fca00f0: 0x00000000 0x3fca00f8 0xffffffff 0x3fca00f8 0x3fca00f8 0x00000000 0x3fca010c 0xffffffff



ELF file SHA256: 0000000000000000

cdata avatar Aug 26 '21 17:08 cdata

Oh, I just realized I'm still using my locally modified esp-idf-svc package (modified to add log lines and error handling). Let me fix that...

cdata avatar Aug 26 '21 17:08 cdata

We will see the same stacktrace. The thing is, it is not failing in our code. This seems to be a separate thread of ESP-IDF, on which the Wifi device is being initialized.

It fails in function register_chipv7_phy which I can't find in the ESP-IDF source, so it is either part of their Wifi binary blob, or in the ESP ROM.

Might be even a malfunctioning device to be honest. Have you been able to use Wifi on that board with C code? Also - very low chance - but do you power this board with a proper power supply?

ivmarkov avatar Aug 26 '21 17:08 ivmarkov

I'm powering the board over USB. It is very possible that it is malfunctioning - this is my first time trying to do anything with it.

Thank you for the time you spent investigating this with me. I will probably give it a rest for now until I can get another board to confirm if this one works.

cdata avatar Aug 26 '21 17:08 cdata

You can also try flashing some of the ESP-IDF C wifi examples. If they work fine, chances are we are somehow doing something wrong.

ivmarkov avatar Aug 26 '21 17:08 ivmarkov

I took a stab at running the scan wifi example in the esp-idf repo, and it seems to work. Here is the output:

I (32) boot: ESP-IDF v4.4-dev-2740-gf65c8249af 2nd stage bootloader
I (32) boot: compile time 10:58:17
I (32) boot: chip revision: 2
I (35) boot.esp32c3: SPI Speed      : 80MHz
I (40) boot.esp32c3: SPI Mode       : DIO
I (45) boot.esp32c3: SPI Flash Size : 2MB
I (50) boot: Enabling RNG early entropy source...
I (55) boot: Partition Table:
I (59) boot: ## Label            Usage          Type ST Offset   Length
I (66) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (73) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (81) boot:  2 factory          factory app      00 00 00010000 00100000
I (88) boot: End of partition table
I (93) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=133c0h ( 78784) map
I (113) esp_image: segment 1: paddr=000233e8 vaddr=3fc8da00 size=02b18h ( 11032) load
I (115) esp_image: segment 2: paddr=00025f08 vaddr=40380000 size=0a110h ( 41232) load
I (126) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=793c8h (496584) map
I (202) esp_image: segment 4: paddr=000a93f0 vaddr=4038a110 size=037f8h ( 14328) load
I (204) esp_image: segment 5: paddr=000acbf0 vaddr=50000000 size=00010h (    16) load
I (211) boot: Loaded app from partition at offset 0x10000
I (213) boot: Disabling RNG early entropy source...
I (230) cpu_start: Pro cpu up.
I (238) cpu_start: Pro cpu start user code
I (238) cpu_start: cpu freq: 160000000
I (238) cpu_start: Application information:
I (241) cpu_start: Project name:     scan
I (246) cpu_start: App version:      v4.4-dev-2740-gf65c8249af
I (252) cpu_start: Compile time:     Aug 26 2021 10:58:26
I (258) cpu_start: ELF file SHA256:  c338b0a436f07751...
I (264) cpu_start: ESP-IDF:          v4.4-dev-2740-gf65c8249af
I (271) heap_init: Initializing. RAM available for dynamic allocation:
I (278) heap_init: At 3FC94460 len 0002BBA0 (174 KiB): DRAM
I (284) heap_init: At 3FCC0000 len 0001F260 (124 KiB): STACK/DRAM
I (291) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM
I (298) spi_flash: detected chip: generic
I (302) spi_flash: flash io: dio
W (306) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (319) sleep: Configure to isolate all GPIO pins in sleep state
I (326) sleep: Enable automatic switching of GPIO sleep configuration
I (333) cpu_start: Starting scheduler.
I (342) pp: pp rom version: 8459080
I (342) net80211: net80211 rom version: 8459080
I (352) wifi:wifi driver task: 3fc9cdb0, prio:23, stack:6656, core=0
I (352) system_api: Base MAC address is not set
I (362) system_api: read default base MAC address from EFUSE
I (362) wifi:wifi firmware version: 70f0192
I (372) wifi:wifi certification version: v7.0
I (372) wifi:config NVS flash: enabled
I (372) wifi:config nano formating: disabled
I (382) wifi:Init data frame dynamic rx buffer num: 32
I (382) wifi:Init management frame dynamic rx buffer num: 32
I (392) wifi:Init management short buffer num: 32
I (392) wifi:Init dynamic tx buffer num: 32
I (402) wifi:Init static tx FG buffer num: 2
I (402) wifi:Init static rx buffer size: 1600
I (402) wifi:Init static rx buffer num: 10
I (412) wifi:Init dynamic rx buffer num: 32
I (412) wifi_init: rx ba win: 6
I (422) wifi_init: tcpip mbox: 32
I (422) wifi_init: udp mbox: 6
I (422) wifi_init: tcp mbox: 6
I (432) wifi_init: tcp tx win: 5744
I (432) wifi_init: tcp rx win: 5744
I (442) wifi_init: tcp mss: 1440
I (442) wifi_init: WiFi IRAM OP enabled
I (442) wifi_init: WiFi RX IRAM OP enabled
I (452) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08
I (572) wifi:set rx active PTI: 0, rx ack PTI: 0, and default PTI: 0
I (572) wifi:mode : sta (7c:df:a1:43:40:14)
I (572) wifi:enable tsf
I (2672) scan: Total APs scanned = 9
I (2672) scan: SSID             Macaque Moving Crew
I (2672) scan: RSSI             -61
I (2672) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2672) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2682) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2682) scan: Channel          11

I (2692) scan: SSID             Macaque Moving Crew
I (2692) scan: RSSI             -62
I (2692) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2702) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2702) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2712) scan: Channel          11

I (2712) scan: SSID             Macaque Guest
I (2722) scan: RSSI             -62
I (2722) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2732) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2732) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2742) scan: Channel          11

I (2742) scan: SSID             Macaque Guest
I (2752) scan: RSSI             -63
I (2752) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2752) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2762) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2762) scan: Channel          11

I (2772) scan: SSID             Lighthouse Primus
I (2772) scan: RSSI             -75
I (2782) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2782) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_TKIP_CCMP
I (2792) scan: Group Cipher     WIFI_CIPHER_TYPE_TKIP
I (2792) scan: Channel          6

I (2802) scan: SSID             ORBI96
I (2802) scan: RSSI             -78
I (2802) scan: Authmode         WIFI_AUTH_WPA3_PSK
I (2812) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2812) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2822) scan: Channel          8

I (2822) scan: SSID             ORBI96-Guest
I (2832) scan: RSSI             -79
I (2832) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2842) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2842) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2852) scan: Channel          8

I (2852) scan: SSID             Lee-Family
I (2852) scan: RSSI             -88
I (2862) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2862) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2872) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2872) scan: Channel          1

I (2882) scan: SSID             SMA3007924700
I (2882) scan: RSSI             -90
I (2882) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2892) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2892) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2902) scan: Channel          6

I'll re-open this issue for now.

cdata avatar Aug 26 '21 18:08 cdata

Can you try to flash the same example, but from ESP-IDF release/4.3? You have flashed master essentially (release/4.4dev), which possibly has a newer Wifi firmware version.

ivmarkov avatar Aug 26 '21 18:08 ivmarkov

(If that's not clear, the wifi firmware is newer in the version you are flashing) If the C example still works with release/4.3, I'll provide a way to use the latest release/4.3. The 4.3 release prepackaged with PlatformIO is unfortunately always lagging behind with updates.

ivmarkov avatar Aug 26 '21 18:08 ivmarkov

Hello, sorry for the delay in replying. I just did what you suggested. After getting the scan example to build at the 4.3 release, I flashed it and it appears to work with this output:

ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x181c
load:0x403ce000,len:0x8d4
load:0x403d0000,len:0x293c
entry 0x403ce000
I (32) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (32) boot: compile time 22:25:45
I (32) boot: chip revision: 2
I (34) boot.esp32c3: SPI Speed      : 80MHz
I (39) boot.esp32c3: SPI Mode       : DIO
I (44) boot.esp32c3: SPI Flash Size : 2MB
I (48) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (80) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot: End of partition table
I (91) esp_image: segment 0: paddr=00010020 vaddr=3c090020 size=16d10h ( 93456) map
I (114) esp_image: segment 1: paddr=00026d38 vaddr=3fc8dc00 size=03428h ( 13352) load
I (117) esp_image: segment 2: paddr=0002a168 vaddr=40380000 size=05eb0h ( 24240) load
I (124) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=82914h (534804) map
I (212) esp_image: segment 4: paddr=000b293c vaddr=40385eb0 size=07c58h ( 31832) load
I (218) esp_image: segment 5: paddr=000ba59c vaddr=50000000 size=00010h (    16) load
I (223) boot: Loaded app from partition at offset 0x10000
I (224) boot: Disabling RNG early entropy source...
I (241) cpu_start: Pro cpu up.
I (253) cpu_start: Pro cpu start user code
I (253) cpu_start: cpu freq: 160000000
I (253) cpu_start: Application information:
I (256) cpu_start: Project name:     scan
I (261) cpu_start: App version:      v4.3-dirty
I (266) cpu_start: Compile time:     Aug 29 2021 22:25:55
I (272) cpu_start: ELF file SHA256:  f8b948e4a87efb16...
I (278) cpu_start: ESP-IDF:          v4.3-dirty
I (283) heap_init: Initializing. RAM available for dynamic allocation:
I (290) heap_init: At 3FC95BA0 len 0002A460 (169 KiB): DRAM
I (296) heap_init: At 3FCC0000 len 0001F260 (124 KiB): STACK/DRAM
I (303) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM
I (310) spi_flash: detected chip: generic
I (314) spi_flash: flash io: dio
W (318) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using t
he size in the binary image header.
I (332) sleep: Configure to isolate all GPIO pins in sleep state
I (338) sleep: Enable automatic switching of GPIO sleep configuration
I (345) cpu_start: Starting scheduler.
I (355) pp: pp rom version: 8459080
I (355) net80211: net80211 rom version: 8459080
I (365) wifi:wifi driver task: 3fc9ede4, prio:23, stack:6656, core=0
I (365) system_api: Base MAC address is not set
I (375) system_api: read default base MAC address from EFUSE
I (375) wifi:wifi firmware version: c7d0450
I (385) wifi:wifi certification version: v7.0
I (385) wifi:config NVS flash: enabled
I (385) wifi:config nano formating: disabled
I (395) wifi:Init data frame dynamic rx buffer num: 32
I (395) wifi:Init management frame dynamic rx buffer num: 32
I (405) wifi:Init management short buffer num: 32
I (405) wifi:Init dynamic tx buffer num: 32
I (415) wifi:Init static tx FG buffer num: 2
I (415) wifi:Init static rx buffer size: 1600
I (415) wifi:Init static rx buffer num: 10
I (425) wifi:Init dynamic rx buffer num: 32
I (425) wifi_init: rx ba win: 6
I (435) wifi_init: tcpip mbox: 32
I (435) wifi_init: udp mbox: 6
I (435) wifi_init: tcp mbox: 6
I (445) wifi_init: tcp tx win: 5744
I (445) wifi_init: tcp rx win: 5744
I (455) wifi_init: tcp mss: 1440
I (455) wifi_init: WiFi IRAM OP enabled
I (455) wifi_init: WiFi RX IRAM OP enabled
I (465) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08
I (585) wifi:set rx active PTI: 0, rx ack PTI: 0, and default PTI: 0
I (585) wifi:mode : sta (7c:df:a1:43:40:14)
I (585) wifi:enable tsf
I (2685) scan: Total APs scanned = 6
I (2685) scan: SSID             Macaque Moving Crew
I (2685) scan: RSSI             -40
I (2685) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2685) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2695) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2695) scan: Channel          11

I (2705) scan: SSID             Macaque Guest
I (2705) scan: RSSI             -40
I (2705) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2715) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2715) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2725) scan: Channel          11

I (2725) scan: SSID             Macaque Moving Crew
I (2735) scan: RSSI             -62
I (2735) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2745) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2745) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2755) scan: Channel          11

I (2755) scan: SSID             Macaque Guest
I (2765) scan: RSSI             -63
I (2765) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2765) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2775) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2775) scan: Channel          11

I (2785) scan: SSID             Lighthouse Primus
I (2785) scan: RSSI             -89
I (2795) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2795) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_TKIP_CCMP
I (2805) scan: Group Cipher     WIFI_CIPHER_TYPE_TKIP
I (2805) scan: Channel          6

I (2815) scan: SSID             ORBI96-Guest
I (2815) scan: RSSI             -91
I (2815) scan: Authmode         WIFI_AUTH_WPA2_PSK
I (2825) scan: Pairwise Cipher  WIFI_CIPHER_TYPE_CCMP
I (2825) scan: Group Cipher     WIFI_CIPHER_TYPE_CCMP
I (2835) scan: Channel          8

cdata avatar Aug 30 '21 05:08 cdata

Did you have any further info on this @cdata? I'm hitting the same issue on my C3 devkit.

rthomas avatar Jul 09 '22 13:07 rthomas

@ivmarkov this might not be a problem anymore after commit 8aac6d0dd41953f16c58c85f14ebb7720c719309 ish or what do you think?

Vollbrecht avatar Mar 29 '23 15:03 Vollbrecht

The issue seems to persist with ESP IDF v5.0 (setup via espup and esp-idf-template). I have fixed the toolchain to channel = "nightly-2023-03-09" With IDF v4.4.1 everything worked fine.

Details

I (5444) wifi:wifi firmware version: 57982fe
I (5444) wifi:wifi certification version: v7.0
I (5454) wifi:config NVS flash: enabled
I (5454) wifi:config nano formating: disabled
I (5454) wifi:Init data frame dynamic rx buffer num: 32
I (5464) wifi:Init management frame dynamic rx buffer num: 32
I (5464) wifi:Init management short buffer num: 32
I (5474) wifi:Init dynamic tx buffer num: 32
I (5474) wifi:Init static tx FG buffer num: 2
I (5484) wifi:Init static rx buffer size: 1600
I (5484) wifi:Init static rx buffer num: 10
I (5484) wifi:Init dynamic rx buffer num: 32
I (5494) wifi_init: rx ba win: 6
I (5494) wifi_init: tcpip mbox: 32
I (5504) wifi_init: udp mbox: 6
I (5504) wifi_init: tcp mbox: 6
I (5504) wifi_init: tcp tx win: 5744
I (5514) wifi_init: tcp rx win: 5744
I (5514) wifi_init: tcp mss: 1440
I (5524) wifi_init: WiFi IRAM OP enabled
I (5524) wifi_init: WiFi RX IRAM OP enabled
I (5524) esp_idf_svc::wifi: Driver initialized
I (5534) esp_idf_svc::wifi: Stop requested
I (5534) esp_idf_svc::wifi: Stopping
I (5544) mvg_monitor::wifi: Searching for Wifi network 
I (5554) esp_idf_svc::wifi: About to scan for access points
I (5554) esp_idf_svc::wifi: Stop requested
I (5564) esp_idf_svc::wifi: Stopping
I (5564) esp_idf_svc::wifi: Disconnect requested
I (5574) esp_idf_svc::wifi: Stop requested
I (5574) esp_idf_svc::wifi: Stopping
I (5584) wifi:Deinit lldesc rx mblock:10
I (5594) esp_idf_svc::wifi: Driver deinitialized
I (5594) esp_idf_svc::wifi: Dropped
I (5594) esp_idf_svc::nvs: Dropped
I (5594) esp_idf_svc::eventloop: Dropped

JuliDi avatar Apr 27 '23 08:04 JuliDi

The issue seems to persist with ESP IDF v5.0 (setup via espup and esp-idf-template). I have fixed the toolchain to channel = "nightly-2023-03-09" With IDF v4.4.1 everything worked fine. Details

your output doesn't imply you run the std-demo. could you clarify what you are actually doing? i don't see any loop here in your code just dropping out of context. you are scanning for any wifi AP's?

Vollbrecht avatar Apr 27 '23 11:04 Vollbrecht

No, there is no loop. Just scanning for an AP and suddenly it crashes. Iirc I pretty much copy&pasted the code from the example, though.

pub fn wifi(
    ssid: &str,
    psk: &str,
    modem: impl peripheral::Peripheral<P = esp_idf_hal::modem::Modem> + 'static,
    sysloop: EspSystemEventLoop,
) -> anyhow::Result<Box<EspWifi<'static>>> {
    
    if ssid.is_empty() {
        anyhow::bail!("missing WiFi name")
    }
    if psk.is_empty() {
        info!("Wifi password is empty");
    }

    let mut wifi = Box::new(EspWifi::new(
        modem,
        sysloop.clone(),
        Some(EspDefaultNvsPartition::take()?),
    )?);

    info!("Searching for Wifi network {}", ssid);

    let ap_infos = wifi.scan()?;

    let ours = ap_infos.into_iter().find(|a| a.ssid == ssid);

    let channel = if let Some(ours) = ours {
        info!(
            "Found configured access point {} on channel {}",
            ssid, ours.channel
        );
        Some(ours.channel)
    } else {
        info!(
            "Configured access point {} not found during scanning, will go with unknown channel",
            ssid
        );
        None
    };

    info!("setting Wifi configuration");
    wifi.set_configuration(&wifi::Configuration::Client(ClientConfiguration {
        ssid: ssid.into(),
        password: psk.into(),
        channel,
        ..Default::default()
    }))?;

    wifi.start()?;
    info!("Starting wifi...");

    if !WifiWait::new(&sysloop)?
        .wait_with_timeout(Duration::from_secs(20), || wifi.is_started().unwrap())
    {
        bail!("Wifi did not start");
    }

    info!("Connecting wifi...");
    wifi.connect()?;

    while !EspNetifWait::new::<EspNetif>(wifi.sta_netif(), &sysloop)?.wait_with_timeout(
        Duration::from_secs(7),
        || {
            wifi.is_connected().unwrap()
                && wifi.sta_netif().get_ip_info().unwrap().ip != Ipv4Addr::new(0, 0, 0, 0)
        },
    ) {
        wifi.connect()?;
    }

    let ip_info = wifi.sta_netif().get_ip_info()?;

    info!("Wifi DHCP info: {:?}", ip_info);

    Ok(wifi)
}

JuliDi avatar Apr 27 '23 13:04 JuliDi

@JuliDi your code is not working because you get an Error: ESP_ERR_WIFI_NOT_STARTED . and as the name suggest -> you should use wifi.start() before the first wifi.scan() than it is working, at least it does for me tested on my esp32c3 hardware. So it has nothing todo with the initial issue, can you confirm that?

so move the following code block between the wifi creation and the wifi.scan()

    wifi.start()?;
    info!("Starting wifi...");

    if !WifiWait::new(&sysloop)?
        .wait_with_timeout(Duration::from_secs(20), || wifi.is_started().unwrap())
    {
        bail!("Wifi did not start");
    }

Vollbrecht avatar Apr 27 '23 20:04 Vollbrecht

keep in mind: if you are using wokwi to simulate this, this also don't work, but works on real hardware!

Vollbrecht avatar Apr 27 '23 20:04 Vollbrecht

I will try with your fix tomorrow. However, I don't get why it was working with the previous version of IDF and now it doesn't.

JuliDi avatar Apr 27 '23 21:04 JuliDi