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

ESP32-audioI2S crashes on arduino-esp32 v3.0.7 #875

Closed
enjoyneering opened this issue Oct 24, 2024 · 10 comments
Closed

ESP32-audioI2S crashes on arduino-esp32 v3.0.7 #875

enjoyneering opened this issue Oct 24, 2024 · 10 comments

Comments

@enjoyneering
Copy link

enjoyneering commented Oct 24, 2024

Hi schreibfaul1,

The latest ESP32-audioI2S v3.0.13d crashes on arduino-esp32 v3.0.7. Same code works OK on arduino-esp32 v3.0.5. I'm not an expert, but I think the problem is related to the latest changes in arduino PSRAM. The Exception Decoder points to Audio::setDefaults().

The hardware I use:
ESP32-S3 R8N2 at 240Mhz with 8MB flash at 80MHz (QIO) & 2MB PSRAM (QSPI).

Exception_Decoder_setDefaults()

@schreibfaul1
Copy link
Owner

The Arduino version 3.0.7 was released recently. I have tested this version in VSCode nit PIO and have not been able to reproduce the error. According to your log, there is a memory violation during an if query. Strange, maybe the error only occurs under certain configurations?

@enjoyneering
Copy link
Author

enjoyneering commented Oct 25, 2024

Hi schreibfaul1,

If I disable PSRAM, my code works fine on arduino-esp32 v3.0.7. Looks like problem is related to the latest changes in arduino PSRAM:

This is my PSRAM configuration when everything crashes on v3.0.7 (the same settings work OK on arduino-esp32 v3.0.5):

esp32-s_settings

@enjoyneering
Copy link
Author

I enabled PSRAM, commented out the line audio.connecttohost(AUDIO_WEBRADIO_00); and everything worked, without sound.

codec_info
sys_info

@stef-ladefense
Copy link

hi, I have exactly the same crashes with version 3.07.

I went back to version ESP32-audioI2S-3.0.12f to work with 3.07.
with 3.05, version ESP32-audioI2S-3.0.13e works.

@schreibfaul1
Copy link
Owner

I have now tested V3.0.7 in the Arduino IDE. @enjoyneering is right, PSRAM is not initialised correctly. This leads to an "out of memory".
image

Arduino V3.0.5 works.

@me-no-dev
Copy link

The problem is not in Arduino, but in the library constructor: https://github.com/schreibfaul1/ESP32-audioI2S/blob/master/src/Audio.cpp#L161

It is allocating and dealing with memory BEFORE the memory is properly initialized. All that code should be executed in setup() and not before that.

It worked before, because it ran before any PSRAM was touched, thus acting like PSRAM is not there at all.

@schreibfaul1
Copy link
Owner

I don't think the timing of the PSRAM initialisation is the problem, it hasn't been since V1. The Arduino version 3.0.7 (IDF 5.1.4) runs flawlessly in PlatformIO. I only have the error in the Arduino IDE

@me-no-dev
Copy link

This does not change the fact that in the constructor (which runs before PSRAM is added to heap and anything else is started and prepared) there are many things done that should not be done there. All that should happen in the constructor is basic class variables setup. All other memory operations should be done later in setup(). Starting I2S also. That oom error above happened at the same time that PSRAM was enabled, which means that the code that allocates memory started even earlier. This all lands the constructor in no man's land (at the same time that memory map for the OS is being set).

@me-no-dev
Copy link

This has not been a problem so far, because PSRAM was initialized AFTER Audio::Audio(), therefore PSRAM was not even on yet. You were starting it yourself here which is also a very bad idea. This is a private API that is called by the core at the appropriate time. Please revise your constructor, else coming 3.1.0 there will be even more issues with the memory

@schreibfaul1
Copy link
Owner

@me-no-dev Thanks for the explanation. The PSRAM will now be initialised at a later time, everything is perfect, and in the Arduino IDE it is now also running.
I think I can close this topic with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants