ESP32S2 I2S and MQTT Error

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

ESP32S2 I2S and MQTT Error

Postby markirwin » Sun Sep 19, 2021 9:44 am

Dear All,

I am using I2S to play audio files and MQTT to transfer these audio files between devices and saving to SPIFFS. I have a curious problem where I can create and play audio files on the same device and never run into any issues. However, if i create a file on device A and then send it to the second device B, file approximately 100KB, writing to the SPIFFS this all works fine. But then playback causes a kernel panic with the following error:

Code: Select all

I (811131) I2S_Audio: Start playing
E (811141) I2S: Register I2S Interrupt error: 261
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400c98fe  PS      : 0x00060830  A0      : 0x800a1ff6  A1      : 0x3ffd6c40
0x400c98fe: i2s_set_pin at C:/Users/mpwir/esp/esp-idf/components/driver/i2s.c:780

A2      : 0x00000000  A3      : 0x3ffd0c54  A4      : 0x0000000a  A5      : 0x00000000
A6      : 0x3ffd1d00  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffd6bf0
A10     : 0x00000001  A11     : 0x3f019eec  A12     : 0x3f01a4b4  A13     : 0x000c6085
A14     : 0x3f019eec  A15     : 0x00000105  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000002c  LBEG    : 0x3f01a4b4  LEND    : 0x000c6085  LCOUNT  : 0x40026bbd
0x40026bbd: _xt_user_exc at C:/Users/mpwir/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:627


Backtrace:0x400c98fb:0x3ffd6c40 0x400a1ff3:0x3ffd6c80 0x4008bfa3:0x3ffd6cd0 0x4008c03b:0x3ffd6cf0 0x400899cb:0x3ffd6d10 0x400a0f0d:0x3ffd6d30 0x400a0fff:0x3ffd6d50 0x40089081:0x3ffd6d70 0x400890aa:0x3ffd6da0 0x40032365:0x3ffd6dc0
0x400c98fb: i2s_set_pin at C:/Users/mpwir/esp/esp-idf/components/driver/i2s.c:780

0x400a1ff3: I2SOutput::start(int) at C:/Users/mpwir/esp/FL_Standard/components/i2saudio/I2SOutput.cpp:26

0x4008bfa3: play(Output*, char const*) at c:\users\mpwir\esp\fl_standard\standard_lamp\build/../main/app_audio.cpp:197

0x4008c03b: audio_play at c:\users\mpwir\esp\fl_standard\standard_lamp\build/../main/app_audio.cpp:237

0x400899cb: button_audio_play_cb at c:\users\mpwir\esp\fl_standard\standard_lamp\build/../main/app_driver.c:353 (discriminator 15)

0x400a0f0d: button_handler at C:/Users/mpwir/esp/FL_Standard/components/button/iot_button.c:122 (discriminator 1)

0x400a0fff: button_cb at C:/Users/mpwir/esp/FL_Standard/components/button/iot_button.c:171 (discriminator 3)

0x40089081: timer_process_alarm at C:/Users/mpwir/esp/esp-idf/components/esp_timer/src/esp_timer.c:330

0x400890aa: timer_task at C:/Users/mpwir/esp/esp-idf/components/esp_timer/src/esp_timer.c:349 (discriminator 1)

0x40032365: vPortTaskWrapper at C:/Users/mpwir/esp/esp-idf/components/freertos/port/xtensa/port.c:168
I changed the i2s error to give the err code which is 261 or 0x150 which indicates that the resource is not available.

There seems to be some shared IRQ between I2S and the MQTT library? I am not sure which way to investigate this.

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

Re: ESP32S2 I2S and MQTT Error

Postby markirwin » Tue Sep 28, 2021 12:20 pm

Anyone have any pointers in how to get a more descriptive error?

and why would MQTT share interrupts with I2S? This only happens when handling a large file transfer.

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32S2 I2S and MQTT Error

Postby ESP_Sprite » Wed Sep 29, 2021 3:00 am

MQTT doesn't use interrupts; there must be something else going on. Are you sure you're not running out of memory?

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

Re: ESP32S2 I2S and MQTT Error

Postby markirwin » Thu Oct 14, 2021 5:25 am

Hi ESP_Sprite,

I managed to fix the problem which seemed to be because I had initialised the SD card which I wasn't using. Once the SD card init was removed it then started working.

I am using an ESP32S2 with 8MB PSRAM which has been added to the heap so I would hope I'm not running out of memory.

Code: Select all

I (2103) spiram: Adding pool of 8192K of external SPI memory to heap allocator
I (2112) spi_flash: detected chip: winbond
I (2116) spi_flash: flash io: dio
I (2124) cpu_start: Starting scheduler on PRO CPU.
I (2126) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I am however now using a WiFi-Manager and got a similar problem. I have switched from SoftAP to an HTTP WiFi-Manager (https://github.com/tonyp7/esp32-wifi-manager) but then my audio task failed to start.. with debugging I found I couldn't start my audio task because of the stack size, i had defined it has

Code: Select all

xReturned = xTaskCreate(&audio_task, "audio_task", 16384, NULL, 1, &xHandleAudioTsk);
But i kept returning -1 and not starting. Once I changed the stack to 8192 it would start but now I get this error:
E (171666) I2S: Error malloc dma buffer

Any suggestions on next steps to fix this problem?

Best

Mark

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32S2 I2S and MQTT Error

Postby ESP_Sprite » Thu Oct 14, 2021 6:47 am

You're likely out of internal memory (needed to do DMA transfers). There's an option in menuconfig somewhere that allows you to reserve a certain amount of internal memory for DMA stuff ('Reserve this amount of bytes for data that specifically needs to be in DMA or internal memory' under Component config → CHIP91-Specific → Support for external, SPI-connected RAM → SPI RAM config), suggest you increase that and try again.

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

Re: ESP32S2 I2S and MQTT Error

Postby markirwin » Fri Oct 15, 2021 10:40 am

Hi ESP_SPRITE,

I did this and it did fix my DMA issue, however, then the ESP-MQTT TLS stack kept failing to create an SSL connection. Which i couldn't resolve by rolling back my code changes either.

mbedtls_ssl_setup returned -0x7f00 which was also an out of memory problem.

I am using ESP32S2 on IDF 4.3.1 and saw that there was a newer version of IDF. I have pulled and updated the sub modules, but found this has now broken my i2s and i2c drivers.

The I2S was pretty straight forward as it complained about sample rate being uint32_t was previously an int and missing defines for
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT,
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT,

This got it to load but then it would works reading from the microphone but now writing out results in this ISR error.

Code: Select all

E (127206) I2S: i2s_dma_intr_init(539): Register I2S Interrupt error
E (127216) I2S: i2s_driver_install(1952): I2S interrupt initailze failed
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40099f32  PS      : 0x00060030  A0      : 0x8009348e  A1      : 0x3ffd3820
0x40099f32: i2s_set_pin at C:/Users/mpwir/esp/esp-idf/components/driver/i2s.c:302 (discriminator 4)

A2      : 0x00000000  A3      : 0x3ffd38c8  A4      : 0x00000000  A5      : 0x00000000
A6      : 0x00000105  A7      : 0x3fffd42c  A8      : 0x3ffcdb94  A9      : 0xffffffff
A10     : 0x0000000c  A11     : 0x00000000  A12     : 0xffc00000  A13     : 0x0001f0f0
A14     : 0x3f0102c8  A15     : 0x3f011058  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000038  LBEG    : 0xffc00000  LEND    : 0x0001f0f0  LCOUNT  : 0x40026dbd
0x40026dbd: _xt_user_exc at C:/Users/mpwir/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:633



Backtrace:0x40099f2f:0x3ffd38200x4009348b:0x3ffd3850 0x4008b5e7:0x3ffd38a0 0x4008b68f:0x3ffd38c0 0x400892ff:0x3ffd3900 0x40128589:0x3ffd3920 0x4008bd01:0x3ffd3940 0x400885e1:0x3ffd3960 0x40088629:0x3ffd3990 0x40030221:0x3ffd39b0
The I2C is also broken. I can initalise the i2C but everytime i read from it I get a panic.

Code: Select all

Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40027610  PS      : 0x00060031  A0      : 0x8002778d  A1      : 0x3ffcba30
0x40027610: i2c_master_cmd_begin_static at C:/Users/mpwir/esp/esp-idf/components/driver/i2c.c:1345

A2      : 0x00000000  A3      : 0x3fff74b4  A4      : 0x00000000  A5      : 0x00002000
A6      : 0x3ffcbe7c  A7      : 0x3ff9fbf0  A8      : 0x00000000  A9      : 0x3f413000
A10     : 0x00000901  A11     : 0x00000001  A12     : 0x3ffd8228  A13     : 0x6001301c
A14     : 0x00000001  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000008  LBEG    : 0x3ffd8228  LEND    : 0x6001301c  LCOUNT  : 0x40026ecd
0x40026ecd: _xt_user_exc at C:/Users/mpwir/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:633

Core  0 was running in ISR context:
EPC1    : 0x40084387  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x00000000
0x40084387: uart_hal_write_txfifo at C:/Users/mpwir/esp/esp-idf/components/hal/uart_hal_iram.c:35



Backtrace:0x4002760d:0x3ffcba300x4002778a:0x3ffcba60 0x40026fea:0x3ffcba90 0x4012daeb:0x3ff9fc20 0x400a5f46:0x3ff9fc40 0x4002fa95:0x3ff9fc60 0x400314b5:0x3ff9fc80
0x4002760d: i2c_master_cmd_begin_static at C:/Users/mpwir/esp/esp-idf/components/driver/i2c.c:1344

0x4002778a: i2c_isr_handler_default at C:/Users/mpwir/esp/esp-idf/components/driver/i2c.c:497

0x40026fea: _xt_lowint1 at C:/Users/mpwir/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1111

markirwin
Posts: 10
Joined: Sun Nov 22, 2020 10:42 am

Re: ESP32S2 I2S and MQTT Error

Postby markirwin » Fri Oct 15, 2021 11:24 am

I resolved the I2S error on able to allocate interrupt by setting
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, it was set to level2.

Still not resolved the i2c issue, not sure exactly what has changed in the 4.3.1 branch since release last week.

Who is online

Users browsing this forum: Google [Bot] and 199 guests