Page 1 of 1

UART baudrate error in STM32L476

Posted: Wed May 25, 2016 3:12 pm
by shaoziyang
When I set uart baudrate, it will prompt :

>>> uart=UART(2)
>>> uart.init(9600)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: set baudrate 2459173 is not within 5% of desired value

But baudrate is set correctly and uart works.

Re: UART baudrate error in STM32L476

Posted: Fri May 27, 2016 7:28 pm
by Roberthh
Looks like line 583 in stmhal/uart.c is the culprit. It has a special treatment for the L4 series, which seems not needed here.
I do not have the board, so I cannot check it.

Code: Select all

    #if defined(MCU_SERIES_L4)
    actual_baudrate = (actual_baudrate << 5) / (self->uart.Instance->BRR >> 3);
    #else
    actual_baudrate /= self->uart.Instance->BRR;
    #endif
Best Regards, Robert

Re: UART baudrate error in STM32L476

Posted: Sun May 29, 2016 4:40 pm
by badi
The baud rate calculation between L4 and F4 is different, See Reference Manual F4:Sec 30.3.4, P 971 (Rev 11, Oct 15) and L4 Sec 36.5.4 Page 1184 (Rev 1, May 15). During the port I by mistake took the definition for LPUART which is again different (L4 sec 37.4.4).

I will fix the calculation and do a PR.

Re: UART baudrate error in STM32L476

Posted: Fri Jun 03, 2016 12:24 pm
by badi