Skip to content

Commit c5bfa7e

Browse files
authored
Merge pull request #14340 from chrJost/master
STM32L5: enable USBDEVICE
2 parents 1f28e6e + 96c31e1 commit c5bfa7e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

targets/TARGET_STM/TARGET_STM32L5/system_clock.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ uint8_t SetSysClock_PLL_MSI(void)
147147
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
148148
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
149149
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
150-
#if DEVICE_TRNG
150+
#if DEVICE_TRNG || DEVICE_USBDEVICE
151151
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
152152
#else
153153
RCC_OscInitStruct.HSI48State = RCC_HSI48_OFF;
@@ -176,12 +176,21 @@ uint8_t SetSysClock_PLL_MSI(void)
176176
return 0; // FAIL
177177
}
178178

179-
#if DEVICE_TRNG
180179
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
180+
#if DEVICE_TRNG
181181
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RNG;
182182
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_HSI48;
183-
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
184-
#endif
183+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
184+
return 0; // FAIL
185+
}
186+
#endif
187+
#if DEVICE_USBDEVICE
188+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
189+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
190+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
191+
return 0; // FAIL
192+
}
193+
#endif
185194

186195
return 1; // OK
187196
}

targets/TARGET_STM/USBPhyHw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(TARGET_STM32WB) || defined(TARGET_STM32G4)
4747
#define USBHAL_IRQn USB_LP_IRQn
48+
#elif defined(TARGET_STM32L5)
49+
#define USBHAL_IRQn USB_FS_IRQn
4850
#else
4951
#define USBHAL_IRQn USB_IRQn
5052
#endif

targets/targets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,8 @@
39513951
"FLASH",
39523952
"MPU",
39533953
"SERIAL_ASYNCH",
3954-
"TRNG"
3954+
"TRNG",
3955+
"USBDEVICE"
39553956
]
39563957
},
39573958
"MCU_STM32L552xE": {

0 commit comments

Comments
 (0)