Skip to content

dwc2/host: enable disconnect interrupt + handle it #3067

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

Merged
merged 3 commits into from
Apr 18, 2025

Conversation

maximevince
Copy link
Contributor

Describe the PR
On boards using the Synopsys DWC2 USB IP core, there were no disconnection events when a USB device was unplugged.
This PR enabled the GINTSTS_DISCINT flag, to get an interrupt on disconnection + handles it by calling hcd_event_device_remove().

Additional context
Tested on an STM32F7, but behavior should be identical on any device using the dwc2

@HiFiPhile
Copy link
Collaborator

Hi, I ended up with the same thing in #2960

I also removed hcd_event_device_remove(rhport, in_isr); from handle_hprt_irq() to prevent double remove event in some cases.

@maximevince
Copy link
Contributor Author

Aha, nice!
Do you want me to remove hcd_event_device_remove in handle_hprt_irq as well, and merge this PR first?

It doesn't matter to me, whichever you can get merged first :)

@HiFiPhile
Copy link
Collaborator

Do you want me to remove hcd_event_device_remove in handle_hprt_irq as well

Yes please, just double checked ST's HAL code.

and merge this PR first ?

@hathach is busy atm, since dwc2 is widely used it's better wait for Espressif @roma-jam for a double check.
Personally I tested with ESP32-S3-DevKitM and NUCLEO-H7S3L8.


Out of topic: Have you experienced any bouncing issue doing quickly connection/disconnection like in #2960 ?

… to prevent double removal

Signed-off-by: Maxime Vincent <[email protected]>
@maximevince maximevince force-pushed the dwc2-host-fix-disconnect branch from ebb3b6e to 6607b76 Compare April 8, 2025 12:34
@maximevince
Copy link
Contributor Author

maximevince commented Apr 8, 2025

@HiFiPhile

  • I've updated the PR. I have also removed hcd_event_device_remove(rhport, in_isr); from handle_hprt_irq() now
  • About the "bouncing": if I manually connect/disconnect very quickly, the USB port crashes indeed.
    It crashes in usbh.c in function process_enumeration() in case ENUM_ADDR0_DEVICE_DESC:
    TU_ASSERT(tuh_descriptor_get_device(addr0, _usbh_epbuf.ctrl, 8,
                                        process_enumeration, ENUM_SET_ADDR),);
    or in: hcd_dwc2.c, function hcd_edpt_xfer() at line 638:
    uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir);
    TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX);

@maximevince
Copy link
Contributor Author

Can we merge this? Is there any more action required from my side?
@hathach @HiFiPhile

Copy link
Collaborator

@HiFiPhile HiFiPhile left a comment

Choose a reason for hiding this comment

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

It's reliable in my end, @hathach do you need more test ?

@HiFiPhile HiFiPhile merged commit 91163c9 into hathach:master Apr 18, 2025
129 of 130 checks passed
@hathach
Copy link
Owner

hathach commented Apr 22, 2025

perfect, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants