espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.71k stars 7.3k forks source link

using I2S_COMM_FORMAT_STAND_PCM_SHORT doesn't trigger I2S_INTR_IN_SUC_EOF (IDFGH-6315) #7977

Open CarlosDerSeher opened 2 years ago

CarlosDerSeher commented 2 years ago

Environment

Problem Description

When configured as a I2S master with communication format I2S_COMM_FORMAT_STAND_PCM_SHORT receiving data is impossible and i2s_read() will time out. I2S_INTR_IN_SUC_EOF will never be set.

Expected Behavior

i2s_read() returning audio data from audio codec.

Actual Behavior

i2s_read() will time out, no data is returned

Code to reproduce this issue


void setup_dsp_i2s(void)
{
    uint32_t rate = 8000;

  i2s_config_t i2s_config0 = {
    .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX,
    .sample_rate = rate,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,             // 1-channels
    .communication_format = I2S_COMM_FORMAT_STAND_PCM_SHORT,
    .dma_buf_count = 2,
    .dma_buf_len = I2S_FRAME_SIZE,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM,  //Default interrupt priority
    .use_apll = true,
    .fixed_mclk = 0,
    .mclk_multiple = 1280,
    .bits_per_chan = 0,        // default '0' means equal to 'bits_per_sample'
    .tx_desc_auto_clear = true  // Auto clear tx descriptor on underflow
  };

  i2s_pin_config_t pin_config0 = {
      .bck_io_num   = CONFIG_MASTER_I2S_BCK_PIN,
      .ws_io_num    = CONFIG_MASTER_I2S_LRCK_PIN,
      .data_out_num = CONFIG_MASTER_I2S_DATAOUT_PIN,
      .data_in_num  = CONFIG_MASTER_I2S_DATAIN_PIN
    };

  i2s_driver_install(I2S_NUM_0, &i2s_config0, 1, &i2s_event_queue);
  i2s_set_pin(I2S_NUM_0, &pin_config0);
  i2s_mclk_gpio_select(I2S_NUM_0, GPIO_NUM_0);

  GPIO.func_out_sel_cfg[CONFIG_MASTER_I2S_LRCK_PIN].inv_sel = 1;  // invert the output of GPIO matrix.

  i2s_set_clk(I2S_NUM_0, rate, 16, I2S_CHANNEL_STEREO);
}

void app_main(void)
{
      uint32_t dataBufSize = 2*64 * sizeof(int16_t);
      int16_t *dataBuf = (int16_t *)malloc(dataBufSize);
      size_t bytes_written, bytes_read;

      setup_dsp_i2s();

      i2s_start(I2S_NUM_0);
      while(1) {
        i2s_event_t ev;

        //while(xQueueReceive(i2s_event_queue, &ev, portMAX_DELAY));
        //ESP_LOGI(BT_HF_TAG, "event %d", ev.type);

        memset(dataBuf, 0, dataBufSize);
        i2s_write(I2S_NUM_0, (uint8_t *)dataBuf, 2*64 * sizeof(int16_t), &bytes_written, pdMS_TO_TICKS(1000));
        ESP_LOGI(BT_HF_TAG, "wrote %d", bytes_written);
        i2s_read(I2S_NUM_0, (uint8_t *)dataBuf, bytes_written, &bytes_read, pdMS_TO_TICKS(1000));
        ESP_LOGI(BT_HF_TAG, "read %d", bytes_read);

      }
}

Debug Logs

I (27) boot: ESP-IDF v5.0-dev-489-gef98a363e3-dirty 2nd stage bootloader
I (27) boot: compile time 14:59:31
I (28) boot: chip revision: 3
I (32) boot_comm: chip revision: 3, min. bootloader chip revision: 1
I (39) boot.esp32: SPI Speed      : 80MHz
I (44) boot.esp32: SPI Mode       : DIO
I (48) boot.esp32: SPI Flash Size : 4MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (84) boot:  2 factory          factory app      00 00 00010000 003e9000
I (92) boot: End of partition table
I (96) boot_comm: chip revision: 3, min. application chip revision: 1
I (103) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0a128h ( 41256) map
I (124) esp_image: segment 1: paddr=0001a150 vaddr=3ffbdb60 size=034b4h ( 13492) load
I (129) esp_image: segment 2: paddr=0001d60c vaddr=40080000 size=02a0ch ( 10764) load
I (134) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=189f0h (100848) map
I (169) esp_image: segment 4: paddr=00038a18 vaddr=40082a0c size=0a3a0h ( 41888) load
I (184) esp_image: segment 5: paddr=00042dc0 vaddr=50000000 size=00010h (    16) load
I (191) boot: Loaded app from partition at offset 0x10000
I (191) boot: Disabling RNG early entropy source...
I (204) cpu_start: Pro cpu up.
I (205) cpu_start: Starting app cpu, entry point is 0x4008125c
0x4008125c: call_start_cpu1 at C:/Users/karl/espressif/esp-idf/esp-idf-v4.4/esp-idf/components/esp_system/port/cpu_start.c:164

I (0) cpu_start: App cpu up.
W (365) clk: 32 kHz XTAL not found, switching to internal 150 kHz oscillator
I (373) cpu_start: Pro cpu start user code
I (373) cpu_start: cpu freq: 240000000 Hz
I (373) cpu_start: Application information:
I (378) cpu_start: Project name:     hfp_hf
I (383) cpu_start: App version:      7b01ed8-dirty
I (388) cpu_start: Compile time:     Nov 29 2021 14:59:21
I (394) cpu_start: ELF file SHA256:  ea6747d5bc939d90...
I (400) cpu_start: ESP-IDF:          v5.0-dev-489-gef98a363e3-dirty
I (407) heap_init: Initializing. RAM available for dynamic allocation:
I (414) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (420) heap_init: At 3FFB6BF8 len 00001408 (5 KiB): DRAM
I (426) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (433) heap_init: At 3FFC1C08 len 0001E3F8 (120 KiB): DRAM
I (439) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (445) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (452) heap_init: At 4008CDAC len 00013254 (76 KiB): IRAM
I (458) spi_flash: detected chip: generic
I (463) spi_flash: flash io: dio
W (466) spi_flash: Detected size(8192k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (491) pm: Frequency switching config: CPU_MAX: 240, APB_MAX: 240, APB_MIN: 40, Light sleep: DISABLED
I (491) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (508) I2S: queue free spaces: 1
I (516) I2S: APLL Enabled, coefficient: sdm0=39, sdm1=49, sdm2=4, odir=6
I (519) I2S: DMA Malloc info, datalen=blocksize=128, dma_buf_count=2
I (526) I2S: DMA Malloc info, datalen=blocksize=128, dma_buf_count=2
I (533) I2S: I2S0, MCLK output by GPIO0
I (537) GENERIC_BOARD: I2S0, MCLK output by GPIO0
I (547) I2S: APLL Enabled, coefficient: sdm0=39, sdm1=49, sdm2=4, odir=6
I (563) BT_HF: wrote 256
I (1563) BT_HF: read 0
I (1568) BT_HF: wrote 256
I (2568) BT_HF: read 0
I (2571) BT_HF: wrote 256
I (3571) BT_HF: read 0
I (3579) BT_HF: wrote 256

Other items if possible

/ List of deprecated options /

define CONFIG_A2D_TRACE_LEVEL_WARNING CONFIG_BT_LOG_A2D_TRACE_LEVEL_WARNING

define CONFIG_ADC2_DISABLE_DAC CONFIG_ADC_DISABLE_DAC

define CONFIG_APPL_TRACE_LEVEL_WARNING CONFIG_BT_LOG_APPL_TRACE_LEVEL_WARNING

define CONFIG_AVCT_TRACE_LEVEL_WARNING CONFIG_BT_LOG_AVCT_TRACE_LEVEL_WARNING

define CONFIG_AVDT_TRACE_LEVEL_WARNING CONFIG_BT_LOG_AVDT_TRACE_LEVEL_WARNING

define CONFIG_AVRC_TRACE_LEVEL_WARNING CONFIG_BT_LOG_AVRC_TRACE_LEVEL_WARNING

define CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT

define CONFIG_BLUEDROID_ENABLED CONFIG_BT_BLUEDROID_ENABLED

define CONFIG_BLUEDROID_PINNED_TO_CORE_0 CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0

define CONFIG_BLUFI_TRACE_LEVEL_WARNING CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_WARNING

define CONFIG_BROWNOUT_DET CONFIG_ESP32_BROWNOUT_DET

define CONFIG_BROWNOUT_DET_LVL_SEL_0 CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0

define CONFIG_BTC_TASK_STACK_SIZE CONFIG_BT_BTC_TASK_STACK_SIZE

define CONFIG_BTC_TRACE_LEVEL_WARNING CONFIG_BT_LOG_BTC_TRACE_LEVEL_WARNING

define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN

define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN

define CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI CONFIG_BTDM_CTRL_HCI_MODE_VHCI

define CONFIG_BTDM_CONTROLLER_MODEM_SLEEP CONFIG_BTDM_CTRL_MODEM_SLEEP

define CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY

define CONFIG_BTIF_TRACE_LEVEL_WARNING CONFIG_BT_LOG_BTIF_TRACE_LEVEL_WARNING

define CONFIG_BTM_TRACE_LEVEL_WARNING CONFIG_BT_LOG_BTM_TRACE_LEVEL_WARNING

define CONFIG_BTU_TASK_STACK_SIZE CONFIG_BT_BTU_TASK_STACK_SIZE

define CONFIG_CLASSIC_BT_ENABLED CONFIG_BT_CLASSIC_ENABLED

define CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT

define CONFIG_ESP32S2_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT

define CONFIG_ESP32_APPTRACE_DEST_NONE CONFIG_APPTRACE_DEST_NONE

define CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY

define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE CONFIG_ESP_COREDUMP_ENABLE_TO_NONE

define CONFIG_ESP32_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT

define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE

define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER CONFIG_ESP_PHY_MAX_WIFI_TX_POWER

define CONFIG_ESP32_PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN

define CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT CONFIG_PTHREAD_TASK_NAME_DEFAULT

define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT CONFIG_PTHREAD_TASK_PRIO_DEFAULT

define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT

define CONFIG_ESP32_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER

define CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS

define CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES

define CONFIG_ESP_GRATUITOUS_ARP CONFIG_LWIP_ESP_GRATUITOUS_ARP

define CONFIG_ESP_SYSTEM_PD_FLASH CONFIG_ESP_SLEEP_POWER_DOWN_FLASH

define CONFIG_FLASHMODE_DIO CONFIG_ESPTOOLPY_FLASHMODE_DIO

define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR

define CONFIG_GAP_TRACE_LEVEL_WARNING CONFIG_BT_LOG_GAP_TRACE_LEVEL_WARNING

define CONFIG_GARP_TMR_INTERVAL CONFIG_LWIP_GARP_TMR_INTERVAL

define CONFIG_GATT_TRACE_LEVEL_WARNING CONFIG_BT_LOG_GATT_TRACE_LEVEL_WARNING

define CONFIG_HCI_TRACE_LEVEL_WARNING CONFIG_BT_LOG_HCI_TRACE_LEVEL_WARNING

define CONFIG_HFP_AUDIO_DATA_PATH_HCI CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI

define CONFIG_HFP_CLIENT_ENABLE CONFIG_BT_HFP_CLIENT_ENABLE

define CONFIG_HFP_ENABLE CONFIG_BT_HFP_ENABLE

define CONFIG_HID_TRACE_LEVEL_WARNING CONFIG_BT_LOG_HID_TRACE_LEVEL_WARNING

define CONFIG_INT_WDT CONFIG_ESP_INT_WDT

define CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1

define CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS

define CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_TASK_STACK_SIZE

define CONFIG_L2CAP_TRACE_LEVEL_WARNING CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_WARNING

define CONFIG_LOG_BOOTLOADER_LEVEL_INFO CONFIG_BOOTLOADER_LOG_LEVEL_INFO

define CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE

define CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE

define CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT

define CONFIG_MB_CONTROLLER_SLAVE_ID CONFIG_FMB_CONTROLLER_SLAVE_ID

define CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT

define CONFIG_MB_CONTROLLER_STACK_SIZE CONFIG_FMB_CONTROLLER_STACK_SIZE

define CONFIG_MB_EVENT_QUEUE_TIMEOUT CONFIG_FMB_EVENT_QUEUE_TIMEOUT

define CONFIG_MB_MASTER_DELAY_MS_CONVERT CONFIG_FMB_MASTER_DELAY_MS_CONVERT

define CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND

define CONFIG_MB_QUEUE_LENGTH CONFIG_FMB_QUEUE_LENGTH

define CONFIG_MB_SERIAL_BUF_SIZE CONFIG_FMB_SERIAL_BUF_SIZE

define CONFIG_MB_SERIAL_TASK_PRIO CONFIG_FMB_PORT_TASK_PRIO

define CONFIG_MB_SERIAL_TASK_STACK_SIZE CONFIG_FMB_PORT_TASK_STACK_SIZE

define CONFIG_MB_TIMER_PORT_ENABLED CONFIG_FMB_TIMER_PORT_ENABLED

define CONFIG_MCA_TRACE_LEVEL_WARNING CONFIG_BT_LOG_MCA_TRACE_LEVEL_WARNING

define CONFIG_MONITOR_BAUD_115200B CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B

define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE

define CONFIG_OSI_TRACE_LEVEL_WARNING CONFIG_BT_LOG_OSI_TRACE_LEVEL_WARNING

define CONFIG_PAN_TRACE_LEVEL_WARNING CONFIG_BT_LOG_PAN_TRACE_LEVEL_WARNING

define CONFIG_POST_EVENTS_FROM_IRAM_ISR CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR

define CONFIG_POST_EVENTS_FROM_ISR CONFIG_ESP_EVENT_POST_FROM_ISR

define CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER

define CONFIG_RFCOMM_TRACE_LEVEL_WARNING CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_WARNING

define CONFIG_SDP_TRACE_LEVEL_WARNING CONFIG_BT_LOG_SDP_TRACE_LEVEL_WARNING

define CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN

define CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS

define CONFIG_SMP_TRACE_LEVEL_WARNING CONFIG_BT_LOG_SMP_TRACE_LEVEL_WARNING

define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS

define CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE

define CONFIG_SUPPORT_TERMIOS CONFIG_VFS_SUPPORT_TERMIOS

define CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT

define CONFIG_SW_COEXIST_ENABLE CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE

define CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE

define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE

define CONFIG_TASK_WDT CONFIG_ESP_TASK_WDT

define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0

define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1

define CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIMEOUT_S

define CONFIG_TCPIP_RECVMBOX_SIZE CONFIG_LWIP_TCPIP_RECVMBOX_SIZE

define CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY

define CONFIG_TCPIP_TASK_STACK_SIZE CONFIG_LWIP_TCPIP_TASK_STACK_SIZE

define CONFIG_TCP_MAXRTX CONFIG_LWIP_TCP_MAXRTX

define CONFIG_TCP_MSL CONFIG_LWIP_TCP_MSL

define CONFIG_TCP_MSS CONFIG_LWIP_TCP_MSS

define CONFIG_TCP_OVERSIZE_MSS CONFIG_LWIP_TCP_OVERSIZE_MSS

define CONFIG_TCP_QUEUE_OOSEQ CONFIG_LWIP_TCP_QUEUE_OOSEQ

define CONFIG_TCP_RECVMBOX_SIZE CONFIG_LWIP_TCP_RECVMBOX_SIZE

define CONFIG_TCP_SND_BUF_DEFAULT CONFIG_LWIP_TCP_SND_BUF_DEFAULT

define CONFIG_TCP_SYNMAXRTX CONFIG_LWIP_TCP_SYNMAXRTX

define CONFIG_TCP_WND_DEFAULT CONFIG_LWIP_TCP_WND_DEFAULT

define CONFIG_TIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH

define CONFIG_TIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY

define CONFIG_TIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH

define CONFIG_TIMER_TASK_STACK_SIZE CONFIG_ESP_TIMER_TASK_STACK_SIZE

define CONFIG_TOOLPREFIX CONFIG_SDK_TOOLPREFIX

define CONFIG_UDP_RECVMBOX_SIZE CONFIG_LWIP_UDP_RECVMBOX_SIZE

tpbedford commented 2 years ago

Same is true of ESP-IDF 4.3. I've experienced the same issue. I've had some luck by deliberately misconfiguring the RX register bit I2S_CONF_REG.I2S_RX_SHORT_SYNC

In i2s_ll.h (ESP-IDF 4.3) I can make the below change in _i2s_ll_set_rx_pcm_short(i2s_devt *hw) by modifying _conf.rx_shortsync to be cleared. The physical WS clock signal on GPIO is still set to PCM SHORT thanks to the _conf.tx_shortsync bit setting, at least when using _i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODERX)

/**
 * @brief Set I2S TX to PCM short standard
 *
 * @param hw Peripheral I2S hardware instance address.
 */
static inline void i2s_ll_set_tx_pcm_short(i2s_dev_t *hw)
{
    hw->conf.tx_short_sync = 1;
    hw->conf.tx_msb_shift = 0;
}

/**
 * @brief Set I2S RX to PCM short standard
 *
 * @param hw Peripheral I2S hardware instance address.
 */
static inline void i2s_ll_set_rx_pcm_short(i2s_dev_t *hw)
{
    //hw->conf.rx_short_sync = 1; // fails to trigger ISR on receive
    hw->conf.rx_short_sync = 0; // UNSET this to correctly trigger the ISR on receive
    hw->conf.rx_msb_shift = 0;
}

I see that this has been refactored in ESP-IDF 4.4 and 5.0, so perhaps there's a similar work-around that can be made to omit the call to i2s_hal_rx_pcm_cfg(hal, cfg), or after installing the driver try a call to i2s_hal_rx_set_common_mode(i2s_hal_context_t hal, const i2s_hal_config_t hal_cfg) to revert the short PCM setting for the RX path?

CarlosDerSeher commented 2 years ago

Thank you for your input and indeed after changing

void setup_dsp_i2s(void)
{
  uint32_t rate = 8000;

  i2s_config_t i2s_config0 = {
    .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX,
    .sample_rate = rate,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,             // 1-channels
    .communication_format = I2S_COMM_FORMAT_STAND_PCM_SHORT,
    .dma_buf_count = 2,
    .dma_buf_len = I2S_FRAME_SIZE,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM,  //Default interrupt priority
    .use_apll = true,
    .fixed_mclk = 0,
    .mclk_multiple = 1280,
    .bits_per_chan = 0,        // default '0' means equal to 'bits_per_sample'
    .tx_desc_auto_clear = true  // Auto clear tx descriptor on underflow
  };

  i2s_pin_config_t pin_config0 = {
      .bck_io_num   = CONFIG_MASTER_I2S_BCK_PIN,
      .ws_io_num    = CONFIG_MASTER_I2S_LRCK_PIN,
      .data_out_num = CONFIG_MASTER_I2S_DATAOUT_PIN,
      .data_in_num  = CONFIG_MASTER_I2S_DATAIN_PIN
    };

  i2s_driver_install(I2S_NUM_0, &i2s_config0, 1, &i2s_event_queue);
  i2s_set_pin(I2S_NUM_0, &pin_config0);
  i2s_mclk_gpio_select(I2S_NUM_0, GPIO_NUM_0);

  GPIO.func_out_sel_cfg[CONFIG_MASTER_I2S_LRCK_PIN].inv_sel = 1;  // invert the output of GPIO matrix.

  i2s_set_clk(I2S_NUM_0, rate, 16, I2S_CHANNEL_STEREO);

  (&I2S0)->conf.rx_short_sync = 0;  // UNSET this to correctly trigger the ISR on receive
}

Notice the last line (&I2S0)->conf.rx_short_sync = 0; // UNSET this to correctly trigger the ISR on receive in the function it starts to work. I'll still have to check if audio coming in sounds right, but doing loopback as in my opening post I am getting some data.