stm32:rcc: update _get_clock (uart/i2c) to handle all cases

Adds handling for missing cases.  While i2c only has 3 cases, uarts have
all 4, so make sure they're handled properly.
Removes duplicated/redundant definitions.
Adds doxygen wrappers, even if only for internal use.

Fixes: e41ac6ea71 stm32: added peripheral clock get helpers for all stm32
Signed-of-by: Karl Palsson <karlp@tweak.au>
This commit is contained in:
Karl Palsson
2023-01-13 02:06:34 +00:00
parent df654d7f28
commit 88e91c9a7c
11 changed files with 175 additions and 168 deletions

View File

@@ -385,36 +385,30 @@ Control</b>
/**@}*/
/* --- RCC_CFGR3 values ---------------------------------------------------- */
/** @defgroup rcc_cfgr3_uart_choices UART for clock source selecting
* @note This is only used internally.
* @{
*/
#define RCC_CFGR3_USART3SW_SHIFT 18
#define RCC_CFGR3_USART3SW (3 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART3SW_PCLK (0 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART3SW_SYSCLK (1 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART3SW_LSE (2 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART3SW_HSI (3 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART2SW_SHIFT 16
#define RCC_CFGR3_USART2SW (3 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART2SW_PCLK (0 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART2SW_SYSCLK (1 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART2SW_LSE (2 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART2SW_HSI (3 << RCC_CFGR3_USART2SW_SHIFT)
#define RCC_CFGR3_USART1SW_SHIFT 0
/**@}*/
/** @defgroup rcc_cfgr3_uart_clksel UART Clock source selections
* @{
*/
#define RCC_CFGR3_USARTxSW_PCLK 0x0
#define RCC_CFGR3_USARTxSW_SYSCLK 0x1
#define RCC_CFGR3_USARTxSW_LSE 0x2
#define RCC_CFGR3_USARTxSW_HSI 0x3
/**@}*/
#define RCC_CFGR3_USARTxSW_MASK 0x3
#define RCC_CFGR3_ADCSW (1 << 8)
#define RCC_CFGR3_USBSW (1 << 7)
#define RCC_CFGR3_CECSW (1 << 6)
#define RCC_CFGR3_I2C1SW (1 << 4)
#define RCC_CFGR3_USART1SW_SHIFT 0
#define RCC_CFGR3_USART1SW (3 << RCC_CFGR3_USART1SW_SHIFT)
#define RCC_CFGR3_USART1SW_PCLK (0 << RCC_CFGR3_USART1SW_SHIFT)
#define RCC_CFGR3_USART1SW_SYSCLK (1 << RCC_CFGR3_USART1SW_SHIFT)
#define RCC_CFGR3_USART1SW_LSE (2 << RCC_CFGR3_USART1SW_SHIFT)
#define RCC_CFGR3_USART1SW_HSI (3 << RCC_CFGR3_USART1SW_SHIFT)
#define RCC_CFGR3_USARTxSW_MASK 3
/* --- RCC_CFGR3 values ---------------------------------------------------- */
#define RCC_CR2_HSI48CAL_SHIFT 24
#define RCC_CR2_HSI48CAL (0xFF << RCC_CR2_HSI48CAL_SHIFT)
#define RCC_CR2_HSI48RDY (1 << 17)

View File

@@ -405,36 +405,25 @@
#define RCC_CFGR3_TIM1SW (1 << 8)
#define RCC_CFGR3_I2C2SW (1 << 5)
#define RCC_CFGR3_I2C1SW (1 << 4)
/* UART5SW: UART5 clock source selection */
/** @defgroup rcc_cfgr3_uart_choices UART for clock sour selecting
* @{
*/
#define RCC_CFGR3_UART5SW_SHIFT 22
#define RCC_CFGR3_UART5SW_PCLK 0x0
#define RCC_CFGR3_UART5SW_SYSCLK 0x1
#define RCC_CFGR3_UART5SW_LSE 0x2
#define RCC_CFGR3_UART5SW_HSI 0x3
/* UART4SW: UART4 clock source selection */
#define RCC_CFGR3_UART4SW_SHIFT 20
#define RCC_CFGR3_UART4SW_PCLK 0x0
#define RCC_CFGR3_UART4SW_SYSCLK 0x1
#define RCC_CFGR3_UART4SW_LSE 0x2
#define RCC_CFGR3_UART4SW_HSI 0x3
/* UART3SW: UART3 clock source selection */
#define RCC_CFGR3_UART3SW_SHIFT 18
#define RCC_CFGR3_UART3SW_PCLK 0x0
#define RCC_CFGR3_UART3SW_SYSCLK 0x1
#define RCC_CFGR3_UART3SW_LSE 0x2
#define RCC_CFGR3_UART3SW_HSI 0x3
/* UART2SW: UART2 clock source selection */
#define RCC_CFGR3_UART2SW_SHIFT 16
#define RCC_CFGR3_UART2SW_PCLK 0x0
#define RCC_CFGR3_UART2SW_SYSCLK 0x1
#define RCC_CFGR3_UART2SW_LSE 0x2
#define RCC_CFGR3_UART2SW_HSI 0x3
/* UART1SW: UART1 clock source selection */
#define RCC_CFGR3_UART1SW_SHIFT 0
#define RCC_CFGR3_UART1SW_PCLK 0x0
#define RCC_CFGR3_UART1SW_SYSCLK 0x1
#define RCC_CFGR3_UART1SW_LSE 0x2
#define RCC_CFGR3_UART1SW_HSI 0x3
/**@}*/
/** @defgroup rcc_cfgr3_uart_clksel UART Clock source selections
* @note This is only used internally.
* @{
*/
#define RCC_CFGR3_UARTxSW_PCLK 0x0
#define RCC_CFGR3_UARTxSW_SYSCLK 0x1
#define RCC_CFGR3_UARTxSW_LSE 0x2
#define RCC_CFGR3_UARTxSW_HSI 0x3
/**@}*/
/* Shared mask for UART clock source. */
#define RCC_CFGR3_UARTxSW_MASK 0x3

View File

@@ -622,33 +622,36 @@
#define RCC_DCKCFGR2_CECSEL (1<<26)
#define RCC_DCKCFGR2_LPTIM1SEL_MASK 0x3
#define RCC_DCKCFGR2_LPTIM1SEL_SHIFT 24
#define RCC_DCKCFGR2_I2C4SEL_MASK 0x3
#define RCC_DCKCFGR2_I2CxSEL_MASK 0x3
#define RCC_DCKCFGR2_I2C4SEL_SHIFT 22
#define RCC_DCKCFGR2_I2C3SEL_MASK 0x3
#define RCC_DCKCFGR2_I2C3SEL_SHIFT 20
#define RCC_DCKCFGR2_I2C2SEL_MASK 0x3
#define RCC_DCKCFGR2_I2C2SEL_SHIFT 18
#define RCC_DCKCFGR2_I2C1SEL_MASK 0x3
#define RCC_DCKCFGR2_I2C1SEL_SHIFT 16
#define RCC_DCKCFGR2_UART8SEL_MASK 0x3
#define RCC_DCKCFGR2_UARTxSEL_MASK 0x3
/** @defgroup rcc_dckcfgr2_uart_choices UART for clock source selecting
* @note This is only used internally.
* @{
*/
#define RCC_DCKCFGR2_UART8SEL_SHIFT 14
#define RCC_DCKCFGR2_UART7SEL_MASK 0x3
#define RCC_DCKCFGR2_UART7SEL_SHIFT 12
#define RCC_DCKCFGR2_USART6SEL_MASK 0x3
#define RCC_DCKCFGR2_USART6SEL_SHIFT 10
#define RCC_DCKCFGR2_UART5SEL_MASK 0x3
#define RCC_DCKCFGR2_UART5SEL_SHIFT 8
#define RCC_DCKCFGR2_UART4SEL_MASK 0x3
#define RCC_DCKCFGR2_UART4SEL_SHIFT 6
#define RCC_DCKCFGR2_UART3SEL_MASK 0x3
#define RCC_DCKCFGR2_UART3SEL_SHIFT 4
#define RCC_DCKCFGR2_UART2SEL_MASK 0x3
#define RCC_DCKCFGR2_UART2SEL_SHIFT 2
#define RCC_DCKCFGR2_UART1SEL_MASK 0x3
#define RCC_DCKCFGR2_UART1SEL_SHIFT 0
#define RCC_DCKCFGR2_UARTxSEL_PCLK 0
#define RCC_DCKCFGR2_UARTxSEL_SYSCLK 1
#define RCC_DCKCFGR2_UARTxSEL_HSI 2
/**@}*/
/** @defgroup rcc_dckcfgr2_uart_clksel UART Clock source selections
* @{
*/
#define RCC_DCKCFGR2_UARTxSEL_PCLK 0x0
#define RCC_DCKCFGR2_UARTxSEL_SYSCLK 0x1
#define RCC_DCKCFGR2_UARTxSEL_HSI 0x2
#define RCC_DCKCFGR2_UARTxSEL_LSE 0x3
/**@}*/
extern uint32_t rcc_ahb_frequency;

View File

@@ -537,23 +537,25 @@
#define RCC_CCIPR_I2S1SEL_I2S_CKIN 3
/**@}*/
#define RCC_CCIPR_I2C1SEL_MASK 0x3
#define RCC_CCIPR_I2CxSEL_MASK 0x3
#define RCC_CCIPR_I2C1SEL_SHIFT 12
#define RCC_CCIPR_I2C2SEL_SHIFT 14
/** @defgroup rcc_ccipr_i2c1sel I2C1SEL I2C1 Clock source selection
@{*/
#define RCC_CCIPR_I2C1SEL_PCLK 0
#define RCC_CCIPR_I2C1SEL_SYSCLK 1
#define RCC_CCIPR_I2C1SEL_HSI16 2
#define RCC_CCIPR_I2CxSEL_PCLK 0
#define RCC_CCIPR_I2CxSEL_SYSCLK 1
#define RCC_CCIPR_I2CxSEL_HSI16 2
/**@}*/
#define RCC_CCIPR_LPUART1SEL_MASK 0x3
#define RCC_CCIPR_LPUARTxSEL_MASK 0x3
#define RCC_CCIPR_LPUART1SEL_SHIFT 10
/** @defgroup rcc_ccipr_lpuart1sel LPUART1SEL LPUART1 Clock source selection
#define RCC_CCIPR_LPUART2SEL_SHIFT 8
/** @defgroup rcc_ccipr_lpuartxsel LPUARTxSEL LPUART1 Clock source selection
@{*/
#define RCC_CCIPR_LPUART1SEL_PCLK 0
#define RCC_CCIPR_LPUART1SEL_SYSCLK 1
#define RCC_CCIPR_LPUART1SEL_HSI16 2
#define RCC_CCIPR_LPUART1SEL_LSE 3
#define RCC_CCIPR_LPUARTxSEL_PCLK 0
#define RCC_CCIPR_LPUARTxSEL_SYSCLK 1
#define RCC_CCIPR_LPUARTxSEL_HSI16 2
#define RCC_CCIPR_LPUARTxSEL_LSE 3
/**@}*/
#define RCC_CCIPR_CECSEL_MASK 0x1
@@ -564,25 +566,18 @@
#define RCC_CCIPR_CECSEL_LSE 1
/**@}*/
#define RCC_CCIPR_USART2SEL_MASK 0x3
#define RCC_CCIPR_USARTxSEL_MASK RCC_CCIPR_LPUARTxSEL_MASK
#define RCC_CCIPR_USART3SEL_SHIFT 4
#define RCC_CCIPR_USART2SEL_SHIFT 2
/** @defgroup rcc_ccipr_usart2sel USART2SEL USART2 Clock source selection
#define RCC_CCIPR_USART1SEL_SHIFT 0
/** @defgroup rcc_ccipr_usartxsel USARTxSEL USARTx Clock source selection
@{*/
#define RCC_CCIPR_USART2SEL_PCLK 0
#define RCC_CCIPR_USART2SEL_SYSCLK 1
#define RCC_CCIPR_USART2SEL_HSI16 2
#define RCC_CCIPR_USART2SEL_LSE 3
#define RCC_CCIPR_USARTxSEL_PCLK RCC_CCIPR_LPUARTxSEL_PCLK
#define RCC_CCIPR_USARTxSEL_SYSCLK RCC_CCIPR_LPUARTxSEL_SYSCLK
#define RCC_CCIPR_USARTxSEL_HSI16 RCC_CCIPR_LPUARTxSEL_HSI16
#define RCC_CCIPR_USARTxSEL_LSE RCC_CCIPR_LPUARTxSEL_LSE
/**@}*/
#define RCC_CCIPR_USART1SEL_MASK 0x3
#define RCC_CCIPR_USART1SEL_SHIFT 0
/** @defgroup rcc_ccipr_usart1sel USART1SEL USART1 Clock source selection
@{*/
#define RCC_CCIPR_USART1SEL_PCLK 0
#define RCC_CCIPR_USART1SEL_SYSCLK 1
#define RCC_CCIPR_USART1SEL_HSI16 2
#define RCC_CCIPR_USART1SEL_LSE 3
/**@}*/
/**@}*/
/** @defgroup rcc_bdcr BDCR Backup Domain Control Register

View File

@@ -443,38 +443,48 @@
#define RCC_CCIPR_LPTIM1SEL_SHIFT 18
#define RCC_CCIPR_LPTIM1SEL_MASK 0x3
#define RCC_CCIPR_I2C3SEL_APB 0
#define RCC_CCIPR_I2C3SEL_SYS 1
#define RCC_CCIPR_I2C3SEL_HSI16 2
/** @defgroup rcc_ccipr_i2c_clksel I2C Clock source selections
* @{
*/
#define RCC_CCIPR_I2CxSEL_PCLK 0
#define RCC_CCIPR_I2CxSEL_SYSCLK 1
#define RCC_CCIPR_I2CxSEL_HSI 2
/**@}*/
#define RCC_CCIPR_I2CxSEL_MASK 0x3
/** @defgroup rcc_ccipr_i2c_choices I2C for clock source selecting
* @note This is only used internally.
* @{
*/
#define RCC_CCIPR_I2C3SEL_SHIFT 16
#define RCC_CCIPR_I2C3SEL_MASK 0x3
#define RCC_CCIPR_I2C1SEL_APB 0
#define RCC_CCIPR_I2C1SEL_SYS 1
#define RCC_CCIPR_I2C1SEL_HSI16 2
#define RCC_CCIPR_I2C1SEL_SHIFT 12
#define RCC_CCIPR_I2C1SEL_MASK 0x3
/**@}*/
#define RCC_CCIPR_LPUART1SEL_APB 0
#define RCC_CCIPR_LPUART1SEL_SYS 1
#define RCC_CCIPR_LPUART1SEL_HSI16 2
#define RCC_CCIPR_LPUART1SEL_LSE 3
/** @defgroup rcc_ccipr_uart_clksel UART Clock source selections
* @{
*/
#define RCC_CCIPR_USARTxSEL_PCLK 0
#define RCC_CCIPR_USARTxSEL_SYSCLK 1
#define RCC_CCIPR_USARTxSEL_HSI 2
#define RCC_CCIPR_USARTxSEL_LSE 3
/**@}*/
#define RCC_CCIPR_LPUARTxSEL_PCLK RCC_CCIPR_USARTxSEL_PCLK
#define RCC_CCIPR_LPUARTxSEL_SYSCK RCC_CCIPR_USARTxSEL_SYSCLK
#define RCC_CCIPR_LPUARTxSEL_HSI RCC_CCIPR_USARTxSEL_HSI
#define RCC_CCIPR_LPUARTxSEL_LSE RCC_CCIPR_USARTxSEL_LSE
#define RCC_CCIPR_LPUARTxSEL_MASK 0x3
#define RCC_CCIPR_USARTxSEL_MASK RCC_CCIPR_LPUARTxSEL_MASK
/** @defgroup rcc_ccipr_uart_choices UART for clock source selecting
* @note This is only used internally.
* @{
*/
#define RCC_CCIPR_LPUART1SEL_SHIFT 10
#define RCC_CCIPR_LPUART1SEL_MASK 0x3
#define RCC_CCIPR_USART2SEL_APB 0
#define RCC_CCIPR_USART2SEL_SYS 1
#define RCC_CCIPR_USART2SEL_HSI16 2
#define RCC_CCIPR_USART2SEL_LSE 3
#define RCC_CCIPR_USART2SEL_SHIFT 2
#define RCC_CCIPR_USART2SEL_MASK 0x3
#define RCC_CCIPR_USART1SEL_APB 0
#define RCC_CCIPR_USART1SEL_SYS 1
#define RCC_CCIPR_USART1SEL_HSI16 2
#define RCC_CCIPR_USART1SEL_LSE 3
#define RCC_CCIPR_USART1SEL_SHIFT 0
#define RCC_CCIPR_USART1SEL_MASK 0x3
/**@}*/
/* --- RCC_CSRT - Control/Status register */