This is an automated email from the ASF dual-hosted git repository.

kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 9cd8a6a59 tinyusb/synopsys: Use TinyUSB port matching selected USB core
9cd8a6a59 is described below

commit 9cd8a6a5944996eed96d2e51df93cb242f43962e
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Thu Oct 15 11:28:02 2026 +0200

    tinyusb/synopsys: Use TinyUSB port matching selected USB core
    
    Interrupt handlers passed fixed TinyUSB port numbers: 1 for OTG_HS and
    0 for OTG_FS. TinyUSB (dwc2_stm32.h) numbers OTG_FS as port 0 and
    OTG_HS as port 1 only on devices that have both cores. On devices with
    OTG_HS only (STM32H72x/H73x/H7Ax/H7Bx, STM32U59x/5Ax) OTG_HS is port 0.
    It worked on STM32H72x only because TinyUSB maps both ports to the
    single core there.
    
    Derive port number of the selected core and use it in single interrupt
    handler. Report wrong USBD_RHPORT setting at build time, i.e. OTG_HS
    selected on STM32F7 without USBD_RHPORT: USB1, which silently
    initialized OTG_FS core instead.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 hw/usb/tinyusb/synopsys/src/synopsys.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/hw/usb/tinyusb/synopsys/src/synopsys.c 
b/hw/usb/tinyusb/synopsys/src/synopsys.c
index 704077aef..9aad36c4e 100755
--- a/hw/usb/tinyusb/synopsys/src/synopsys.c
+++ b/hw/usb/tinyusb/synopsys/src/synopsys.c
@@ -37,6 +37,29 @@
 #endif
 #define GPIO_AF_USB        MYNEWT_VAL(USB_AF_USB)
 
+/*
+ * TinyUSB port of selected core (dwc2_stm32.h): OTG_FS is port 0, OTG_HS
+ * is port 1 when device also has OTG_FS.  On devices with OTG_HS only
+ * (STM32H72x/H73x/H7Ax/H7Bx, STM32U59x/5Ax) OTG_HS is port 0.
+ */
+#if !MYNEWT_VAL(USB_USE_OTG_HS) && !defined(USB_OTG_FS)
+#error "MCU has no USB_OTG_FS, set USB_USE_OTG_HS: 1"
+#endif
+#if MYNEWT_VAL(USB_USE_OTG_HS) && defined(USB_OTG_FS)
+#define USB_OTG_RHPORT 1
+#else
+#define USB_OTG_RHPORT 0
+#endif
+
+#if (MYNEWT_VAL_CHOICE(USBD_RHPORT, USB0) && USB_OTG_RHPORT != 0) ||          \
+    (MYNEWT_VAL_CHOICE(USBD_RHPORT, USB1) && USB_OTG_RHPORT != 1)
+#if USB_OTG_RHPORT == 0
+#error "USB core selected by USB_USE_OTG_HS requires USBD_RHPORT: USB0"
+#else
+#error "USB core selected by USB_USE_OTG_HS requires USBD_RHPORT: USB1"
+#endif
+#endif
+
 #if MYNEWT_VAL(USB_USE_OTG_HS_ULPI)
 static const int ulpi_pins[] = {
     MYNEWT_VAL(USB_ULPI_CK_PIN),
@@ -55,17 +78,10 @@ static const int ulpi_pins[] = {
 #endif
 
 void
-OTG_HS_IRQHandler(void)
-{
-    /* TinyUSB provides interrupt handler code */
-    tud_int_handler(1);
-}
-
-void
-OTG_FS_IRQHandler(void)
+USB_OTG_IRQHandler(void)
 {
     /* TinyUSB provides interrupt handler code */
-    tud_int_handler(0);
+    tud_int_handler(USB_OTG_RHPORT);
 }
 
 void

Reply via email to