I have an issue passing data my application reads in from wav files stored on SD-card to the I2S driver. I though I did everything right but I cannot get rid of the error and the board (Adafruit Huzzah32) keeps resetting.
I know that the code does not have major problems as it was developed for another microcontroller with I2S interface originally and verified to be working. Now I wanted to port the same code to the ESP32. I tried my setup with an Audio library (https://github.com/schreibfaul1/ESP32-audioI2S) which worked and therefore I know that wiring-wise my setup can play sound via I2S.
The I2S config looks like this:
Code: Select all
// configure the ESP32's I2S interface
m_i2s_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT;
m_i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
// memory (SRAM) allocated to I2S buffer: (bits_per_sample/8)*channels*dma_buf_count*dmu_buf_len
m_i2s_config.dma_buf_count = 2; // between 2 and 128 (see error code 283)
m_i2s_config.dma_buf_len = I2S_BUF_SIZE*2; // number of I2S samples, multiplied by 2 due to 16bit samples stored on 32bit (L/R)
m_i2s_config.fixed_mclk = I2S_PIN_NO_CHANGE;
m_i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; // interrupt priority
m_i2s_config.sample_rate = 16000;
m_i2s_config.tx_desc_auto_clear = true; // new in V1.0.1
m_i2s_config.use_apll = APLL_DISABLE;
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
#if ESP_ARDUINO_VERSION_MAJOR >= 2
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S); // Arduino vers. > 2.0.0
#else
// standard I2S format (i.e. not left-justified) means data transmission starts one BCLK cycle after LRCLK transition
// MAX98357A needs I2S format and MSB first
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB);
#endif
space .
I have 3 variables to fetch the samples from SD and pass them to I2S:
Code: Select all
uint8_t* maBufferA = NULL;
uint8_t* maBufferB = NULL;
int32_t maMixedI2SSamples[I2S_BUF_SIZE] = {};
Code: Select all
maBufferA = (uint8_t*) heap_caps_calloc(I2S_BUF_SIZE, sizeof(int32_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA);
Code: Select all
memcpy(maBufferA, maMixedI2SSamples, sizeof(int32_t)*I2S_BUF_SIZE);
Code: Select all
err = i2s_write((i2s_port_t)I2S_NUM_0, maBufferA, sizeof(int32_t) * I2S_BUF_SIZE, 0, 100);
20:27:42: I2SWavPlayer::StartPlayback>>Pass BufferA to i2s driver.
20:27:42: Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
20:27:42: Core 1 register dump:
20:27:42: PC : 0x400f15ad PS : 0x00060730 A0 : 0x800d37c2 A1 : 0x3ffb1ea0
20:27:42: A2 : 0x00000000 A3 : 0x3ffb2068 A4 : 0x00000004 A5 : 0x00000000
20:27:42: A6 : 0x00000064 A7 : 0x00000000 A8 : 0x800d5428 A9 : 0x3ffb1e90
20:27:42: A10 : 0x00000002 A11 : 0x3f401518 A12 : 0x00000ffc A13 : 0x3ffb5090
20:27:42: A14 : 0x3ffb86fc A15 : 0x000000ff SAR : 0x0000001b EXCCAUSE: 0x0000001d
20:27:42: EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffff1
20:27:42:
20:27:42: ELF file SHA256: 0000000000000000
20:27:42:
20:27:42: Backtrace: 0x400f15ad:0x3ffb1ea0 0x400d37bf:0x3ffb1ed0 0x400d1586:0x3ffb1f10 0x400d19cf:0x3ffb1f30 0x400d722a:0x3ffb1fb0 0x400864c9:0x3ffb1fd0
20:27:42:
20:27:42: Rebooting...
I tried everything I could thing of but the core still throws this error, I would be grateful if someone could give me a helping hand