Skip to content

Commit

Permalink
arch/stm32h7: add defines for USART clock selection
Browse files Browse the repository at this point in the history
This adds the necessary defines to set the USARTs' kernel clock source
selection.

This is required for a configuration where the bootloader (running
before NuttX) changes the USARTs' clock selection, so they need to be
restored on board init.

This is according to the reference manual RM0399 page 448.
  • Loading branch information
julianoes authored and davids5 committed Aug 6, 2024
1 parent d3b85f3 commit 5d74bc1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions arch/arm/src/stm32h7/hardware/stm32h7x3xx_rcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,21 @@

#define RCC_D2CCIP2R_USART234578SEL_SHIFT (0) /* Bits 0-2 */
# define RCC_D2CCIP2R_USART234578SEL_MASK (7 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
# define RCC_D2CCIP2R_USART234578SEL_RCC (0 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
# define RCC_D2CCIP2R_USART234578SEL_PLL2 (1 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
# define RCC_D2CCIP2R_USART234578SEL_PLL3 (2 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
# define RCC_D2CCIP2R_USART234578SEL_HSI (3 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
# define RCC_D2CCIP2R_USART234578SEL_CSI (4 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
# define RCC_D2CCIP2R_USART234578SEL_LSE (5 << RCC_D2CCIP2R_USART234578SEL_SHIFT)
#define RCC_D2CCIP2R_USART16SEL_SHIFT (3) /* Bits 3-5 */
# define RCC_D2CCIP2R_USART16SEL_MASK (7 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_MASK (7 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_RCC (0 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_PLL2 (1 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_PLL3 (2 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_HSI (3 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_CSI (4 << RCC_D2CCIP2R_USART16SEL_SHIFT)
# define RCC_D2CCIP2R_USART16SEL_LSE (5 << RCC_D2CCIP2R_USART16SEL_SHIFT)
/* Bits 6-7: Reserved */
#define RCC_D2CCIP2R_RNGSEL_SHIFT (8) /* Bits 8-9 */
# define RCC_D2CCIP2R_RNGSEL_MASK (3 << RCC_D2CCIP2R_RNGSEL_SHIFT)
Expand Down
18 changes: 18 additions & 0 deletions arch/arm/src/stm32h7/stm32h7x3xx_rcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,24 @@ void stm32_stdclockconfig(void)
putreg32(regval, STM32_RCC_D2CCIP2R);
#endif

/* Configure USART2, 3, 4, 5, 7, and 8 kernel clock source selection */

#if defined(STM32_RCC_D2CCIP2R_USART234578_SEL)
regval = getreg32(STM32_RCC_D2CCIP2R);
regval &= ~RCC_D2CCIP2R_USART234578SEL_MASK;
regval |= STM32_RCC_D2CCIP2R_USART234578_SEL;
putreg32(regval, STM32_RCC_D2CCIP2R);
#endif

/* Configure USART1 and 6 kernel clock source selection */

#if defined(STM32_RCC_D2CCIP2R_USART16_SEL)
regval = getreg32(STM32_RCC_D2CCIP2R);
regval &= ~RCC_D2CCIP2R_USART16SEL_MASK;
regval |= STM32_RCC_D2CCIP2R_USART16_SEL;
putreg32(regval, STM32_RCC_D2CCIP2R);
#endif

/* Configure ADC source clock */

#if defined(STM32_RCC_D3CCIPR_ADCSRC)
Expand Down
17 changes: 17 additions & 0 deletions arch/arm/src/stm32h7/stm32h7x7xx_rcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,23 @@ void stm32_stdclockconfig(void)
regval |= STM32_RCC_D2CCIP2R_USBSRC;
putreg32(regval, STM32_RCC_D2CCIP2R);
#endif
/* Configure USART2, 3, 4, 5, 7, and 8 kernel clock source selection */

#if defined(STM32_RCC_D2CCIP2R_USART234578_SEL)
regval = getreg32(STM32_RCC_D2CCIP2R);
regval &= ~RCC_D2CCIP2R_USART234578SEL_MASK;
regval |= STM32_RCC_D2CCIP2R_USART234578_SEL;
putreg32(regval, STM32_RCC_D2CCIP2R);
#endif

/* Configure USART1 and 6 kernel clock source selection */

#if defined(STM32_RCC_D2CCIP2R_USART16_SEL)
regval = getreg32(STM32_RCC_D2CCIP2R);
regval &= ~RCC_D2CCIP2R_USART16SEL_MASK;
regval |= STM32_RCC_D2CCIP2R_USART16_SEL;
putreg32(regval, STM32_RCC_D2CCIP2R);
#endif

/* Configure ADC source clock */

Expand Down

0 comments on commit 5d74bc1

Please sign in to comment.