# How to query APB1 clock frequency?

I'm trying to query the current value of the APB1 clock frequency to input into a USART configuration. Ideally, I could just query whatever the USART2 clock source is on an STM32F302xx, in case I move to another USART instance that is backed by say, the system clock.

I know what the value is from doing the math, but I want it to be parametrized in case I change clock settings. What is available in the HAL to call to replace my 36MHz value below?

LL_USART_SetBaudRate(USARTx_INSTANCE, 36000000, LL_USART_OVERSAMPLING_16, 115200);


I don't see any way to inspect what has been set by another part of the sytem, only:

HAL_Driver/Inc/stm32f3xx_hal_rcc.h
811:#define __HAL_RCC_USART2_CLK_ENABLE()   do { \
850:#define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
953:#define __HAL_RCC_USART2_IS_CLK_ENABLED()  ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != RESET)
962:#define __HAL_RCC_USART2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == RESET)
1024:#define __HAL_RCC_USART2_FORCE_RESET()   (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
1034:#define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
1337:#define __HAL_RCC_USART2_CONFIG(__USART2CLKSOURCE__) \

• You could just access the register directly without the HAL call. – DKNguyen May 3 at 1:59
• @Toor: That doesn't help, you still need to know what baud rate divider to write to the register. – Ben Voigt May 3 at 3:45