Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds deinitialization support for the Synopsys DWC2 USB controller, enabling dynamic start/stop of USB host and device modes. The implementation mirrors the initialization sequence in reverse, disabling interrupts, disconnecting from the bus, and resetting the core. This was tested on STM32H7S3 with device mode toggling via button press.
Key Changes
- Implements
hcd_deinit()anddcd_deinit()functions for DWC2 host and device controllers - Adds common
dwc2_core_deinit()function shared between host and device modes - Updates error handling in
tuh_deinit()andtud_deinit()to useTU_ASSERTconsistently - Fixes button active state configuration for STM32H7S3 Nucleo board
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/portable/synopsys/dwc2/hcd_dwc2.c |
Adds host controller deinit implementation with interrupt disable |
src/portable/synopsys/dwc2/dwc2_common.h |
Declares dwc2_core_deinit() for shared deinitialization logic |
src/portable/synopsys/dwc2/dwc2_common.c |
Implements common core deinit with soft disconnect and core reset |
src/portable/synopsys/dwc2/dcd_dwc2.c |
Adds device controller deinit with disconnect and cleanup |
src/host/usbh.c |
Changes hcd_deinit() call to use TU_ASSERT for error checking |
src/device/usbd.c |
Changes dcd_deinit() call to use TU_ASSERT for consistency |
hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h |
Corrects button active state from 1 to 0 (active-low with pullup) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2c8f34d to
2a994a3
Compare
9461753 to
e214976
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e214976 to
ceb4274
Compare
|
TinyUSB Average Code Size Metrics
Input files
|
| return phys_addr; | ||
| } | ||
|
|
||
| TU_ATTR_WEAK void tusb_pre_init_cb(uint8_t rhport, tusb_role_t role) { |
There was a problem hiding this comment.
do we really need this, both init() and de-init() is called by application, they should call them before/after those accordingly ?
There was a problem hiding this comment.
@hathach It's for host/device specific init, like STM32's GCCFG and GOTGCTL register, which need to be set to different value on host/device. Their meaning is also different across families, I haven't found a easy way to include them in the driver.
tinyusb/hw/bsp/stm32h7rs/family.c
Line 390 in 8a466ff
There was a problem hiding this comment.
Give me a bit of time, I will try to review and see if we could avoid using these callbacks
7c4233b to
f7d82a1
Compare
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
d9f369e to
22acfb6
Compare
|
@hathach I've rebased on master. |
| // Suppress IAR warning | ||
| // Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement | ||
| #if defined(__ICCARM__) | ||
| #pragma diag_suppress = Pa082 |
There was a problem hiding this comment.
@HiFiPhile which compile flags to pass to IAR to enable most warning like gcc, we can enable it for tinyusb build as well.
PS: ah, I just add --warnings-are-errors then try to fix them
|
@HiFiPhile I push changes that also add mcu specific phy deinit as well (suggested by claude). Please review to see if that makes sense to you. Also I haven't tested with the dynamic_switch example (getting lazy with wiring), please re-check if you already have it setup PS: I think we can do better with low power/suspend mode by disable clock etc, but that is for later. |
| dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN; | ||
|
|
||
| // Disable HS PHY if present | ||
| #ifdef USB_HS_PHYC |
There was a problem hiding this comment.
F723 has USB_HS_PHYC but only for HS port.
There was a problem hiding this comment.
I guess we also need the hs_phy_type argument to de-init the right one ?
There was a problem hiding this comment.
I think yes, also need to take care of when both HS port are used like on N6.
There was a problem hiding this comment.
I think we need to avoid turning off PHYC on N6 when another port is still active.
There was a problem hiding this comment.
right N6 has 2 instance of USB1/2_HS_PHYC_NS. We can use the dwc2 check to disale the right phy. But we didn't enable it in dwc2_phy_init(). Not sure if N6 is currently working, I don't have the board to test with
There was a problem hiding this comment.
I think it's okay in fact, didn't notice on N6 it has 2 dedicated PHYC instance.
N6 is working with my N6570-DK.
There was a problem hiding this comment.
hmm, maybe the phy is auto enabled/disabled using dwc2 signal (physel, utmi) with latet stm config. Variant with USB_HS_PHYC seems to use stm32_gccfg to enable/disable phy. I guess that would be ok to merge now ?
There was a problem hiding this comment.
The PHYC init code is in bsp currently:
tinyusb/hw/bsp/stm32n6/family.c
Line 184 in cd7bbba
It's okay to merge.
There was a problem hiding this comment.
ah thanks, I think we should move it inside our driver that will allow us to disable phy to save power later on. But that can be on its own PR later.
…ialization across all MCUs
hathach
left a comment
There was a problem hiding this comment.
perfect, thank you very much, I am glad that we finally merge this
a54e973 to
75a5bed
Compare



@roma-jam Hi, I've added deinit support to dwc2.
A dynamic switch example is added and tested on: