Skip to content

Commit dc969ba

Browse files
author
Tauno Magnusson
committed
After checking other parts of the code (trng_api.c and a few other board platforms (NUCLEO_F413ZH, ...)) it appears that even though the reset value defaults correctly it may be good practice to keep the HAL_RCCEx_PeriphCLKConfig statement that selects the HSI48CLK as source for USB/RNG.
1 parent 21176e9 commit dc969ba

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

targets/TARGET_STM/TARGET_STM32G4/TARGET_STM32G431xB/system_clock.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
121121
return 0; // FAIL
122122
}
123123

124+
#if defined(DEVICE_USBDEVICE)
125+
// Connect the HSI48 Clock to drive the USB & RNG Clocks @ 48 MHz (CK48 Clock Mux)
126+
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
127+
RCC_PeriphCLKInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
128+
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct) != HAL_OK) {
129+
return 0; // FAIL
130+
}
131+
#endif
132+
124133
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
125134
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
126135
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
@@ -175,6 +184,15 @@ uint8_t SetSysClock_PLL_HSI(void)
175184
return 0; // FAIL
176185
}
177186

187+
#if defined(DEVICE_USBDEVICE)
188+
// Connect the HSI48 Clock to drive the USB & RNG Clocks @ 48 MHz (CK48 Clock Mux)
189+
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
190+
RCC_PeriphCLKInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
191+
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct) != HAL_OK) {
192+
return 0; // FAIL
193+
}
194+
#endif
195+
178196
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
179197
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
180198
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

0 commit comments

Comments
 (0)