Skip to content

Commit 92d2de8

Browse files
committed
stm32/usbd_conf: Treat G0 USB periph as MICROPY_HW_USB_IS_MULTI_OTG=0.
The G0 USB peripheral behaves more like MICROPY_HW_USB_IS_MULTI_OTG=0 than that config =1. This fixes the configuration of the PMA FIFO buffers. Signed-off-by: Damien George <[email protected]>
1 parent b839acc commit 92d2de8

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

ports/stm32/mpconfigboard_common.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@
574574
#endif
575575

576576
// Whether the USB peripheral is device-only, or multiple OTG
577-
#if defined(STM32G4) || defined(STM32L0) || defined(STM32L432xx) || defined(STM32WB)
577+
// For STM32G0 the USB peripheral supports device and host mode,
578+
// but otherwise acts like a non-multi-OTG peripheral.
579+
#if defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L432xx) || defined(STM32WB)
578580
#define MICROPY_HW_USB_IS_MULTI_OTG (0)
579581
#else
580582
#define MICROPY_HW_USB_IS_MULTI_OTG (1)

ports/stm32/usbd_cdc_interface.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252

5353
#if !MICROPY_HW_USB_IS_MULTI_OTG
5454
#define USE_USB_CNTR_SOFM (1)
55-
#elif defined(STM32G0)
56-
#define USE_USB_CNTR_SOFM (1)
55+
#if defined(STM32G0)
5756
#define USB USB_DRD_FS
57+
#endif
5858
#else
5959
#define USE_USB_CNTR_SOFM (0)
6060
#endif

ports/stm32/usbd_conf.c

+6-12
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ PCD_HandleTypeDef pcd_fs_handle;
4444
PCD_HandleTypeDef pcd_hs_handle;
4545
#endif
4646

47-
#if !MICROPY_HW_USB_IS_MULTI_OTG
48-
// The MCU has a single USB device-only instance
49-
#define USB_OTG_FS USB
50-
#endif
51-
5247
#if defined(STM32G0)
5348
#define USB_OTG_FS USB_DRD_FS
49+
#elif !MICROPY_HW_USB_IS_MULTI_OTG
50+
// The MCU has a single USB device-only instance
51+
#define USB_OTG_FS USB
5452
#endif
5553

5654
/*******************************************************************************
@@ -119,7 +117,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
119117
#endif
120118

121119
// Enable USB FS Clocks
122-
#if !MICROPY_HW_USB_IS_MULTI_OTG || defined(STM32G0)
120+
#if !MICROPY_HW_USB_IS_MULTI_OTG
123121
__HAL_RCC_USB_CLK_ENABLE();
124122
#else
125123
__USB_OTG_FS_CLK_ENABLE();
@@ -262,11 +260,7 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) {
262260
#if MICROPY_HW_USB_FS
263261
if (hpcd->Instance == USB_OTG_FS) {
264262
/* Disable USB FS Clocks */
265-
#if defined(STM32G0)
266-
__HAL_RCC_USB_CLK_DISABLE();
267-
#else
268263
__USB_OTG_FS_CLK_DISABLE();
269-
#endif
270264
return;
271265
}
272266
#endif
@@ -443,7 +437,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev, int high_speed, const
443437
pcd_fs_handle.Init.speed = PCD_SPEED_FULL;
444438
pcd_fs_handle.Init.lpm_enable = DISABLE;
445439
pcd_fs_handle.Init.battery_charging_enable = DISABLE;
446-
#if MICROPY_HW_USB_IS_MULTI_OTG
440+
#if MICROPY_HW_USB_IS_MULTI_OTG || defined(STM32G0)
447441
#if !defined(STM32G0)
448442
pcd_fs_handle.Init.use_dedicated_ep1 = 0;
449443
#endif
@@ -463,7 +457,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev, int high_speed, const
463457
HAL_PCD_Init(&pcd_fs_handle);
464458

465459
// Set FIFO buffer sizes
466-
#if !MICROPY_HW_USB_IS_MULTI_OTG || defined(STM32G0)
460+
#if !MICROPY_HW_USB_IS_MULTI_OTG
467461
uint32_t fifo_offset = USBD_PMA_RESERVE; // need to reserve some data at start of FIFO
468462
for (size_t i = 0; i < USBD_PMA_NUM_FIFO; ++i) {
469463
uint16_t ep_addr = ((i & 1) * 0x80) | (i >> 1);

0 commit comments

Comments
 (0)