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

M5Stack Core2 panics on startup #1227

Closed
meganetaaan opened this issue Oct 3, 2023 · 6 comments
Closed

M5Stack Core2 panics on startup #1227

meganetaaan opened this issue Oct 3, 2023 · 6 comments
Labels
fixed - please verify Issue has been fixed. Please verify and close.

Comments

@meganetaaan
Copy link
Contributor

Build environment: Linux(22.04)
Moddable SDK version: v4.2.0
Target device: M5Stack Core2

Description

M5Stack Core2 panics on startup.
According to the instrument log, it seems to be a kind of deprecation error for i2s driver.

W (613) ADC: legacy driver is deprecated, please migrate to `esp_adc/adc_oneshot.h`
E (620) i2s(legacy): CONFLICT! The new i2s driver can't work along with the legacy i2s driver

abort() was called at PC 0x400fca4c on core 0
0x400fca4c: check_i2s_driver_conflict at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/driver/deprecated/i2s_legacy.c:1939 (discriminator 3)

Steps to Reproduce

  1. cd $MODDABLE/examples/helloworld
  2. mcconfig -m -i -p esp32/m5stack_core2
  3. See error

Other information

Full Instrumentation log
Executing action: monitor
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP32
Running idf_monitor in directory /home/sskw/.local/share/moddable/build/tmp/esp32/m5stack_core2/instrument/helloworld/xsProj-esp32
Executing "/home/sskw/.espressif/python_env/idf5.1_py3.10_env/bin/python /home/sskw/.local/share/esp32/esp-idf-v5.1.1/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32-elf- --decode-coredumps info --target esp32 --revision 300 /home/sskw/.local/share/moddable/build/tmp/esp32/m5stack_core2/instrument/helloworld/xsProj-esp32/build/xs_esp32.elf -m '/home/sskw/.espressif/python_env/idf5.1_py3.10_env/bin/python' '/home/sskw/.local/share/esp32/esp-idf-v5.1.1/tools/idf.py' '-n'"...
--- esp-idf-monitor 1.3.0 on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
I (13) cpu_start: Multicore app
I (13) quad_psram: This chip is ESP32-D0WD
I (13) esp_psram: Found 8MB PSRAM device
I (13) esp_psram: Speed: 80MHz
I (15) esp_psram: PSRAM initialized, cache is in low/high (2-core) mode.
W (21) esp_psram: Virtual address not enough for PSRAM, map as much as we can. 4MB is mapped
I (29) cpu_start: Pro cpu up.
I (32) cpu_start: Starting app cpu, entry point is 0x40080eec
0x40080eec: call_start_cpu1 at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/port/cpu_start.c:154

I (0) cpu_start: App cpu up.
I (525) esp_psram: SPI SRAM memory test OK
I (533) cpu_start: Pro cpu start user code
I (533) cpu_start: cpu freq: 240000000 Hz
I (533) cpu_start: Application information:
I (533) cpu_start: Project name:     xs_esp32
I (537) cpu_start: App version:      4.2.0-dirty
I (542) cpu_start: Compile time:     Oct  3 2023 12:27:08
I (547) cpu_start: ELF file SHA256:  9cfbe59df6d7b9ca...
I (552) cpu_start: ESP-IDF:          v5.1.1
I (556) cpu_start: Min chip rev:     v3.0
I (559) cpu_start: Max chip rev:     v3.99 
I (563) cpu_start: Chip rev:         v3.0
I (567) heap_init: Initializing. RAM available for dynamic allocation:
I (573) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (578) heap_init: At 3FFB4AC0 len 0002B540 (173 KiB): DRAM
I (584) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (589) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (595) heap_init: At 4008E644 len 000119BC (70 KiB): IRAM
I (600) esp_psram: Adding pool of 4096K of PSRAM memory to heap allocator
I (607) spi_flash: detected chip: generic
I (610) spi_flash: flash io: qio
W (613) ADC: legacy driver is deprecated, please migrate to `esp_adc/adc_oneshot.h`
E (620) i2s(legacy): CONFLICT! The new i2s driver can't work along with the legacy i2s driver

abort() was called at PC 0x400fca4c on core 0
0x400fca4c: check_i2s_driver_conflict at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/driver/deprecated/i2s_legacy.c:1939 (discriminator 3)



Backtrace: 0x400815f6:0x3ffe3b40 0x40088191:0x3ffe3b60 0x4008d38a:0x3ffe3b80 0x400fca4c:0x3ffe3bf0 0x400d223a:0x3ffe3c10 0x400812a1:0x3ffe3c50 0x40079462:0x3ffe3c90 |<-CORRUPTED
0x400815f6: panic_abort at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/panic.c:452

0x40088191: esp_system_abort at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/port/esp_system_chip.c:84

0x4008d38a: abort at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/newlib/abort.c:38

0x400fca4c: check_i2s_driver_conflict at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/driver/deprecated/i2s_legacy.c:1939 (discriminator 3)

0x400d223a: do_global_ctors at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/startup.c:200
 (inlined by) start_cpu0_default at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/startup.c:463

0x400812a1: call_start_cpu0 at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/port/cpu_start.c:689





ELF file SHA256: 9cfbe59df6d7b9ca

Initiating core dump!
I (653) esp_core_dump_uart: Press Enter to print core dump to UART...
I (659) esp_core_dump_uart: Print core dump to uart...
Core dump started (further output muted)
Received   3 kB...
Core dump finished!
===============================================================
==================== ESP32 CORE DUMP START ====================

Crashed task handle: 0x3ffaf424, name: 'ipc0', GDB name: 'process 1073411108'

================== CURRENT THREAD REGISTERS ===================
exccause       0xffff (InvalidCauseRegister)
excvaddr       0x0
pc             0x20000000          0x20000000
lbeg           0x0                 0
lend           0x0                 0
lcount         0x0                 0
sar            0x0                 0
ps             0x30                48
threadptr      <unavailable>
br             <unavailable>
scompare1      <unavailable>
acclo          <unavailable>
acchi          <unavailable>
m0             <unavailable>
m1             <unavailable>
m2             <unavailable>
m3             <unavailable>
expstate       <unavailable>
f64r_lo        <unavailable>
f64r_hi        <unavailable>
f64s           <unavailable>
fcr            <unavailable>
fsr            <unavailable>
a0             0x20000070          536871024
a1             0x0                 0
a2             0x0                 0
a3             0x0                 0
a4             0x0                 0
a5             0x0                 0
a6             0x40085dec          1074290156
a7             0x1                 1
a8             0x0                 0
a9             0x0                 0
a10            0x0                 0
a11            0x0                 0
a12            0x0                 0
a13            0x0                 0
a14            0x0                 0
a15            0x0                 0

==================== CURRENT THREAD STACK =====================
#0  0x20000000 in ?? ()

======================== THREADS INFO =========================
  Id   Target Id          Frame 
* 1    process 1073411108 0x20000000 in ?? ()
  2    process 1073412488 vPortTaskWrapper (pxCode=0x0, pvParameters=0x0) at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:161

==================== THREAD 1 (TCB: 0x3ffaf424, name: 'ipc0') =====================
#0  0x20000000 in ?? ()

==================== THREAD 2 (TCB: 0x3ffaf988, name: 'ipc1') =====================
#0  vPortTaskWrapper (pxCode=0x0, pvParameters=0x0) at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:161
#1  0x40000000 in ?? ()


======================= ALL MEMORY REGIONS ========================
Name   Address   Size   Attrs
.rtc.text 0x400c0000 0x0 RW  
.rtc.dummy 0x3ff80000 0x0 RW  
.rtc.force_fast 0x3ff80000 0x0 RW  
.rtc_noinit 0x50000000 0x0 RW  
.rtc.force_slow 0x50000000 0x0 RW  
.iram0.vectors 0x40080000 0x403 R XA
.iram0.text 0x40080404 0xe23f RWXA
.dram0.data 0x3ffb0000 0x2e38 RW A
.ext_ram_noinit 0x3f800000 0x0 RW  
.ext_ram.bss 0x3f800000 0x0 RW  
.flash.appdesc 0x3f400020 0x100 R  A
.flash.rodata 0x3f400120 0x23424 RW A
.flash.rodata_noload 0x3f423544 0x0 RW  
.flash.text 0x400d0020 0x4a10f R XA
.iram0.data 0x4008e644 0x0 RW  
.iram0.bss 0x4008e644 0x0 RW  
.dram0.heap_start 0x3ffb4ac0 0x0 RW  
.coredump.tasks.data 0x3ffaf424 0x15c RW 
.coredump.tasks.data 0x20000000 0x70 RW 
.coredump.tasks.data 0x3ffaf988 0x15c RW 
.coredump.tasks.data 0x3ffaf860 0x120 RW 

===================== ESP32 CORE DUMP END =====================
===============================================================
Done!
Coredump checksum='1515e0cd'
I (1021) esp_core_dump_uart: Core dump has been written to uart.
Entering gdb stub now.
$T0b#e6GNU gdb (esp-gdb) 12.1_20221002
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=xtensa-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/sskw/.local/share/moddable/build/tmp/esp32/m5stack_core2/instrument/helloworld/xsProj-esp32/build/xs_esp32.elf...
Remote debugging using /dev/ttyUSB0
warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread
0x400815f9 in panic_abort (details=0x3ffe3b80 "abort() was called at PC 0x400fca4c on core 0") at /home/sskw/.local/share/esp32/esp-idf-v5.1.1/components/esp_system/panic.c:452
452	    *((volatile int *) 0) = 0; // NOLINT(clang-analyzer-core.NullDereference) should be an invalid operation on targets
(gdb) 
@mkellner
Copy link
Collaborator

mkellner commented Oct 3, 2023

Could you please remove build output and try again with a verbose build?

rm -rf $MODDABLE/build/bin/esp32 $MODDABLE/build/tmp/esp32
VERBOSE=1 mcconfig -d -m -p esp32/m5stack_core2 > $MODDABLE/build/tmp/debug.output 2>&1

Then send $MODDABLE/build/tmp/debug.output to me?

Thank you. Are you able to build for other targets?

@phoddie
Copy link
Collaborator

phoddie commented Oct 3, 2023

I think the key thing is here: check_i2s_driver_conflict.

@meganetaaan
Copy link
Contributor Author

Could you please remove build output and try again with a verbose build?

rm -rf $MODDABLE/build/bin/esp32 $MODDABLE/build/tmp/esp32
VERBOSE=1 mcconfig -d -m -p esp32/m5stack_core2 > $MODDABLE/build/tmp/debug.output 2>&1

Then send $MODDABLE/build/tmp/debug.output to me?

Here it is. I put instrumental build version (debug_instrument.output) aside just in case.
debug.zip

Are you able to build for other targets?

esp32/m5stack and esp32/m5stack_fire build and run. AudioOut can play sound.

esp32/m5stack_cores3 builds and runs but no sound plays. I will take a look if it's related to this issue.

@meganetaaan
Copy link
Contributor Author

I've delved into the implementation of audioout.c. As the error message suggests, I checked for any remaining legacy APIs for I2S. It appears that the i2s_write_expand function does not exist in esp-idf v5, which seems to be leading to a runtime error.

https://github.com/Moddable-OpenSource/moddable/blame/public/modules/pins/i2s/audioout.c#L1602

To verify this, I modified esp32/m5stack_core2/manifest.json and changed MODDEF_AUDIOOUT_I2S_BITSPERSAMPLE to 16 to bypass the use of i2s_write_expand. Doing so eliminates the relevant error, and audio playback proceeds as expected.

@phoddie
Copy link
Collaborator

phoddie commented Oct 3, 2023

It looks like the M5Stack Core2 is the only public device that uses 32-bit output. That's why the use of the deprecated i2s_write_expand API was missed. The expansion has been added to the new channel API as part of initialization. Unfortunately, I don't have an M5Stack Core2 to try. Would you test the following changes in audioOut.c?

In audioOutLoop() set the 32-bit case to expand from 16-bit source to 32-bit out:

#if MODDEF_AUDIOOUT_I2S_BITSPERSAMPLE == 32
	i2s_config.slot_cfg.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT;
	i2s_config.slot_cfg.ws_width = I2S_DATA_BIT_WIDTH_32BIT;

In the same function, fold together the 16 and 32 bit cases, so both use i2s_channel_write:

#elif (16 == MODDEF_AUDIOOUT_I2S_BITSPERSAMPLE) || (32 == MODDEF_AUDIOOUT_I2S_BITSPERSAMPLE)
		i2s_channel_write(out->tx_handle, (const char *)out->buffer, sizeof(out->buffer), &bytes_written, portMAX_DELAY);
#else
	#error invalid MODDEF_AUDIOOUT_I2S_BITSPERSAMPLE
#endif

It would be good to have this case working for other devices that may need it. Still, it may be just fine on M5Stack Core2 to use the 16 bit case.

Thank you!

@meganetaaan
Copy link
Contributor Author

meganetaaan commented Oct 6, 2023

I applied the change above and the sound is back! Thank you for your quick fix.

@phoddie phoddie added the fixed - please verify Issue has been fixed. Please verify and close. label Oct 11, 2023
@phoddie phoddie closed this as completed Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed - please verify Issue has been fixed. Please verify and close.
Projects
None yet
Development

No branches or pull requests

3 participants