UART baudrate error in STM32L476

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
shaoziyang
Posts: 303
Joined: Sun Apr 17, 2016 1:55 pm

UART baudrate error in STM32L476

Post by shaoziyang » Wed May 25, 2016 3:12 pm

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.

User avatar
Roberthh
Posts: 1886
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: UART baudrate error in STM32L476

Post by Roberthh » Fri May 27, 2016 7:28 pm

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

User avatar
badi
Posts: 51
Joined: Mon Aug 10, 2015 2:18 pm
Location: Bern, Switzerland

Re: UART baudrate error in STM32L476

Post by badi » Sun May 29, 2016 4:40 pm

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.
badi

User avatar
badi
Posts: 51
Joined: Mon Aug 10, 2015 2:18 pm
Location: Bern, Switzerland

Re: UART baudrate error in STM32L476

Post by badi » Fri Jun 03, 2016 12:24 pm

badi

Post Reply