@@ -90,18 +90,130 @@ ESP32 QEMU emulation is not perfect and has several known limitations:
9090
9191## Analyzing Crashes
9292
93- ### Check Exception Type
94- Common ESP32 exceptions:
95- - ` LoadProhibited ` : Reading from invalid memory address
96- - ` StoreProhibited ` : Writing to invalid memory address
97- - ` IllegalInstruction ` : Executing invalid code
93+ ### Common Exception Types
94+ ESP32 exceptions with EXCCAUSE codes:
95+ - ` 0x00000000 ` (IllegalInstruction): Executing invalid code
96+ - ` 0x00000001 ` (Syscall): Syscall instruction
97+ - ` 0x00000002 ` (InstructionFetchError): Cannot fetch instruction
98+ - ` 0x00000003 ` (LoadStoreError): Load/store alignment error
99+ - ` 0x00000005 ` (LoadStoreAlignmentCause): Load/store alignment error
100+ - ` 0x00000006 ` (InstructionDataError): Data error during instruction fetch
101+ - ` 0x00000007 ` (LoadStoreDataError): Data error during load/store
102+ - ` 0x00000009 ` (LoadStorePrivilegeViolation): Privilege violation
103+ - ` 0x0000000f ` (LoadStorePIFAddrError): Invalid PIF address (common in QEMU)
104+ - ` 0x0000001c ` (InstructionAddrError): Address error during instruction fetch
105+ - ` 0x0000001d ` (LoadStoreAddrError): Address error during load/store
106+ - ` 0x0000001e ` (InstructionBusError): Bus error during instruction fetch
107+ - ` 0x0000001f ` (LoadStoreBusError): Bus error during load/store
108+
109+ ### LoadStorePIFAddrError (0x0000000f)
110+ This is ** very common in QEMU** and usually indicates:
111+ - Accessing hardware registers not emulated by QEMU
112+ - Accessing invalid memory-mapped peripheral addresses
113+ - Often occurs during peripheral initialization (I2C, SPI, ADC, etc.)
114+ - ** May work fine on real hardware** - QEMU limitation
115+
116+ ### Decoding Crash Backtraces
117+
118+ When you see a crash like:
119+ ```
120+ Guru Meditation Error: Core 1 panic'ed (LoadStorePIFAddrError)
121+ Backtrace: 0x401771aa:0x3ffb2090 0x4015b4c5:0x3ffb20c0 ...
122+ ```
123+
124+ #### Method 1: Using PlatformIO Exception Decoder
125+ ``` bash
126+ # In the WLED-MM directory
127+ pio device monitor --filter esp32_exception_decoder
128+
129+ # Then paste the exception output (registers + backtrace)
130+ # The decoder will show function names and file locations
131+ ```
132+
133+ #### Method 2: Using ESP-IDF addr2line
134+ ``` bash
135+ # Install toolchain (if not already from PlatformIO)
136+ ~ /.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line \
137+ -pfiaC -e .pio/build/esp32_16MB_V4_M_eth_debug/firmware.elf \
138+ 0x401771aa 0x4015b4c5 0x40134813 0x40103cd0 0x40135d33 0x401383c6 0x4016107e
139+ ```
140+
141+ Replace the addresses with those from your backtrace.
142+
143+ #### Method 3: Online Decoder
144+ 1 . Get firmware.elf from build artifacts
145+ 2 . Use https://github.com/me-no-dev/EspExceptionDecoder
146+ 3 . Paste exception info and upload firmware.elf
147+ 4 . Get decoded stack trace
148+
149+ ### Example Decoded Output
150+ ```
151+ 0x401771aa: emac_hal_init at components/hal/esp32/emac_hal.c:45
152+ 0x4015b4c5: esp_eth_mac_esp32_init at components/esp_eth/src/esp_eth_mac_esp32.c:123
153+ 0x40134813: NetworkClass::begin at wled00/network.cpp:234
154+ ```
155+
156+ This shows the crash occurred in ethernet MAC initialization - likely a QEMU emulation limitation.
157+
158+ ### Analyzing the Crash Location
159+
160+ 1 . ** Check the function names** : Are they in hardware/peripheral code?
161+ - ` emac_ ` , ` i2c_ ` , ` spi_ ` , ` adc_ ` , etc. → Likely QEMU limitation
162+ - Application functions → Likely real bug
163+
164+ 2 . ** Check EXCVADDR** : The address being accessed
165+ - ` 0x3ff69xxx ` range → Peripheral registers (QEMU issue)
166+ - ` 0x00000000 ` or very low → Null pointer (real bug)
167+ - Stack addresses → Possible stack overflow
168+
169+ 3 . ** Check PC (Program Counter)** : Where code was executing
170+ - ROM addresses (` 0x4000xxxx ` ) → ESP32 ROM functions
171+ - Flash addresses (` 0x400dxxxx - 0x4017xxxx ` ) → Your firmware
172+ - RAM addresses (` 0x4008xxxx ` ) → RAM-loaded code
173+
174+ ### Common QEMU-Specific Crashes
175+
176+ #### Ethernet MAC Initialization
177+ ```
178+ Backtrace: ... esp_eth_mac_esp32_init ... emac_hal_init ...
179+ ```
180+ ** Cause** : QEMU's ethernet emulation may not fully support all MAC features
181+ ** Action** : Check if ethernet link comes up; web server may still work
182+
183+ #### I2C/SPI Peripheral Access
184+ ```
185+ Backtrace: ... i2c_master_cmd_begin ...
186+ ```
187+ ** Cause** : I2C peripherals not emulated
188+ ** Action** : Expected in QEMU; disable or mock peripheral access
189+
190+ #### WiFi Functions
191+ ```
192+ Backtrace: ... esp_wifi_init ... wifi_hw_init ...
193+ ```
194+ ** Cause** : WiFi not emulated
195+ ** Action** : Use ethernet build (already configured)
98196
99197### Expected Behavior in QEMU
100198For WLED testing in QEMU, we expect:
101199- ✅ Web server to start successfully
102200- ✅ HTTP requests to be handled
103201- ✅ Web UI pages to load
104- - ⚠️ WiFi operations to fail/be limited
202+ - ✅ Basic ethernet connectivity
203+ - ⚠️ WiFi operations to fail/be disabled
105204- ⚠️ Some LED control features may not work fully
205+ - ⚠️ Peripheral access (I2C, SPI) may crash
206+ - ⚠️ Some hardware features cause QEMU-specific crashes
106207
107- See full QEMU logs in GitHub Actions artifacts.
208+ ### Investigating Crashes
209+
210+ 1 . ** Download QEMU logs** from GitHub Actions artifacts
211+ 2 . ** Find the exception** in qemu-output.log
212+ 3 . ** Copy the backtrace addresses**
213+ 4 . ** Decode using one of the methods above**
214+ 5 . ** Analyze the decoded output** :
215+ - Hardware access? → Probably QEMU limitation
216+ - Application logic? → Likely real bug to fix
217+ - Initialization code? → May need QEMU workaround
218+
219+ See full QEMU logs in GitHub Actions artifacts (` qemu-logs ` ).
0 commit comments