You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2023/04/13 19:34:04 UTC
[mynewt-core] 04/05: tinyusb: Enable USB for STM32U5
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit f7d9dd25b261d0bc43909c6daa0b0540b7f77f6e
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Mar 28 22:23:36 2023 +0200
tinyusb: Enable USB for STM32U5
STM32U5 has very similar USB block to STM32F4 and STM32L4.
This enable synopsy package that initializes interrupts
that are needed when building USB project on STM32U5 boards.
---
hw/usb/tinyusb/pkg.yml | 2 ++
hw/usb/tinyusb/synopsys/include/tusb_hw.h | 2 ++
hw/usb/tinyusb/synopsys/src/synopsys.c | 17 ++++++++++++++---
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/pkg.yml
index 9887af23d..1fd70176d 100644
--- a/hw/usb/tinyusb/pkg.yml
+++ b/hw/usb/tinyusb/pkg.yml
@@ -48,6 +48,8 @@ pkg.deps.MCU_STM32F7:
- "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
pkg.deps.MCU_STM32L4:
- "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
+pkg.deps.MCU_STM32U5:
+ - "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
pkg.deps.MCU_STM32F1:
- "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev"
pkg.deps.MCU_STM32L0:
diff --git a/hw/usb/tinyusb/synopsys/include/tusb_hw.h b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
index 33137f500..b54bb2a80 100755
--- a/hw/usb/tinyusb/synopsys/include/tusb_hw.h
+++ b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
@@ -34,6 +34,8 @@
#define CFG_TUSB_MCU OPT_MCU_STM32F7
#elif MYNEWT_VAL(MCU_STM32L4)
#define CFG_TUSB_MCU OPT_MCU_STM32L4
+#elif MYNEWT_VAL(MCU_STM32U5)
+#define CFG_TUSB_MCU OPT_MCU_STM32U5
#endif
#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
diff --git a/hw/usb/tinyusb/synopsys/src/synopsys.c b/hw/usb/tinyusb/synopsys/src/synopsys.c
index 69ce4eea0..bca255082 100755
--- a/hw/usb/tinyusb/synopsys/src/synopsys.c
+++ b/hw/usb/tinyusb/synopsys/src/synopsys.c
@@ -24,6 +24,12 @@
#include <mcu/stm32_hal.h>
+#if defined(STM32U5)
+#define GPIO_AF_USB GPIO_AF10_USB
+#else
+#define GPIO_AF_USB GPIO_AF10_OTG_FS
+#endif
+
static void
OTG_FS_IRQHandler(void)
{
@@ -41,7 +47,7 @@ tinyusb_hardware_init(void)
* USB Pin Init
* PA11- DM, PA12- DP
*/
- hal_gpio_init_af(MCU_GPIO_PORTA(11), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+ hal_gpio_init_af(MCU_GPIO_PORTA(11), GPIO_AF_USB, GPIO_NOPULL, GPIO_MODE_AF_PP);
#if MYNEWT_VAL(USB_DP_HAS_EXTERNAL_PULL_UP)
hal_gpio_init_out(MCU_GPIO_PORTA(12), 0);
#if MYNEWT_VAL(BOOT_LOADER)
@@ -50,7 +56,7 @@ tinyusb_hardware_init(void)
os_time_delay(1);
#endif
#endif
- hal_gpio_init_af(MCU_GPIO_PORTA(12), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+ hal_gpio_init_af(MCU_GPIO_PORTA(12), GPIO_AF_USB, GPIO_NOPULL, GPIO_MODE_AF_PP);
/*
* Enable USB OTG clock, force device mode
@@ -58,7 +64,7 @@ tinyusb_hardware_init(void)
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
#if MYNEWT_VAL(USB_ID_PIN_ENABLE)
- hal_gpio_init_af(MCU_GPIO_PORTA(10), GPIO_AF10_OTG_FS, GPIO_PULLUP, GPIO_MODE_AF_OD);
+ hal_gpio_init_af(MCU_GPIO_PORTA(10), GPIO_AF_USB, GPIO_PULLUP, GPIO_MODE_AF_OD);
#else
USB_OTG_FS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD;
USB_OTG_FS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
@@ -88,4 +94,9 @@ tinyusb_hardware_init(void)
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
#endif
#endif
+
+#if MYNEWT_VAL(MCU_STM32U5)
+ /* Enable USB power */
+ HAL_PWREx_EnableVddUSB();
+#endif
}