Skip to content

Commit 04ef3c7

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 c34b6ce commit 04ef3c7

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
@@ -111,6 +111,7 @@ WEAK void SystemClock_Config(void)
111111
{
112112
RCC_OscInitTypeDef RCC_OscInitStruct = {};
113113
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
114+
HAL_StatusTypeDef ret = HAL_OK;
114115
/*
115116
* Initializes the RCC Oscillators according to the specified parameters
116117
* in the RCC_OscInitTypeDef structure.
@@ -121,7 +122,19 @@ WEAK void SystemClock_Config(void)
121122
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
122123
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
123124
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
124-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
125+
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
126+
if (ret == HAL_TIMEOUT) {
127+
/* Try HSI when no external clock is connected, e.g. MB1136 C-01. */
128+
/* HSI 8 MHz / 2 * 12 = 48 MHz. */
129+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
130+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
131+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
132+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
133+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
134+
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
135+
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
136+
}
137+
if (ret != HAL_OK) {
125138
Error_Handler();
126139
}
127140
/* Initializes the CPU, AHB and APB buses clocks */

0 commit comments

Comments
 (0)