2021-12-22 09:07 PM
I'm using STM32 cube IDE for STM32F030CC uC, in this the baud rate of the USART is configured as part of the *.inc file, but my requirement is have to change the baud rate during the run time based on the user input, means, there are 6 USARTs sent in that USART 6 is planned to communicate with PC (this is constant baud rate) to get the user input mostly the baud rate to be set for another USARTs, and then another USARTs to be initialized with given baud from from the user, will it be possible to implement through STM32 cube IDE? If it is not possible in STM32 cube IDE means suggest me some other compilers to meet this requirement implementation.
2021-12-22 10:08 PM
Stop usart dma, deinit, MX_init with new baud rate, start dma.
For initialization purposes you can copy and paste original function code MX_USARTN_UART_Init(void)
and modify huartN.Init.BaudRate = variable_from_user_input field before initialization, other fields are filled already during start-up.
2021-12-22 10:49 PM
Isnt issue of any IDE, is your brain problem, need write or use LL code.
/**
* @brief Configure USART BRR register for achieving expected Baud Rate value.
* @note Compute and set USARTDIV value in BRR Register (full BRR content)
* according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
* @note Peripheral clock and Baud rate values provided as function parameters should be valid
* (Baud rate value != 0)
* @note In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
* @rmtoll BRR BRR LL_USART_SetBaudRate
* @param USARTx USART Instance
* @param PeriphClk Peripheral Clock
* @param OverSampling This parameter can be one of the following values:
* @arg @ref LL_USART_OVERSAMPLING_16
* @arg @ref LL_USART_OVERSAMPLING_8
* @param BaudRate Baud Rate
* @retval None
*/
__STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
uint32_t BaudRate)
{
uint32_t usartdiv;
uint32_t brrtemp;
if (OverSampling == LL_USART_OVERSAMPLING_8)
{
usartdiv = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
brrtemp = usartdiv & 0xFFF0U;
brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000FU) >> 1U);
USARTx->BRR = brrtemp;
}
else
{
USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
}
}
2021-12-24 10:24 AM
The information in this thread has saved me 4 hours of eating out brain and turning into a frightening granny. Thank you guys!
2021-12-25 02:43 PM
All configurations are done during runtime, therefore the answer depends: