2023-11-13 05:36 PM
Hi:
Now, I am using STM32C031. When debugging UART, it works normally when the optimization setting is set to -O2 or -O3, but fails to work when set to -O0 or -O1. Finally, it was found through checking the registers that the UART baud rate was not set effectively when optimization was set to -O0 or -O1, and the UART baud rate setting used an inline function. Can it be explained whether there is any correlation between optimization and inline, and why setting optimization would cause UART initialization to fail? The code as follow:
__STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t PrescalerValue,
uint32_t OverSampling,
uint32_t BaudRate)
{
uint32_t usartdiv;
uint32_t brrtemp;
if (PrescalerValue > LL_USART_PRESCALER_DIV256)
{
/* Do not overstep the size of USART_PRESCALER_TAB */
}
else if (BaudRate == 0U)
{
/* Can Not divide per 0 */
}
else if (OverSampling == LL_USART_OVERSAMPLING_8)
{
usartdiv = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, (uint8_t)PrescalerValue, 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, (uint8_t)PrescalerValue, BaudRate));
}
}
Solved! Go to Solution.
2023-11-14 02:03 AM
Hello @Jerly,
>> Whether there is any correlation between optimization and inline
yes, inlining of functions is an optimization and it really “works” only in optimizing compilation. If you don't use -O, no function is really inline.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-11-13 06:55 PM
Does what vs what?
2023-11-14 02:03 AM
Hello @Jerly,
>> Whether there is any correlation between optimization and inline
yes, inlining of functions is an optimization and it really “works” only in optimizing compilation. If you don't use -O, no function is really inline.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-11-14 08:17 AM
> Finally, it was found through checking the registers that the UART baud rate was not set effectively
Elaborate, please.
JW
2023-11-14 05:14 PM
Hi Sarra.S:
Thank you for replying. Can you explain the relationship between inlining of functions and optimization? In normal circumstances, how should it be configured and are there any relevant resources explaining this?