Skip to content

Commit 400f296

Browse files
kywwilson11acassis
authored andcommitted
Added PLLxFRACN definitions. Updated board.h to use them. Updated board.h to set SYSCLK to 250 MHz properly.
PLL1FRACN was being set improperly. stm32h5xxx_rcc.c does not shift the value provided by board.h. So it was being set wrong. The defintions in stm32h5xxx_rcc.h shift the FRACN value and are now used by board.h. Also, board.h was not setting PLL1P properly. PLL1P can not have odd divisors. Therefore a value of 0 was invalid. Set it to a value of 1 (divide by 2), then adjust PLL1N to 31 and PLL1FRAC1 to 2048 to actually set SYSCLK to 250MHz.
1 parent 4ba941e commit 400f296

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

arch/arm/src/stm32h5/hardware/stm32h5xxx_rcc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@
395395
#define RCC_PLL1DIVR_PLL1R_MASK (0x7f << RCC_PLL1DIVR_PLL1R_SHIFT)
396396
# define RCC_PLL1DIVR_PLL1R(n) ((n-1) << RCC_PLL1DIVR_PLL1R_SHIFT) /* m = 1..128 */
397397

398+
/* PLL1 fractional divider register */
399+
400+
#define RCC_PLL1FRACR_PLL1FRACN_SHIFT (3)
401+
#define RCC_PLL1FRACR_PLL1FRACN_MASK (0x1fff << RCC_PLL1FRACR_PLL1FRACN_SHIFT)
402+
#define RCC_PLL1FRACR_PLL1FRACN(n) (n << RCC_PLL1FRACR_PLL1FRACN_SHIFT) /* m = 0..8192 */
403+
398404
/* PLL2 dividers register */
399405

400406
#define RCC_PLL2DIVR_PLL2N_SHIFT (0) /* Bits 8-0: */
@@ -413,6 +419,12 @@
413419
#define RCC_PLL2DIVR_PLL2R_MASK (0x7f << RCC_PLL2DIVR_PLL2R_SHIFT)
414420
# define RCC_PLL2DIVR_PLL2R(n) ((n-1) << RCC_PLL2DIVR_PLL2R_SHIFT) /* m = 1..128 */
415421

422+
/* PLL2 fractional divider register */
423+
424+
#define RCC_PLL2FRACR_PLL2FRACN_SHIFT (3)
425+
#define RCC_PLL2FRACR_PLL2FRACN_MASK (0x1fff << RCC_PLL2FRACR_PLL2FRACN_SHIFT)
426+
#define RCC_PLL2FRACR_PLL2FRACN(n) (n << RCC_PLL2FRACR_PLL2FRACN_SHIFT) /* m = 0..8192 */
427+
416428
/* PLL3 dividers register */
417429

418430
#define RCC_PLL3DIVR_PLL3N_SHIFT (0) /* Bits 8-0: */
@@ -431,6 +443,12 @@
431443
#define RCC_PLL3DIVR_PLL3R_MASK (0x7f << RCC_PLL3DIVR_PLL3R_SHIFT)
432444
# define RCC_PLL3DIVR_PLL3R(n) ((n-1) << RCC_PLL3DIVR_PLL3R_SHIFT) /* m = 1..128 */
433445

446+
/* PLL3 fractional divider register */
447+
448+
#define RCC_PLL3FRACR_PLL3FRACN_SHIFT (3)
449+
#define RCC_PLL3FRACR_PLL3FRACN_MASK (0x1fff << RCC_PLL3FRACR_PLL3FRACN_SHIFT)
450+
#define RCC_PLL3FRACR_PLL3FRACN(n) (n << RCC_PLL3FRACR_PLL3FRACN_SHIFT) /* m = 0..8192 */
451+
434452
/* Clock interrupt enable register */
435453

436454
#define RCC_CIER_LSIRDYIE (1 << 0) /* Bit 0: LSI Ready Interrupt Enable */

boards/arm/stm32h5/nucleo-h563zi/include/board.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838

3939
/* The NUCLEO-H563ZI-Q supports both HSE and LSE crystals (X2 and X3).
4040
* However, as shipped, the X3 crystal is not populated. Therefore the
41-
* Nucleo-H563ZI-Q will need to run off the 16MHz HSI clock, or the
42-
* 32kHz-synced CSI. This configuration uses the CSI.
41+
* Nucleo-H563ZI-Q will need to run off the 32MHz HSI clock, or the
42+
* 4 MHz CSI clock. This configuration uses the HSI.
4343
*
4444
* System Clock source : PLL (CSI)
4545
* SYSCLK(Hz) : 250000000 Determined by PLL1 configuration
@@ -49,17 +49,17 @@
4949
* APB2 Prescaler : 1 (STM32_RCC_CFGR_PPRE2) (Max 250MHz)
5050
* CSI Frequency(Hz) : 4000000 (nominal)
5151
* PLL1M : 2 (STM32_PLL1CFGR_PLLM)
52-
* PLL1N : 125 (STM32_PLL1CFGR_PLLN)
53-
* PLL1P : 0 (STM32_PLL1CFGR_PLLP)
52+
* PLL1N : 31 (STM32_PLL1CFGR_PLLN)
53+
* PLL1P : 2 (STM32_PLL1CFGR_PLLP)
5454
* PLL1Q : 0 (STM32_PLL1CFGR_PLLQ)
5555
* PLL1R : 1 (STM32_PLL1CFGR_PLLR)
5656
* PLL2M : 2 (STM32_PLL2CFGR_PLLM)
57-
* PLL2N : 125 (STM32_PLL2CFGR_PLLN)
57+
* PLL2N : 15 (STM32_PLL2CFGR_PLLN)
5858
* PLL2P : 0 (STM32_PLL2CFGR_PLLP)
5959
* PLL2Q : 0 (STM32_PLL2CFGR_PLLQ)
6060
* PLL2R : 1 (STM32_PLL2CFGR_PLLR)
6161
* PLL3M : 2 (STM32_PLL3CFGR_PLLM)
62-
* PLL3N : 125 (STM32_PLL3CFGR_PLLN)
62+
* PLL3N : 15 (STM32_PLL3CFGR_PLLN)
6363
* PLL3P : 0 (STM32_PLL3CFGR_PLLP)
6464
* PLL3Q : 0 (STM32_PLL3CFGR_PLLQ)
6565
* PLL3R : 1 (STM32_PLL3CFGR_PLLR)
@@ -86,25 +86,27 @@
8686

8787
/* 'main' PLL1 config; we use this to generate our system clock */
8888

89-
/* Use 32 MHz HSI, set M to 2, N to 15, FRAC to 0x1400 (5120)
90-
* SYSCLK = (32000000 / 2) * (15 + (5120/8192)) = 250000000
89+
/* Use 32 MHz HSI, set M to 2, N to 31, FRAC to 0x800 (2048), PLL1P to 2
90+
* SYSCLK = ((HSI / PLL1M) * (PLL1N + (PLL1FRACN/8192))) / PLL1P
91+
* SYSCLK = ((32000000 / 2) * (31 + (2048/8192))) / 2 = 250000000
9192
*/
9293

9394
#define STM32_PLL1CFGR_PLL1FRACEN RCC_PLL1CFGR_PLL1FRACEN
9495
#define STM32_PLL1CFGR_PLL1VCOSEL 0
9596
#define STM32_PLL1CFGR_PLL1RGE RCC_PLL1CFGR_PLL1RGE_8_16M
9697

9798
#define STM32_PLL1CFGR_PLL1M RCC_PLL1CFGR_PLL1M(2)
98-
#define STM32_PLL1DIVR_PLL1N RCC_PLL1DIVR_PLL1N(15)
99+
#define STM32_PLL1DIVR_PLL1N RCC_PLL1DIVR_PLL1N(31)
99100

100-
#define STM32_PLL1DIVR_PLL1P RCC_PLL1DIVR_PLL1P(1)
101+
#define STM32_PLL1DIVR_PLL1P RCC_PLL1DIVR_PLL1P(2)
101102
#define STM32_PLL1CFGR_PLL1P_ENABLED 1
103+
#define STM32_PLL1P_FREQUENCY 250000000
102104
#define STM32_PLL1DIVR_PLL1Q 0
103105
#undef STM32_PLL1CFGR_PLL1Q_ENABLED
104106
#define STM32_PLL1DIVR_PLL1R 0
105107
#undef STM32_PLL1CFGR_PLL1R_ENABLED
106108

107-
#define STM32_PLL1FRACR_PLL1FRACN 5120ul
109+
#define STM32_PLL1FRACR_PLL1FRACN RCC_PLL1FRACR_PLL1FRACN(2048)
108110

109111
/* PLL2 config */
110112

@@ -122,7 +124,7 @@
122124
#define STM32_PLL2DIVR_PLL2R 0
123125
#undef STM32_PLL2CFGR_PLL2R_ENABLED
124126

125-
#define STM32_PLL2FRACR_PLL2FRACN 5120ul
127+
#define STM32_PLL2FRACR_PLL2FRACN RCC_PLL2FRACR_PLL2FRACN(5120)
126128

127129
/* PLL3 config */
128130

@@ -140,7 +142,7 @@
140142
#define STM32_PLL3DIVR_PLL3R 0
141143
#undef STM32_PLL3CFGR_PLL3R_ENABLED
142144

143-
#define STM32_PLL3FRACR_PLL3FRACN 5120ul
145+
#define STM32_PLL3FRACR_PLL3FRACN RCC_PLL3FRACR_PLL3FRACN(5120)
144146

145147
/* Enable CLK48; get it from HSI48 */
146148

0 commit comments

Comments
 (0)