Skip to content

Commit 0d851b9

Browse files
chrismas9dpgeorge
authored andcommitted
F4_HAL/uart: Use APB2 clock when configuring UART9 and UART10 baudrate.
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.
1 parent 0b2579a commit 0d851b9

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,17 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
24862486
if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
24872487
{
24882488
/*-------------------------- USART BRR Configuration ---------------------*/
2489-
#if defined(USART6)
2489+
#if defined(UART10)
2490+
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
2491+
{
2492+
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
2493+
}
2494+
#elif defined(UART9)
2495+
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9))
2496+
{
2497+
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
2498+
}
2499+
#elif defined(USART6)
24902500
if((huart->Instance == USART1) || (huart->Instance == USART6))
24912501
{
24922502
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
@@ -2496,7 +2506,7 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
24962506
{
24972507
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
24982508
}
2499-
#endif /* USART6 */
2509+
#endif /* USART6 UART9 UART10 */
25002510
else
25012511
{
25022512
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate);
@@ -2505,7 +2515,17 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
25052515
else
25062516
{
25072517
/*-------------------------- USART BRR Configuration ---------------------*/
2508-
#if defined(USART6)
2518+
#if defined(UART10)
2519+
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
2520+
{
2521+
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
2522+
}
2523+
#elif defined(UART9)
2524+
if((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9))
2525+
{
2526+
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
2527+
}
2528+
#elif defined(USART6)
25092529
if((huart->Instance == USART1) || (huart->Instance == USART6))
25102530
{
25112531
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
@@ -2515,7 +2535,7 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
25152535
{
25162536
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
25172537
}
2518-
#endif /* USART6 */
2538+
#endif /* USART6 UART9 UART10 */
25192539
else
25202540
{
25212541
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate);

0 commit comments

Comments
 (0)