Skip to content

Commit 1f17775

Browse files
committed
fix(h5): ADC/DAC clock config
Complement of #2506 Signed-off-by: Kazuki Ota <ota_droid@live.jp> Co-Authored-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 6e60087 commit 1f17775

File tree

4 files changed

+96
-13
lines changed

4 files changed

+96
-13
lines changed

variants/STM32H5xx/H503KBU/generic_clock.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ WEAK void SystemClock_Config(void)
2222
{
2323
RCC_OscInitTypeDef RCC_OscInitStruct = {};
2424
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
25+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
2526

2627
/** Configure the main internal regulator output voltage
2728
*/
@@ -32,7 +33,9 @@ WEAK void SystemClock_Config(void)
3233
/** Initializes the RCC Oscillators according to the specified parameters
3334
* in the RCC_OscInitTypeDef structure.
3435
*/
35-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_CSI;
36+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_LSI
37+
| RCC_OSCILLATORTYPE_CSI;
38+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
3639
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
3740
RCC_OscInitStruct.CSIState = RCC_CSI_ON;
3841
RCC_OscInitStruct.CSICalibrationValue = RCC_CSICALIBRATION_DEFAULT;
@@ -46,6 +49,7 @@ WEAK void SystemClock_Config(void)
4649
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_2;
4750
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
4851
RCC_OscInitStruct.PLL.PLLFRACN = 0;
52+
4953
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
5054
Error_Handler();
5155
}
@@ -64,6 +68,29 @@ WEAK void SystemClock_Config(void)
6468
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
6569
Error_Handler();
6670
}
71+
72+
/** Initializes the peripherals clock
73+
*/
74+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC | RCC_PERIPHCLK_LPUART1
75+
| RCC_PERIPHCLK_USB;
76+
PeriphClkInitStruct.PLL2.PLL2Source = RCC_PLL2_SOURCE_CSI;
77+
PeriphClkInitStruct.PLL2.PLL2M = 1;
78+
PeriphClkInitStruct.PLL2.PLL2N = 125;
79+
PeriphClkInitStruct.PLL2.PLL2P = 2;
80+
PeriphClkInitStruct.PLL2.PLL2Q = 15;
81+
PeriphClkInitStruct.PLL2.PLL2R = 4;
82+
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2_VCIRANGE_2;
83+
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2_VCORANGE_WIDE;
84+
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
85+
PeriphClkInitStruct.PLL2.PLL2ClockOut = RCC_PLL2_DIVQ | RCC_PLL2_DIVR;
86+
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2Q;
87+
PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_PLL2R;
88+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
89+
90+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
91+
Error_Handler();
92+
}
93+
6794
}
6895

6996
#endif /* ARDUINO_GENERIC_* */

variants/STM32H5xx/H503RBT/generic_clock.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ WEAK void SystemClock_Config(void)
3232
/* Initializes the RCC Oscillators according to the specified parameters
3333
* in the RCC_OscInitTypeDef structure.
3434
*/
35-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_CSI;
35+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_LSI
36+
| RCC_OSCILLATORTYPE_CSI;
37+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
3638
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
3739
RCC_OscInitStruct.CSIState = RCC_CSI_ON;
3840
RCC_OscInitStruct.CSICalibrationValue = RCC_CSICALIBRATION_DEFAULT;
@@ -63,9 +65,21 @@ WEAK void SystemClock_Config(void)
6365
}
6466

6567
/* Initializes the peripherals clock */
66-
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USB;
68+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC | RCC_PERIPHCLK_LPUART1
69+
| RCC_PERIPHCLK_USB;
70+
PeriphClkInitStruct.PLL2.PLL2Source = RCC_PLL2_SOURCE_CSI;
71+
PeriphClkInitStruct.PLL2.PLL2M = 1;
72+
PeriphClkInitStruct.PLL2.PLL2N = 125;
73+
PeriphClkInitStruct.PLL2.PLL2P = 2;
74+
PeriphClkInitStruct.PLL2.PLL2Q = 15;
75+
PeriphClkInitStruct.PLL2.PLL2R = 4;
76+
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2_VCIRANGE_2;
77+
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2_VCORANGE_WIDE;
78+
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
79+
PeriphClkInitStruct.PLL2.PLL2ClockOut = RCC_PLL2_DIVQ | RCC_PLL2_DIVR;
80+
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2Q;
81+
PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_PLL2R;
6782
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
68-
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_CSI;
6983
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
7084
Error_Handler();
7185
}

variants/STM32H5xx/H503RBT/variant_NUCLEO_H503RB.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,10 @@ WEAK void SystemClock_Config(void)
116116

117117
/* Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure */
118118
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE
119-
| RCC_OSCILLATORTYPE_CSI;
119+
| RCC_OSCILLATORTYPE_LSE;
120120
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
121+
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
121122
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
122-
RCC_OscInitStruct.CSIState = RCC_CSI_ON;
123-
RCC_OscInitStruct.CSICalibrationValue = RCC_CSICALIBRATION_DEFAULT;
124123
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
125124
RCC_OscInitStruct.PLL.PLLSource = RCC_PLL1_SOURCE_HSE;
126125
RCC_OscInitStruct.PLL.PLLM = 12;
@@ -131,7 +130,6 @@ WEAK void SystemClock_Config(void)
131130
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_1;
132131
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
133132
RCC_OscInitStruct.PLL.PLLFRACN = 0;
134-
135133
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
136134
Error_Handler();
137135
}
@@ -151,9 +149,21 @@ WEAK void SystemClock_Config(void)
151149
}
152150

153151
/* Initializes the peripherals clock */
154-
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USB;
152+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC | RCC_PERIPHCLK_LPUART1
153+
| RCC_PERIPHCLK_USB;
154+
PeriphClkInitStruct.PLL2.PLL2Source = RCC_PLL2_SOURCE_HSE;
155+
PeriphClkInitStruct.PLL2.PLL2M = 2;
156+
PeriphClkInitStruct.PLL2.PLL2N = 31;
157+
PeriphClkInitStruct.PLL2.PLL2P = 2;
158+
PeriphClkInitStruct.PLL2.PLL2Q = 12;
159+
PeriphClkInitStruct.PLL2.PLL2R = 3;
160+
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2_VCIRANGE_3;
161+
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2_VCORANGE_WIDE;
162+
PeriphClkInitStruct.PLL2.PLL2FRACN = 2048;
163+
PeriphClkInitStruct.PLL2.PLL2ClockOut = RCC_PLL2_DIVQ | RCC_PLL2_DIVR;
164+
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2Q;
165+
PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_PLL2R;
155166
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
156-
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_CSI;
157167

158168
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
159169
Error_Handler();
@@ -164,4 +174,4 @@ WEAK void SystemClock_Config(void)
164174
}
165175
#endif
166176

167-
#endif /* ARDUINO_NUCLEO_H503RB */
177+
#endif /* ARDUINO_NUCLEO_H503RB */

variants/STM32H5xx/H563R(G-I)T_H573RIT/generic_clock.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ WEAK void SystemClock_Config(void)
2323
{
2424
RCC_OscInitTypeDef RCC_OscInitStruct = {};
2525
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
26+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
2627

2728
/** Configure the main internal regulator output voltage
2829
*/
@@ -33,8 +34,8 @@ WEAK void SystemClock_Config(void)
3334
/** Initializes the RCC Oscillators according to the specified parameters
3435
* in the RCC_OscInitTypeDef structure.
3536
*/
36-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_CSI;
37-
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
37+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_CSI;
38+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
3839
RCC_OscInitStruct.CSIState = RCC_CSI_ON;
3940
RCC_OscInitStruct.CSICalibrationValue = RCC_CSICALIBRATION_DEFAULT;
4041
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@@ -65,6 +66,37 @@ WEAK void SystemClock_Config(void)
6566
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
6667
Error_Handler();
6768
}
69+
70+
/** Initializes the peripherals clock
71+
*/
72+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC | RCC_PERIPHCLK_LPUART1
73+
| RCC_PERIPHCLK_USB;
74+
PeriphClkInitStruct.PLL2.PLL2Source = RCC_PLL2_SOURCE_CSI;
75+
PeriphClkInitStruct.PLL2.PLL2M = 1;
76+
PeriphClkInitStruct.PLL2.PLL2N = 125;
77+
PeriphClkInitStruct.PLL2.PLL2P = 2;
78+
PeriphClkInitStruct.PLL2.PLL2Q = 15;
79+
PeriphClkInitStruct.PLL2.PLL2R = 4;
80+
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2_VCIRANGE_2;
81+
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2_VCORANGE_WIDE;
82+
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
83+
PeriphClkInitStruct.PLL2.PLL2ClockOut = RCC_PLL2_DIVQ | RCC_PLL2_DIVR;
84+
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PLL2Q;
85+
PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_PLL2R;
86+
PeriphClkInitStruct.PLL3.PLL3Source = RCC_PLL3_SOURCE_CSI;
87+
PeriphClkInitStruct.PLL3.PLL3M = 1;
88+
PeriphClkInitStruct.PLL3.PLL3N = 48;
89+
PeriphClkInitStruct.PLL3.PLL3P = 2;
90+
PeriphClkInitStruct.PLL3.PLL3Q = 4;
91+
PeriphClkInitStruct.PLL3.PLL3R = 2;
92+
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3_VCIRANGE_0;
93+
PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3_VCORANGE_MEDIUM;
94+
PeriphClkInitStruct.PLL3.PLL3FRACN = 0.0;
95+
PeriphClkInitStruct.PLL3.PLL3ClockOut = RCC_PLL3_DIVQ;
96+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3Q;
97+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
98+
Error_Handler();
99+
}
68100
}
69101

70102
#endif /* ARDUINO_GENERIC_* */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy