Skip to content

Commit e531ea8

Browse files
committed
chore: enhance Nucleo L432KC system clock config
Allows LPUART low baudrate (9600) which is common in Arduino example. Fixes #2897. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent d8062ae commit e531ea8

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

variants/STM32L4xx/L432K(B-C)U_L442KCU/variant_NUCLEO_L432KC.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,34 @@ WEAK void SystemClock_Config(void)
7171
RCC_OscInitTypeDef RCC_OscInitStruct = {};
7272
RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
7373

74-
/* MSI is enabled after System reset, activate PLL with MSI as source */
75-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI;
74+
/** Configure the main internal regulator output voltage
75+
*/
76+
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
77+
Error_Handler();
78+
}
79+
80+
/* Configure LSE Drive Capability */
81+
HAL_PWR_EnableBkUpAccess();
82+
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
83+
84+
/** Initializes the RCC Oscillators according to the specified parameters
85+
* in the RCC_OscInitTypeDef structure.
86+
*/
87+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE
88+
| RCC_OSCILLATORTYPE_MSI;
7689
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
90+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
91+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
7792
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
93+
RCC_OscInitStruct.MSICalibrationValue = 0;
7894
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
79-
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
8095
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
8196
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
8297
RCC_OscInitStruct.PLL.PLLM = 1;
8398
RCC_OscInitStruct.PLL.PLLN = 40;
8499
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
85100
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
86101
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
87-
88102
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
89103
Error_Handler();
90104
}
@@ -96,11 +110,14 @@ WEAK void SystemClock_Config(void)
96110
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
97111
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
98112
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
113+
99114
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
100115
Error_Handler();
101116
}
102117

103-
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
118+
/* Initializes the peripherals clock */
119+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USB;
120+
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_HSI;
104121
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
105122
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
106123
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
@@ -112,10 +129,6 @@ WEAK void SystemClock_Config(void)
112129
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
113130
Error_Handler();
114131
}
115-
/* Configure the main internal regulator output voltage */
116-
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
117-
Error_Handler();
118-
}
119132
/* Enable MSI Auto calibration */
120133
HAL_RCCEx_EnableMSIPLLMode();
121134
}

0 commit comments

Comments
 (0)