From 97e8e036c5e01666d210ae2bf8cf2eb7f65e83e8 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Thu, 15 Aug 2019 12:46:04 +1000
Subject: [PATCH] stm32/usbd: Support USB device mode on STM32L432 MCUs.

---
 ports/stm32/mpconfigboard_common.h | 2 +-
 ports/stm32/stm32_it.c             | 2 +-
 ports/stm32/usbd_conf.c            | 5 +++++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h
index a7a48aabc..d353468f9 100644
--- a/ports/stm32/mpconfigboard_common.h
+++ b/ports/stm32/mpconfigboard_common.h
@@ -288,7 +288,7 @@
 #endif
 
 // Whether the USB peripheral is device-only, or multiple OTG
-#if defined(STM32L0) || defined(STM32WB)
+#if defined(STM32L0) || defined(STM32L432xx) || defined(STM32WB)
 #define MICROPY_HW_USB_IS_MULTI_OTG (0)
 #else
 #define MICROPY_HW_USB_IS_MULTI_OTG (1)
diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c
index 16db92d1d..a2ebb6641 100644
--- a/ports/stm32/stm32_it.c
+++ b/ports/stm32/stm32_it.c
@@ -298,7 +298,7 @@ void DebugMon_Handler(void) {
 /*  file (startup_stm32f4xx.s).                                               */
 /******************************************************************************/
 
-#if defined(STM32L0)
+#if defined(STM32L0) || defined(STM32L432xx)
 
 #if MICROPY_HW_USB_FS
 void USB_IRQHandler(void) {
diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c
index 7577ee21b..275ec15aa 100644
--- a/ports/stm32/usbd_conf.c
+++ b/ports/stm32/usbd_conf.c
@@ -64,6 +64,8 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
         const uint32_t otg_alt = GPIO_AF10_OTG1_FS;
         #elif defined(STM32L0)
         const uint32_t otg_alt = GPIO_AF0_USB;
+        #elif defined(STM32L432xx)
+        const uint32_t otg_alt = GPIO_AF10_USB_FS;
         #elif defined(STM32WB)
         const uint32_t otg_alt = GPIO_AF10_USB;
         #else
@@ -113,6 +115,9 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
         #if defined(STM32L0)
         NVIC_SetPriority(USB_IRQn, IRQ_PRI_OTG_FS);
         HAL_NVIC_EnableIRQ(USB_IRQn);
+        #elif defined(STM32L432xx)
+        NVIC_SetPriority(USB_FS_IRQn, IRQ_PRI_OTG_FS);
+        HAL_NVIC_EnableIRQ(USB_FS_IRQn);
         #elif defined(STM32WB)
         NVIC_SetPriority(USB_LP_IRQn, IRQ_PRI_OTG_FS);
         HAL_NVIC_EnableIRQ(USB_LP_IRQn);
-- 
GitLab