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

i2s support for esp32 and esp32s2 #83710

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

wmrsouza
Copy link
Collaborator

@wmrsouza wmrsouza commented Jan 8, 2025

This PR adds i2s support to those SoCs lacking GDMA:

  • ESP32
  • ESP32-S2

@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch from af5e945 to 60d7026 Compare January 11, 2025 10:41
@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch 2 times, most recently from 4431669 to 045619f Compare January 21, 2025 15:39
@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch from 045619f to 652e2aa Compare February 12, 2025 13:46
@zephyrbot
Copy link
Collaborator

zephyrbot commented Feb 12, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_espressif zephyrproject-rtos/hal_espressif@a459b40 zephyrproject-rtos/hal_espressif@d64439e (zephyr) zephyrproject-rtos/[email protected]

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@wmrsouza wmrsouza marked this pull request as ready for review February 12, 2025 13:47
@zephyrbot zephyrbot added manifest-hal_espressif DNM (manifest) This PR should not be merged (controlled by action-manifest) area: I2S area: Xtensa Xtensa Architecture area: RISCV RISCV Architecture (32-bit & 64-bit) platform: ESP32 Espressif ESP32 area: Pinctrl labels Feb 12, 2025

#include <zephyr/logging/log.h>
#include <zephyr/irq.h>

#include <esp_clk_tree.h>
#include <hal/i2s_hal.h>

#if !SOC_GDMA_SUPPORTED
#include <soc/lldesc.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to line 20 to use a single #if !SOC_GDMA_SUPPORTED?

#if !SOC_GDMA_SUPPORTED
#include <soc/lldesc.h>
#endif /* !SOC_GDMA_SUPPORTED */

LOG_MODULE_REGISTER(i2s_esp32, CONFIG_I2S_LOG_LEVEL);

#if !SOC_GDMA_SUPPORTED
Copy link
Collaborator

@sylvioalves sylvioalves Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this #ifdef is not necessary, just leave the definition in there.

@@ -12,18 +12,28 @@
#include <soc.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/devicetree.h>

#if !SOC_GDMA_SUPPORTED
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is SOC_GDMA_SUPPORTED is set per SoC but dma is not enabled, i.e, app is using descriptors instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not implement dma transfers using descriptor on SoCs that support GDMA. It is only made for those SoCs that do not support GDMA. Since a dma instance is required to perform i2s transfers on SoCs that support GDMA, the build process will fail. I will provide an preprocessor error conditional on SOC_GDMA_SUPPORTED and !DT_HAS_COMPAT_STATUS_OKAY(espressif_esp32_gdma) for the cases where dma has been disable:

#if SOC_GDMA_SUPPORTED && !DT_HAS_COMPAT_STATUS_OKAY(espressif_esp32_gdma)
#error "DMA peripheral is not enabled!"
#endif /* SOC_GDMA_SUPPORTED */

Even so I bilieve the failure will continue to occur despite the error message being issued

@@ -310,8 +310,6 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x6000f000 0x1000>;
interrupts = <I2S0_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed from ESP32S3 and C3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I thought it was necessary, but now I see it's a mistake.
I'll revert it

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Intel Corporation.
* Copyright (c) 2019-2025 Intel Corporation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of extending the copyright of the original creator, append a new line adding Espressif's. Do the same for all files that copyright was changed.

@@ -17,18 +17,6 @@ properties:
clocks:
required: true

interrupts:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interrupts really need to go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interrupts along with interrupt-names was the way I found to inform to the driver during build time which i2s channels are enabled so those resources that are not being used due to a not used i2s channel can be not allocated or removed by optimization process. The same stuff is achieved by using dmas along with dma-names for the GDMA SoCs .

*
* SPDX-License-Identifier: Apache-2.0
*/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra line

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the other files.

i2s_rxtx: &i2s0 {
status = "okay";

interrupts = <I2S0_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interrupts are already defined in .dtsi. Is it needed again here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the other files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interrupts along with interrupt-names was the way I found to inform to the driver during build time which i2s channels are enabled so those resources that are not being used due to a not used i2s channel can be not allocated or removed by optimization process.

@@ -17,3 +17,6 @@ config STOP_START_STREAMS_SW1
depends on $(dt_alias_enabled,sw1)
select GPIO
default y

config DOESNT_SUPPORT_I2S_DIR_BOTH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest I2S_DIR_BOTH_NOT_SUPPORTED

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we can't have I2S_DIR_BOTH implemented in the I2S driver?

Copy link
Collaborator Author

@wmrsouza wmrsouza Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rework the i2s_esp32_trigger() and the ì2s_esp32_configure() functions to accept I2S_DIR_BOTH and revert the changes made on echo sample

@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch 2 times, most recently from d27f92c to 33d75c2 Compare February 14, 2025 02:41
@wmrsouza wmrsouza requested a review from sylvioalves February 14, 2025 02:44
@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch from 33d75c2 to e11d6dc Compare February 14, 2025 04:37
@gmarull gmarull assigned anangl and unassigned gmarull Feb 17, 2025
@gmarull gmarull removed their request for review February 17, 2025 09:03
@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch 3 times, most recently from 8bcbe65 to 17e904c Compare February 19, 2025 05:09
<I2S0_O_SD_GPIO7>,
<I2S0_I_WS_GPIO15>,
<I2S0_I_BCK_GPIO16>;
output-enable;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these the right flags? (usually used for loopback)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are correct

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the input pins be placed in group2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact no. In this configuration they are output pins connected to the input/rx path. In other configuration they could be driven by output sources, but in this conf they will provide output signals.

const struct i2s_esp32_stream *stream;
int err;

switch (dir) {
Copy link
Collaborator

@raffarost raffarost Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use a fallthrough between RX/TX (and the appropriate checks for break instructions), it's possible to avoid repeated code (suggestion only), for I2S_DIR_BOTH

#address-cells = <1>;
#size-cells = <0>;
reg = <0x3ff4f000 0x1000>;
interrupts = <I2S0_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to declare the same source twice (could it be avoided)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was the way I found to save resources (throughout interrup-names and dma-names)
as the interrupt source is the same for TX and RX I had to declare the same source for each channel.

Code and data refactoring to prepare for adding support for non-gdma SoCs

Signed-off-by: Marcio Ribeiro <[email protected]>
hal_espressif revision update to add i2s support for esp32 and esp32s2

Signed-off-by: Marcio Ribeiro <[email protected]>
Adds support for:
- esp32
- esp32s2

Signed-off-by: Marcio Ribeiro <[email protected]>
@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch from 17e904c to 73f2fd1 Compare February 20, 2025 12:39
@zephyrbot zephyrbot removed the DNM (manifest) This PR should not be merged (controlled by action-manifest) label Feb 20, 2025
Adds i2s support for boards based on:
- esp32
- esp32s2

Signed-off-by: Marcio Ribeiro <[email protected]>
Adds esp32 board overlay files to i2s samples

Signed-off-by: Marcio Ribeiro <[email protected]>
@wmrsouza wmrsouza force-pushed the feature/i2s_no_gdma branch from 73f2fd1 to 97c1a72 Compare February 20, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: I2S area: LED Label to identify LED subsystem area: Pinctrl area: RISCV RISCV Architecture (32-bit & 64-bit) area: Samples Samples area: Xtensa Xtensa Architecture manifest manifest-hal_espressif platform: ESP32 Espressif ESP32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants