ESP32 / ESP_WIFI: Problems when enabling COEX
Originally mentioned on Matrix: https://matrix.to/#/!LdaNPfUfvefOLewEIM:matrix.org/$DfubpOedHA5h2wMi2ibpJJ2vNP4WVTELx6X39o-v9Ag?via=matrix.org&via=tchncs.de&via=envs.net
Repro: https://github.com/UnwhiteCat/gpio-test
I can also repro the linker issue (using the v0.22.0 tag - not tried other commits) Using xtensa toolchain 1.82
Add esp-wifi/ble esp-wifi/coex to the wifi_embassy_dhcp example to see this
error: linking with `xtensa-esp32-elf-gcc` failed: exit code: 1
|
= note: "xtensa-esp32-elf-gcc" "C:\\Users\\bq\\AppData\\Local\\Temp\\rustcqmgQSO\\symbols.o" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\deps\\wifi_embassy_dhcp-6df7971b26c33278.wifi_embassy_dhcp.a78f6ecf3e51b938-cgu.0.rcgu.o" "-Wl,--as-needed" "-Wl,-Bstatic" "D:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\deps\\libcompiler_builtins-ab5ce8eb9d03878f.rlib" "-Wl,-Bdynamic" "-lbtdm_app" "-lcoexist" "-lcore" "-lespnow" "-lmesh" "-lnet80211" "-lphy" "-lpp" "-lrtc" "-lsmartconfig" "-lwapi" "-lwpa_supplicant" "-lprintf" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\build\\esp-hal-1794b49980ec6285\\out" "-L" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\build\\esp32-0d44288eee102100\\out" "-L" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\build\\xtensa-lx-decd7544df459813\\out" "-L" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\build\\xtensa-lx-rt-2a1a7ef21be3e2a6\\out" "-L" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\build\\esp-wifi-sys-8d996cb03f06c4e3\\out" "-o" "d:\\projects\\upstream\\esp-hal\\examples\\target\\xtensa-esp32-none-elf\\release\\deps\\wifi_embassy_dhcp-6df7971b26c33278" "-Wl,--gc-sections" "-no-pie" "-Wl,-O1" "-nodefaultlibs" "-Wl,-Tlinkall.x" "-nostartfiles"
= note: C:/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: d:\projects\upstream\esp-hal\examples\target\xtensa-esp32-none-elf\release\build\esp-wifi-sys-8d996cb03f06c4e3\out\libcoexist.a(coexist_hw.o):(.iram1.17+0x0): undefined reference to `btdm_rf_bb_reg_init'␍
C:/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: d:\projects\upstream\esp-hal\examples\target\xtensa-esp32-none-elf\release\build\esp-wifi-sys-8d996cb03f06c4e3\out\libcoexist.a(coexist_hw.o):(.iram1.17+0x1a): undefined reference to `btdm_rf_bb_reg_init'␍
collect2.exe: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
Can get rid of the linker error with lto = false (but not with lto = true)
That creates an unbootable application.
Doing that with the original repro makes it build but fail like this
Exception occurred 'InstrProhibited'
Context
PC=0x00000001 PS=0x00060530
A0=0x800eea52 A1=0x3ffdb1c0 A2=0x3ffdafac A3=0x3ffdb088 A4=0x3ffdb090
0x3ffdb1c0 - g_wifi_mac_time_delta
at ??:??
0x3ffdb088 - coex_bb_rst_mux
at ??:??
0x3ffdb090 - coex_env
at ??:??
A5=0x3ffdb088 A6=0x3ffc40c0 A7=0x3ffc2150 A8=0x800eeb55 A9=0x3ffc4198
0x3ffdb088 - coex_bb_rst_mux
at ??:??
0x3ffc40c0 - async_main::____embassy_main_task::{{closure}}::HEAP
at ??:??
0x3ffc2150 - async_main::____embassy_main_task::{{closure}}::HEAP
at ??:??
0x3ffc4198 - async_main::____embassy_main_task::{{closure}}::HEAP
at ??:??
A10=0x00000001 A11=0x00000000 A12=0x00000000 A13=0x3ffc3fb0 A14=0x00060003
0x3ffc3fb0 - async_main::____embassy_main_task::{{closure}}::HEAP
at ??:??
A15=0x00000001
SAR=0000000f
EXCCAUSE=0x00000014 EXCVADDR=0x00000000
LBEG=0x4000c2e0 LEND=0x4000c2f6 LCOUNT=0x00000000
THREADPTR=0x00000000
SCOMPARE1=0x00000100
BR=0x00000000
ACCLO=0x00000000 ACCHI=0x00000000
M0=0x00000000 M1=0x00000000 M2=0x00000000 M3=0x00000000
F64R_LO=0x00000000 F64R_HI=0x00000000 F64S=0x00000000
FCR=0x00000000 FSR=0x00000000
F0=0x00000000 F1=0x00000000 F2=0x00000000 F3=0x00000000 F4=0x00000000
F5=0x00000000 F6=0x00000000 F7=0x00000000 F8=0x00000000 F9=0x00000000
F10=0x00000000 F11=0x00000000 F12=0x00000000 F13=0x00000000 F14=0x00000000
F15=0x00000000
0x400dc84c
esp_wifi::wifi::coex_initialize
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\esp-wifi-0.11.0\src\wifi\mod.rs:1226
0x400d298f
esp_wifi::init
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\esp-wifi-0.11.0\src\lib.rs:393
0x4013a4c9
embassy_executor::raw::run_queue::RunQueue::dequeue_all
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\embassy-executor-0.6.3\src\raw\run_queue_atomics.rs:78
0x400d26c0
esp_hal_embassy::executor::thread::Executor::run
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\esp-hal-embassy-0.5.0\src\executor\thread.rs:112
0x400d6d92
main
at ??:??
0x400e276b
Reset
at ??:??
0x400e1ca8
esp_hal::soc::<impl esp_hal::soc::implementation::efuse::Efuse>::mac_address
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\esp-hal-0.22.0\src\soc\mod.rs:90
The crash is when initializing coex
(Obviously not using features coex and ble there makes it work).
Pasting the code of wifi_embassy_dhcp instead of the main.rs gives a slightly different output:
Exception occurred 'LoadProhibited'
Context
PC=0x40080c65 PS=0x00060b30
0x40080c65 - core::sync::atomic::atomic_load
at C:\Users\bq\.rustup\toolchains\esp\lib\rustlib\src\rust\library\core\src\sync\atomic.rs:3310
A0=0x800fbc30 A1=0x3ffdad70 A2=0x3ffc2180 A3=0xffffffff A4=0x400e27b8
0x3ffdad70 - g_cnxMgr
at ??:??
0x3ffc2180 - async_main::____embassy_main_task::{{closure}}::HEAP
at ??:??
0x400e27b8 - _critical_section_1_0_acquire
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\critical-section-1.2.0\src\lib.rs:300
A5=0x00000000 A6=0x00000001 A7=0x0000831c A8=0x00000000 A9=0x3ffdad50
0x3ffdad50 - g_cnxMgr
at ??:??
A10=0x00060b20 A11=0x00000000 A12=0x00002710 A13=0x000000ff A14=0x400e27b8
0x400e27b8 - _critical_section_1_0_acquire
at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\critical-section-1.2.0\src\lib.rs:300
A15=0x00000001
SAR=00000004
EXCCAUSE=0x0000001c EXCVADDR=0x00000000
LBEG=0x4000c2e0 LEND=0x4000c2f6 LCOUNT=0x00000000
THREADPTR=0x00000000
SCOMPARE1=0x00000100
BR=0x00000000
ACCLO=0x00000000 ACCHI=0x00000000
M0=0x00000000 M1=0x00000000 M2=0x00000000 M3=0x00000000
F64R_LO=0x00000000 F64R_HI=0x00000000 F64S=0x00000000
FCR=0x00000000 FSR=0x00000000
F0=0x00000000 F1=0x00000000 F2=0x00000000 F3=0x00000000 F4=0x00000000
F5=0x00000000 F6=0x00000000 F7=0x00000000 F8=0x00000000 F9=0x00000000
F10=0x00000000 F11=0x00000000 F12=0x00000000 F13=0x00000000 F14=0x00000000
F15=0x00000000
Would be good to try this again soon.
While LTO (with rustc 1.90) still wants to strip btdm_rf_bb_reg_init, embassy_dhcp works fine with ble+coex enabled. Interestingly the coex example doesn't have the same issue.