ESP32-S3 two codecs ES8311

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

ESP32-S3 two codecs ES8311

Postby dmitrij999 » Fri Feb 17, 2023 9:44 pm

Hello everyone!

In my application, I'd like to use two codecs ES8311, but I cannot initialize both I2S channels, only one of them. And I cannot initialize USB stack with I2S channel initiated.

I2S initialize code:

Code: Select all

#define TRANSCEIVER_I2S_NUM         (0)
#define HEADPHONES_I2S_NUM          (1)

...

static esp_err_t transceiver_i2s_driver_init(void)
{
    i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)TRANSCEIVER_I2S_NUM, I2S_ROLE_MASTER);
    chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
    ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &transceiver_tx_handle, &transceiver_rx_handle));
    i2s_std_config_t std_cfg = {
        .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(EXAMPLE_SAMPLE_RATE),
        .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
        .gpio_cfg = {
            .mclk = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_MCK,
            .bclk = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_BCK,
            .ws = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_WS,
            .dout = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_DOUT,
            .din = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_DIN,
            .invert_flags = {
                .mclk_inv = false,
                .bclk_inv = false,
                .ws_inv = false,
            },
        },
    };
    std_cfg.clk_cfg.mclk_multiple = (i2s_mclk_multiple_t)EXAMPLE_MCLK_MULTIPLE;

    ESP_ERROR_CHECK(i2s_channel_init_std_mode(transceiver_tx_handle, &std_cfg));
    ESP_ERROR_CHECK(i2s_channel_init_std_mode(transceiver_rx_handle, &std_cfg));
    ESP_ERROR_CHECK(i2s_channel_enable(transceiver_tx_handle));
    ESP_ERROR_CHECK(i2s_channel_enable(transceiver_rx_handle));
    return ESP_OK;
}

static esp_err_t headphones_i2s_driver_init(void)
{
    i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)HEADPHONES_I2S_NUM, I2S_ROLE_MASTER);
    chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
    ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &headphones_tx_handle, &headphones_rx_handle));
    i2s_std_config_t std_cfg = {
        .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(EXAMPLE_SAMPLE_RATE),
        .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
        .gpio_cfg = {
            .mclk = (gpio_num_t)CONFIG_HEADPHONES_I2S_MCK,
            .bclk = (gpio_num_t)CONFIG_HEADPHONES_I2S_BCK,
            .ws = (gpio_num_t)CONFIG_HEADPHONES_I2S_WS,
            .dout = (gpio_num_t)CONFIG_HEADPHONES_I2S_DOUT,
            .din = (gpio_num_t)CONFIG_HEADPHONES_I2S_DIN,
            .invert_flags = {
                .mclk_inv = false,
                .bclk_inv = false,
                .ws_inv = false,
            },
        },
    };
    std_cfg.clk_cfg.mclk_multiple = (i2s_mclk_multiple_t)EXAMPLE_MCLK_MULTIPLE;

    ESP_ERROR_CHECK(i2s_channel_init_std_mode(headphones_tx_handle, &std_cfg));
    ESP_ERROR_CHECK(i2s_channel_init_std_mode(headphones_rx_handle, &std_cfg));
    ESP_ERROR_CHECK(i2s_channel_enable(headphones_tx_handle));
    ESP_ERROR_CHECK(i2s_channel_enable(headphones_rx_handle));
    return ESP_OK;
}
Output when I try initialize both of them:

Code: Select all

E (1730) gdma: gdma_install_tx_interrupt(800): alloc interrupt failed
E (1730) gdma: gdma_register_tx_event_callbacks(399): install interrupt service failed
E (1730) gdma: gdma_install_rx_interrupt(773): alloc interrupt failed
E (1740) gdma: gdma_register_rx_event_callbacks(435): install interrupt service failed
I think it related to select DMA channels...
Could you please help me with the problem, especially with DMA channels select

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

Re: ESP32-S3 two codecs ES8311

Postby ESP_Sprite » Sat Feb 18, 2023 12:44 am

Are you also using other drivers that use interrupts? You could be running out of irq spots... could help to allocate some as shared.

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: ESP32-S3 two codecs ES8311

Postby dmitrij999 » Sat Feb 18, 2023 7:55 am

As for interrupts, I use GPIO interrupts, and install ISR service at the startup.
With that, I use I2C 2 channels, 2 ADCs, and use TinyUSB stack.
Explicitly I initiated one interrupt handler, need to check interrupt handlers initiated implicitly

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: ESP32-S3 two codecs ES8311

Postby dmitrij999 » Sat Feb 18, 2023 8:39 am

I commented out some of channels initiation, and it was OK

Code: Select all

static esp_err_t transceiver_i2s_driver_init(void)
{
    ESP_LOGI(TAG, "Initiating transceiver I2S channels");
    i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)TRANSCEIVER_I2S_NUM, I2S_ROLE_MASTER);
    chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
    ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &transceiver_tx_handle, &transceiver_rx_handle));
    i2s_std_config_t std_cfg_tc = {
        .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(EXAMPLE_SAMPLE_RATE),
        .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
        .gpio_cfg = {
            .mclk = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_MCK,
            .bclk = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_BCK,
            .ws = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_WS,
            .dout = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_DOUT,
            .din = (gpio_num_t)CONFIG_TRANSCEIVER_I2S_DIN,
            .invert_flags = {
                .mclk_inv = false,
                .bclk_inv = false,
                .ws_inv = false,
            },
        },
    };
    std_cfg.clk_cfg.mclk_multiple = (i2s_mclk_multiple_t)EXAMPLE_MCLK_MULTIPLE;

    // ESP_ERROR_CHECK(i2s_channel_init_std_mode(transceiver_tx_handle, &std_cfg_tc));
    ESP_ERROR_CHECK(i2s_channel_init_std_mode(transceiver_rx_handle, &std_cfg_tc));
    // ESP_ERROR_CHECK(i2s_channel_enable(transceiver_tx_handle));
    ESP_ERROR_CHECK(i2s_channel_enable(transceiver_rx_handle));
    return ESP_OK;
}

static esp_err_t headphones_i2s_driver_init(void)
{
    ESP_LOGI(TAG, "Initiating headphones I2S channels");
    i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)HEADPHONES_I2S_NUM, I2S_ROLE_MASTER);
    chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
    ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &headphones_tx_handle, &headphones_rx_handle));
    i2s_std_config_t std_cfg_hf = {
        .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(EXAMPLE_SAMPLE_RATE),
        .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
        .gpio_cfg = {
            .mclk = (gpio_num_t)CONFIG_HEADPHONES_I2S_MCK,
            .bclk = (gpio_num_t)CONFIG_HEADPHONES_I2S_BCK,
            .ws = (gpio_num_t)CONFIG_HEADPHONES_I2S_WS,
            .dout = (gpio_num_t)CONFIG_HEADPHONES_I2S_DOUT,
            .din = (gpio_num_t)CONFIG_HEADPHONES_I2S_DIN,
            .invert_flags = {
                .mclk_inv = false,
                .bclk_inv = false,
                .ws_inv = false,
            },
        },
    };
    std_cfg.clk_cfg.mclk_multiple = (i2s_mclk_multiple_t)EXAMPLE_MCLK_MULTIPLE;

    ESP_ERROR_CHECK(i2s_channel_init_std_mode(headphones_tx_handle, &std_cfg_hf));
    // ESP_ERROR_CHECK(i2s_channel_init_std_mode(headphones_rx_handle, &std_cfg_hf));
    ESP_ERROR_CHECK(i2s_channel_enable(headphones_tx_handle));
    // ESP_ERROR_CHECK(i2s_channel_enable(headphones_rx_handle));
    return ESP_OK;
}
I'd like to have both of channels of each codec, not the same time is OK

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

Re: ESP32-S3 two codecs ES8311

Postby ESP_Sprite » Sun Feb 19, 2023 3:16 am

You're possibly running out of IRQ slots. You could see if you can have some of the drivers use a shared interrupt.

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: ESP32-S3 two codecs ES8311

Postby dmitrij999 » Sun Feb 19, 2023 3:36 pm

In my project, the peripherals I use:
- GPIO, isr service is installed with flag 0
- LEDC fade function installs ISR with flag (intr_alloc_flags | ESP_INTR_FLAG_IRAM)
- both I2Cs are initiated with ISR flag 0
- ADC

As well, I need USB and 2 I2S modules
How to check if some of them ones uses shared interrupts?

dmitrij999
Posts: 71
Joined: Sat Mar 02, 2019 8:06 pm

Re: ESP32-S3 two codecs ES8311

Postby dmitrij999 » Sun Feb 19, 2023 3:58 pm

When I enabled verbose output, I see the following (regarding the GDMA ISR installing)

Code: Select all

D (6496) gdma: new rx channel (0,1) at 0x3c060de4
D V (6526) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (6536) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0x80E

Who is online

Users browsing this forum: No registered users and 75 guests