Skip to content

Commit e1d3037

Browse files
authored
Merge pull request #13725 from jeromecoutant/PR_L476_HSE
STM32: update SetSysClock for NUCLEO_L476RG
2 parents 0548981 + 282bc22 commit e1d3037

File tree

1 file changed

+3
-32
lines changed
  • targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG

1 file changed

+3
-32
lines changed

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG/system_clock.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,19 @@ void SetSysClock(void)
110110
/******************************************************************************/
111111
/* PLL (clocked by HSE) used as System clock source */
112112
/******************************************************************************/
113-
uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
113+
MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
114114
{
115115
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
116116
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
117117
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit = {0};
118118

119-
// Used to gain time after DeepSleep in case HSI is used
120-
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) {
121-
return 0;
122-
}
123-
124-
// Select MSI as system clock source to allow modification of the PLL configuration
125-
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
126-
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
127-
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
128-
129119
// Enable HSE oscillator and activate PLL with HSE as source
130-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI;
120+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
131121
if (bypass == 0) {
132122
RCC_OscInitStruct.HSEState = RCC_HSE_ON; // External 8 MHz xtal on OSC_IN/OSC_OUT
133123
} else {
134124
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // External 8 MHz clock on OSC_IN
135125
}
136-
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
137126
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; // 8 MHz
138127
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
139128
RCC_OscInitStruct.PLL.PLLM = 1; // VCO input clock = 8 MHz (8 MHz / 1)
@@ -171,12 +160,6 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
171160
}
172161
#endif /* DEVICE_USBDEVICE */
173162

174-
// Disable MSI Oscillator
175-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
176-
RCC_OscInitStruct.MSIState = RCC_MSI_OFF;
177-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // No PLL update
178-
HAL_RCC_OscConfig(&RCC_OscInitStruct);
179-
180163
// Output clock on MCO1 pin(PA8) for debugging purpose
181164
#if DEBUG_MCO == 2
182165
if (bypass == 0) {
@@ -200,14 +183,8 @@ uint8_t SetSysClock_PLL_HSI(void)
200183
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
201184
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit = {0};
202185

203-
// Select MSI as system clock source to allow modification of the PLL configuration
204-
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
205-
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
206-
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
207-
208186
// Enable HSI oscillator and activate PLL with HSI as source
209-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
210-
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
187+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
211188
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
212189
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
213190
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@@ -246,12 +223,6 @@ uint8_t SetSysClock_PLL_HSI(void)
246223
}
247224
#endif /* DEVICE_USBDEVICE */
248225

249-
// Disable MSI Oscillator
250-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
251-
RCC_OscInitStruct.MSIState = RCC_MSI_OFF;
252-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // No PLL update
253-
HAL_RCC_OscConfig(&RCC_OscInitStruct);
254-
255226
// Output clock on MCO1 pin(PA8) for debugging purpose
256227
#if DEBUG_MCO == 3
257228
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); // 16 MHz

0 commit comments

Comments
 (0)