Skip to content

drivers: usb: dwc2: esp32: Add support #85600

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

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

Conversation

raffarost
Copy link
Collaborator

@raffarost raffarost commented Feb 11, 2025

Add USB device driver support for ESP32 devices with USB-OTG peripheral.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Feb 11, 2025

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

Name Old Revision New Revision Diff

All manifest checks OK

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

@zephyrbot zephyrbot added manifest manifest-hal_espressif DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Feb 11, 2025
@raffarost raffarost marked this pull request as ready for review February 11, 2025 14:09
@zephyrbot zephyrbot added area: USB Universal Serial Bus platform: ESP32 Espressif ESP32 area: Xtensa Xtensa Architecture area: Samples Samples labels Feb 11, 2025
Comment on lines -3163 to +3365
static void udc_dwc2_irq_enable_func_##n(const struct device *dev) \
{ \
IRQ_CONNECT(DT_INST_IRQN(n), \
DT_INST_IRQ(n, priority), \
udc_dwc2_isr_handler, \
DEVICE_DT_INST_GET(n), \
DW_IRQ_FLAGS(n)); \
\
irq_enable(DT_INST_IRQN(n)); \
} \
\
static void udc_dwc2_irq_disable_func_##n(const struct device *dev) \
{ \
irq_disable(DT_INST_IRQN(n)); \
} \
UDC_DWC2_IRQ_DT_INST_DEFINE(n) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like a stray change that was not justified in the commit message. Anyway, I do not agree with it, you should use irq_enable()/irq_disable().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for the time being we are using Espressif's interrupt allocator
I thought about turning it into a quirk API call, but it would be probably disliked as a solution
do you have a different suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not understand the problem with irq_enable/irq_disable. How was it accepted not to use generic API for your platform? Are you working on fixing it?

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 did some checking, and the current behavior for ESP Xtensa chips is: Zephyr's API is used to control non-muxed interrupt lines (such as wifi, systimer). Most peripherals such as USB allow routing sources through an interrupt matrix and for this, the interrupt controller API is used. I'm not sure how much this deviates from the standard implementation, but I believe significant changes would be needed to otherwise accommodate this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jfischer-no, for esp32 device, we still need the irq calls in there, otherwise it is no-go for now. Would you review it again?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still cannot find an explanation as to why your platform cannot use generic functions, or why this has not been done all the time is supported in Zephyr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ESP chips use an interrupt controller peripheral to route interrupt sources coming from each peripheral to the CPU's IRQ lines. For this reason we implement an interrupt controller driver and call it's API directly from all ESP drivers. A few peripherals have their interrupt source lines connected directly to the CPU IRQ's, thus having dedicated lines (e.g. wifi). As USB OTG is routed using the Interrupt Matrix peripheral we need to connect it's interrupt source to the IRQ accessing HAL LL calls. As this can't be accomplished using Zephyr's irq_connect() without making significant changes to the way we manage interrupts, we are asking to treat interrupt allocation as a quirk for the time being. We are already discussing internally if we should rework the interrupt system implementation and we did a review recently, so this will still be an ongoing work for us. Also, we are still not implementing static interrupt allocation even for IRQ lines that are static and don't need routing.

@raffarost
Copy link
Collaborator Author

@jfischer-no
would you mind clarifying these points so I can work on the PR? thank you

marekmatej
marekmatej previously approved these changes Jun 9, 2025
sylvioalves
sylvioalves previously approved these changes Jun 21, 2025
uLipe
uLipe previously approved these changes Jun 26, 2025
@raffarost raffarost dismissed stale reviews from uLipe, sylvioalves, marekmatej, and wmrsouza via efae400 June 27, 2025 12:50
@raffarost raffarost force-pushed the feature/usb_otg branch 2 times, most recently from efae400 to 5cdf02d Compare June 27, 2025 12:53
marekmatej
marekmatej previously approved these changes Jun 27, 2025
wmrsouza
wmrsouza previously approved these changes Jun 27, 2025
@raffarost raffarost dismissed stale reviews from wmrsouza and marekmatej via cecbed3 June 30, 2025 00:36
@raffarost
Copy link
Collaborator Author

CI fix #92314

@raffarost raffarost requested a review from jfischer-no July 1, 2025 17:49
wmrsouza
wmrsouza previously approved these changes Jul 1, 2025
Raffael Rostagno added 4 commits July 8, 2025 09:27
Add USB device driver support for ESP32 devices with
USB-OTG peripheral.

Signed-off-by: Raffael Rostagno <[email protected]>
Limit RX FIFO size allocation to a percentage of the total
SPRAM available, to cap allocation according to memory size.

Signed-off-by: Raffael Rostagno <[email protected]>
Add USB-OTG peripheral support to ESP32S3.

Signed-off-by: Raffael Rostagno <[email protected]>
Add default zephyr_udc0 label for USB-OTG.

Signed-off-by: Raffael Rostagno <[email protected]>
Add USB mass storage sample overlay for esp32s3_devkitm board.

Signed-off-by: Raffael Rostagno <[email protected]>
Copy link

sonarqubecloud bot commented Jul 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: Samples Samples area: USB Universal Serial Bus area: Xtensa Xtensa Architecture platform: ESP32 Espressif ESP32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants