From 519b9d327b924a6999afc64e4919b3f6deed73d9 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 26 Sep 2020 16:29:16 +0200 Subject: [PATCH 1/4] Enable HSI48 and use it to clock the RNG. --- src/cmsis/src/st/system_stm32fxxx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmsis/src/st/system_stm32fxxx.c b/src/cmsis/src/st/system_stm32fxxx.c index f477e3c39..540fc46d5 100644 --- a/src/cmsis/src/st/system_stm32fxxx.c +++ b/src/cmsis/src/st/system_stm32fxxx.c @@ -222,7 +222,9 @@ void SystemClock_Config(void) #if defined(OMV_OSC_CSI_STATE) RCC_OscInitStruct.CSIState = OMV_OSC_CSI_STATE; #endif - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = OMV_OSC_PLL1M; @@ -274,7 +276,8 @@ void SystemClock_Config(void) |RCC_PERIPHCLK_SPI3|RCC_PERIPHCLK_SPI2 |RCC_PERIPHCLK_SDMMC|RCC_PERIPHCLK_I2C2 |RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB - |RCC_PERIPHCLK_QSPI|RCC_PERIPHCLK_FMC; + |RCC_PERIPHCLK_QSPI|RCC_PERIPHCLK_FMC + |RCC_PERIPHCLK_RNG; PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL; PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL; PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL; @@ -285,6 +288,7 @@ void SystemClock_Config(void) PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI; PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1; PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL2; + PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_HSI48; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { // Initialization Error From b07f62cc61695af9e059cf7b41c92dbfb4512b20 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 26 Sep 2020 16:43:49 +0200 Subject: [PATCH 2/4] Make USB clock source configurable for H7 boards. --- src/cmsis/src/st/system_stm32fxxx.c | 6 +++--- src/omv/boards/OPENMV4/omv_boardconfig.h | 5 +++-- src/omv/boards/OPENMV4P/omv_boardconfig.h | 5 +++-- src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h | 5 +++-- src/omv/boards/PORTENTA/omv_boardconfig.h | 5 +++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cmsis/src/st/system_stm32fxxx.c b/src/cmsis/src/st/system_stm32fxxx.c index 540fc46d5..0abb007ad 100644 --- a/src/cmsis/src/st/system_stm32fxxx.c +++ b/src/cmsis/src/st/system_stm32fxxx.c @@ -278,13 +278,13 @@ void SystemClock_Config(void) |RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB |RCC_PERIPHCLK_QSPI|RCC_PERIPHCLK_FMC |RCC_PERIPHCLK_RNG; - PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL; + PeriphClkInitStruct.UsbClockSelection = OMV_OSC_USB_CLKSOURCE; PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL; PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL; PeriphClkInitStruct.FmcClockSelection = RCC_FMCCLKSOURCE_PLL2; PeriphClkInitStruct.QspiClockSelection = RCC_QSPICLKSOURCE_PLL2; - PeriphClkInitStruct.AdcClockSelection = OMV_OSC_ADC_SOURCE; - PeriphClkInitStruct.Spi123ClockSelection = OMV_OSC_SPI123_SOURCE; + PeriphClkInitStruct.AdcClockSelection = OMV_OSC_ADC_CLKSOURCE; + PeriphClkInitStruct.Spi123ClockSelection = OMV_OSC_SPI123_CLKSOURCE; PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI; PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1; PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL2; diff --git a/src/omv/boards/OPENMV4/omv_boardconfig.h b/src/omv/boards/OPENMV4/omv_boardconfig.h index ef7419799..52454ef6b 100644 --- a/src/omv/boards/OPENMV4/omv_boardconfig.h +++ b/src/omv/boards/OPENMV4/omv_boardconfig.h @@ -106,8 +106,9 @@ #define OMV_OSC_PLL3FRAC (0) // Clock Sources -#define OMV_OSC_ADC_SOURCE RCC_ADCCLKSOURCE_PLL3 -#define OMV_OSC_SPI123_SOURCE RCC_SPI123CLKSOURCE_PLL3 +#define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_PLL +#define OMV_OSC_ADC_CLKSOURCE RCC_ADCCLKSOURCE_PLL3 +#define OMV_OSC_SPI123_CLKSOURCE RCC_SPI123CLKSOURCE_PLL3 // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) diff --git a/src/omv/boards/OPENMV4P/omv_boardconfig.h b/src/omv/boards/OPENMV4P/omv_boardconfig.h index 459a6ee2d..45ae3761f 100644 --- a/src/omv/boards/OPENMV4P/omv_boardconfig.h +++ b/src/omv/boards/OPENMV4P/omv_boardconfig.h @@ -110,8 +110,9 @@ #define OMV_OSC_PLL3FRAC (0) // Clock Sources -#define OMV_OSC_ADC_SOURCE RCC_ADCCLKSOURCE_PLL3 -#define OMV_OSC_SPI123_SOURCE RCC_SPI123CLKSOURCE_PLL3 +#define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_PLL +#define OMV_OSC_ADC_CLKSOURCE RCC_ADCCLKSOURCE_PLL3 +#define OMV_OSC_SPI123_CLKSOURCE RCC_SPI123CLKSOURCE_PLL3 // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) diff --git a/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h b/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h index a02d8847f..6a6cc31f0 100644 --- a/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h +++ b/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h @@ -80,8 +80,9 @@ #define OMV_CORE_VBAT "3.3" // Clock Sources -#define OMV_OSC_ADC_SOURCE RCC_ADCCLKSOURCE_PLL2 -#define OMV_OSC_SPI123_SOURCE RCC_SPI123CLKSOURCE_PLL2 +#define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_PLL +#define OMV_OSC_ADC_CLKSOURCE RCC_ADCCLKSOURCE_PLL2 +#define OMV_OSC_SPI123_CLKSOURCE RCC_SPI123CLKSOURCE_PLL2 //PLL1 48MHz for USB, SDMMC and FDCAN #define OMV_OSC_PLL1M (3) diff --git a/src/omv/boards/PORTENTA/omv_boardconfig.h b/src/omv/boards/PORTENTA/omv_boardconfig.h index 2f3fa9878..2c78bede3 100644 --- a/src/omv/boards/PORTENTA/omv_boardconfig.h +++ b/src/omv/boards/PORTENTA/omv_boardconfig.h @@ -107,8 +107,9 @@ #define OMV_OSC_PLL3FRAC (0) // Clock Sources -#define OMV_OSC_ADC_SOURCE RCC_ADCCLKSOURCE_PLL3 -#define OMV_OSC_SPI123_SOURCE RCC_SPI123CLKSOURCE_PLL3 +#define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_HSI48 +#define OMV_OSC_ADC_CLSOURCE RCC_ADCCLKSOURCE_PLL3 +#define OMV_OSC_SPI123_CLKSOURCE RCC_SPI123CLKSOURCE_PLL3 // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_BYPASS) From dc654507864e142a2777b56774514f535e3add78 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 26 Sep 2020 17:37:07 +0200 Subject: [PATCH 3/4] Fix OSC definitions and enable for all boards. --- src/cmsis/src/st/system_stm32fxxx.c | 8 ++++++-- src/omv/boards/OPENMV1/omv_boardconfig.h | 1 - src/omv/boards/OPENMV2/omv_boardconfig.h | 1 - src/omv/boards/OPENMV3/omv_boardconfig.h | 1 - src/omv/boards/OPENMV4/omv_boardconfig.h | 2 -- src/omv/boards/OPENMV4P/omv_boardconfig.h | 2 -- src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h | 2 -- src/omv/boards/PORTENTA/omv_boardconfig.h | 3 +-- 8 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/cmsis/src/st/system_stm32fxxx.c b/src/cmsis/src/st/system_stm32fxxx.c index 0abb007ad..062a8a5d5 100644 --- a/src/cmsis/src/st/system_stm32fxxx.c +++ b/src/cmsis/src/st/system_stm32fxxx.c @@ -215,16 +215,20 @@ void SystemClock_Config(void) /* Enable HSE Oscillator and activate PLL with HSE as source */ #if defined(OMV_OSC_HSE_STATE) RCC_OscInitStruct.HSEState = OMV_OSC_HSE_STATE; + RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_HSE; #endif #if defined(OMV_OSC_HSI_STATE) RCC_OscInitStruct.HSIState = OMV_OSC_HSI_STATE; + RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_HSI; #endif #if defined(OMV_OSC_CSI_STATE) RCC_OscInitStruct.CSIState = OMV_OSC_CSI_STATE; + RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_CSI; #endif - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + #if defined(OMV_OSC_HSI48_STATE) + RCC_OscInitStruct.HSI48State = OMV_OSC_HSI48_STATE; RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_HSI48; - RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + #endif RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = OMV_OSC_PLL1M; diff --git a/src/omv/boards/OPENMV1/omv_boardconfig.h b/src/omv/boards/OPENMV1/omv_boardconfig.h index f7b4388c4..4d1991cdc 100644 --- a/src/omv/boards/OPENMV1/omv_boardconfig.h +++ b/src/omv/boards/OPENMV1/omv_boardconfig.h @@ -38,7 +38,6 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_5) diff --git a/src/omv/boards/OPENMV2/omv_boardconfig.h b/src/omv/boards/OPENMV2/omv_boardconfig.h index 10dc48ca4..f272865eb 100644 --- a/src/omv/boards/OPENMV2/omv_boardconfig.h +++ b/src/omv/boards/OPENMV2/omv_boardconfig.h @@ -77,7 +77,6 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_7) diff --git a/src/omv/boards/OPENMV3/omv_boardconfig.h b/src/omv/boards/OPENMV3/omv_boardconfig.h index 272d74f71..b886cd553 100644 --- a/src/omv/boards/OPENMV3/omv_boardconfig.h +++ b/src/omv/boards/OPENMV3/omv_boardconfig.h @@ -78,7 +78,6 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_7) diff --git a/src/omv/boards/OPENMV4/omv_boardconfig.h b/src/omv/boards/OPENMV4/omv_boardconfig.h index 52454ef6b..60a561eed 100644 --- a/src/omv/boards/OPENMV4/omv_boardconfig.h +++ b/src/omv/boards/OPENMV4/omv_boardconfig.h @@ -112,8 +112,6 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) -#define OMV_OSC_CSI_STATE (RCC_CSI_OFF) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_2) diff --git a/src/omv/boards/OPENMV4P/omv_boardconfig.h b/src/omv/boards/OPENMV4P/omv_boardconfig.h index 45ae3761f..24922aa26 100644 --- a/src/omv/boards/OPENMV4P/omv_boardconfig.h +++ b/src/omv/boards/OPENMV4P/omv_boardconfig.h @@ -116,8 +116,6 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) -#define OMV_OSC_CSI_STATE (RCC_CSI_OFF) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_2) diff --git a/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h b/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h index 6a6cc31f0..047f1bda8 100644 --- a/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h +++ b/src/omv/boards/OPENMVPURETHERMAL/omv_boardconfig.h @@ -116,8 +116,6 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_ON) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) -#define OMV_OSC_CSI_STATE (RCC_CSI_OFF) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_2) diff --git a/src/omv/boards/PORTENTA/omv_boardconfig.h b/src/omv/boards/PORTENTA/omv_boardconfig.h index 2c78bede3..9df46794d 100644 --- a/src/omv/boards/PORTENTA/omv_boardconfig.h +++ b/src/omv/boards/PORTENTA/omv_boardconfig.h @@ -113,8 +113,7 @@ // HSE/HSI/CSI State #define OMV_OSC_HSE_STATE (RCC_HSE_BYPASS) -#define OMV_OSC_HSI_STATE (RCC_HSI_OFF) -#define OMV_OSC_CSI_STATE (RCC_CSI_OFF) +#define OMV_OSC_HSI48_STATE (RCC_HSI48_ON) // Flash Latency #define OMV_FLASH_LATENCY (FLASH_LATENCY_2) From 8509357d47dd0ad2a46477e0f1bf888359039d45 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 26 Sep 2020 17:46:19 +0200 Subject: [PATCH 4/4] Fix typo. --- src/omv/boards/PORTENTA/omv_boardconfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omv/boards/PORTENTA/omv_boardconfig.h b/src/omv/boards/PORTENTA/omv_boardconfig.h index 9df46794d..008552209 100644 --- a/src/omv/boards/PORTENTA/omv_boardconfig.h +++ b/src/omv/boards/PORTENTA/omv_boardconfig.h @@ -108,7 +108,7 @@ // Clock Sources #define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_HSI48 -#define OMV_OSC_ADC_CLSOURCE RCC_ADCCLKSOURCE_PLL3 +#define OMV_OSC_ADC_CLKSOURCE RCC_ADCCLKSOURCE_PLL3 #define OMV_OSC_SPI123_CLKSOURCE RCC_SPI123CLKSOURCE_PLL3 // HSE/HSI/CSI State