From d9e534f6f274d0d8b02a6258a55d6178517bd5fa Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Wed, 6 May 2020 14:25:46 +0200 Subject: [PATCH 1/2] stm32l476disco: fix uninitialized filed usage Field PLLState was not initialized in RCC_OscInitStruct.PLL in function SystemClock_Config(). Value is used in HAL_RCC_OscConfig() regardless of oscillator. In lucky case value would be 0 RCC_PLL_NONE and nothing would happen. If value was incorrect following line would end up in assert: assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState)); If value was valid but no RCC_PLL_NONE pll could be configured with some other random values. Setting PLLState to RCC_PLL_NONE eliminates potential problem. --- hw/bsp/stm32l476disco/stm32l476disco.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/bsp/stm32l476disco/stm32l476disco.c b/hw/bsp/stm32l476disco/stm32l476disco.c index 2d4a4e3de..3ecfc90a6 100644 --- a/hw/bsp/stm32l476disco/stm32l476disco.c +++ b/hw/bsp/stm32l476disco/stm32l476disco.c @@ -86,9 +86,10 @@ static void SystemClock_Config(void) RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; - /* Enable the LSE Oscilator */ + /* Enable the LSE Oscillator */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.LSEState = RCC_LSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct); /* Enable the CSS interrupt in case LSE signal is corrupted or not present */ From 615369a6eb28c9203d33549c8b944d35539de1b9 Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Wed, 6 May 2020 14:34:40 +0200 Subject: [PATCH 2/2] stm32l476disco: Fix system clock setup Code suggested that PLL with MSI is used resulting in 80MHz clock. When in fact PLL was not configured and system clock was left at MSI 48MHz. This happens because PLL configuration requires that SysTick interrupt has interrupt priority level configured correctly. As it seems ST code intentionally setups variable uwTickPrio to invalid value and later when it is not setup by user code configuration of oscillator will fail before PLL is configured. This simple changes systick priority to some valid value that allows clock to use PLL. --- hw/bsp/stm32l476disco/stm32l476disco.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/bsp/stm32l476disco/stm32l476disco.c b/hw/bsp/stm32l476disco/stm32l476disco.c index 3ecfc90a6..b18846685 100644 --- a/hw/bsp/stm32l476disco/stm32l476disco.c +++ b/hw/bsp/stm32l476disco/stm32l476disco.c @@ -95,6 +95,10 @@ static void SystemClock_Config(void) /* Enable the CSS interrupt in case LSE signal is corrupted or not present */ HAL_RCCEx_DisableLSECSS(); + /* Set tick interrupt priority, default HAL value is intentionally invalid + and that prevents PLL initialization in HAL_RCC_OscConfig() */ + HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL); + /* Enable MSI Oscillator and activate PLL with MSI as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.MSIState = RCC_MSI_ON;