Skip to content

Commit 86a68db

Browse files
ralfdoeringfpistm
andcommitted
fix: add a fallback HSI clock config for Nucleo F030R8
Allow boards without ST-LINK MCO, including MB1136 C-01 in its factory-default wiring, to use HSI / 2 * 12 at 48 MHz. These boards cannot start sketches with the existing HSE bypass configuration. Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> Signed-off-by: Ralf Doering <ralf@rdoering.net>
1 parent 6a2cdda commit 86a68db

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎variants/STM32F0xx/F030R8T/variant_NUCLEO_F030R8.cpp‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ WEAK void SystemClock_Config(void)
113113
{
114114
RCC_OscInitTypeDef RCC_OscInitStruct = {};
115115
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
116+
HAL_StatusTypeDef ret = HAL_OK;
116117
/*
117118
* Initializes the RCC Oscillators according to the specified parameters
118119
* in the RCC_OscInitTypeDef structure.
@@ -123,7 +124,19 @@ WEAK void SystemClock_Config(void)
123124
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
124125
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
125126
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
126-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
127+
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
128+
if (ret == HAL_TIMEOUT) {
129+
/* Try HSI when no external clock is connected, e.g. MB1136 C-01. */
130+
/* HSI 8 MHz / 2 * 12 = 48 MHz. */
131+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
132+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
133+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
134+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
135+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
136+
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
137+
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
138+
}
139+
if (ret != HAL_OK) {
127140
Error_Handler();
128141
}
129142
/* Initializes the CPU, AHB and APB buses clocks */

0 commit comments

Comments
 (0)