Skip to content

Commit

Permalink
F4_HAL/uart: Use APB2 clock when configuring UART9 and UART10 baudrate.
Browse files Browse the repository at this point in the history
UART9 and UART10 are on APB2, like UART1 and UART6.  Fixes problem with
wrong baud rate when APB1 and APB2 run at different clock rates.
  • Loading branch information
chrismas9 authored and dpgeorge committed Jul 3, 2019
1 parent 027aaab commit 668d7a9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,17 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
{
/*-------------------------- USART BRR Configuration ---------------------*/
#if defined(USART6)
#if defined(UART10)
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
{
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
}
#elif defined(UART9)
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9))
{
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
}
#elif defined(USART6)
if((huart->Instance == USART1) || (huart->Instance == USART6))
{
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
Expand All @@ -2496,7 +2506,7 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
{
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
}
#endif /* USART6 */
#endif /* USART6 UART9 UART10 */
else
{
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate);
Expand All @@ -2505,7 +2515,17 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
else
{
/*-------------------------- USART BRR Configuration ---------------------*/
#if defined(USART6)
#if defined(UART10)
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
{
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
}
#elif defined(UART9)
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9))
{
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
}
#elif defined(USART6)
if((huart->Instance == USART1) || (huart->Instance == USART6))
{
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
Expand All @@ -2515,7 +2535,7 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
{
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
}
#endif /* USART6 */
#endif /* USART6 UART9 UART10 */
else
{
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate);
Expand Down

0 comments on commit 668d7a9

Please sign in to comment.