Merge pull request #12099 from J91Olivier/stm32f4_baud_rate_calculation_fix

Implemented recommended fix from https://github.com/STMicroelectronic
pull/12132/head
Anna Bridge 2019-12-17 16:27:19 +00:00 committed by GitHub
commit 8b0a5c2e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 14 deletions

View File

@ -2432,6 +2432,7 @@ static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
static void UART_SetConfig(UART_HandleTypeDef *huart) static void UART_SetConfig(UART_HandleTypeDef *huart)
{ {
uint32_t tmpreg = 0x00U; uint32_t tmpreg = 0x00U;
uint32_t pclk;
/* Check the parameters */ /* Check the parameters */
assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate)); assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
@ -2484,39 +2485,58 @@ static void UART_SetConfig(UART_HandleTypeDef *huart)
if(huart->Init.OverSampling == UART_OVERSAMPLING_8) if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
{ {
/*-------------------------- USART BRR Configuration ---------------------*/ /*-------------------------- USART BRR Configuration ---------------------*/
#if defined(USART6) #if defined(USART6) && defined(UART9) && defined(UART10)
if((huart->Instance == USART1) || (huart->Instance == USART6)) 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); pclk = HAL_RCC_GetPCLK2Freq();
huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate);
}
#elif defined(USART6)
if ((huart->Instance == USART1) || (huart->Instance == USART6))
{
pclk = HAL_RCC_GetPCLK2Freq();
huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate);
} }
#else #else
if(huart->Instance == USART1) if (huart->Instance == USART1)
{ {
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate); pclk = HAL_RCC_GetPCLK2Freq();
} huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate);
}
#endif /* USART6 */ #endif /* USART6 */
else else
{ {
huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate); pclk = HAL_RCC_GetPCLK1Freq();
huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate);
} }
} }
else else
{ {
/*-------------------------- USART BRR Configuration ---------------------*/ /*-------------------------- USART BRR Configuration ---------------------*/
#if defined(USART6) #if defined(USART6) && defined(UART9) && defined(UART10)
if((huart->Instance == USART1) || (huart->Instance == USART6))
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); pclk = HAL_RCC_GetPCLK2Freq();
huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
}
#elif defined(USART6)
if ((huart->Instance == USART1) || (huart->Instance == USART6))
{
pclk = HAL_RCC_GetPCLK2Freq();
huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
} }
#else #else
if(huart->Instance == USART1) if (huart->Instance == USART1)
{ {
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate); pclk = HAL_RCC_GetPCLK2Freq();
} huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
}
#endif /* USART6 */ #endif /* USART6 */
else else
{ {
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate); pclk = HAL_RCC_GetPCLK1Freq();
huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
} }
} }
} }