Change UART baudrate on the go STM32G4 (DMA)
Hi all,
I'm having problem implementing a function to change the baudrate during runtime. I've read all the other topics about it and tried the proposed solutions but couldn't get it to work, maybe I missed something.
I use DMA for the UART which might also change the way things have to be handled.
Here's my code, basically a copy of the MX_USART1_UART_Init function:
void MX_USART1_ChangeBaudRate(uint32_t baudrate)
{
while (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE) == SET)
{
// wait for UART to be idle
}
huart1.Init.BaudRate = baudrate;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
{
Error_Handler();
}
}
I've also tried calling DeInit / MspDeInit before the Init but without success too ( + few other things...). The init function seems to call the UART disable function as recommended before changing the settings.
Kind regards
