From af155a47288686f9577a2eb642dfe204ab0b5ef7 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Thu, 10 Dec 2015 12:37:54 +0100 Subject: Abort startup on non-working RCC. Without this, failure to initialize the HSE will go unnoticed. --- src/led-test/src/stm_init.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/led-test/src/stm_init.c b/src/led-test/src/stm_init.c index 971f1ef..3df5d3e 100644 --- a/src/led-test/src/stm_init.c +++ b/src/led-test/src/stm_init.c @@ -85,7 +85,18 @@ void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLN = 360; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; - HAL_RCC_OscConfig(&RCC_OscInitStruct); + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + volatile uint32_t i; + + MX_GPIO_Init(); + + HAL_GPIO_WritePin(LED_PORT, LED_RED, GPIO_PIN_SET); + HAL_GPIO_WritePin(LED_PORT, LED_BLUE, GPIO_PIN_SET); + + while (1) { + i++; /* To not get optimized away */ + } + } HAL_PWREx_ActivateOverDrive(); @@ -94,7 +105,20 @@ void SystemClock_Config(void) RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { + volatile uint32_t j; + + MX_GPIO_Init(); + + HAL_GPIO_WritePin(LED_PORT, LED_RED, GPIO_PIN_SET); + if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) { + HAL_GPIO_WritePin(LED_PORT, LED_YELLOW, GPIO_PIN_SET); + } + + while (1) { + j++; /* To not get optimized away */ + } + } } /** Configure pins as -- cgit v1.2.3