NUCLEO-L476RG (STM32L476RG), NUCLEO_G0B1RE (STM32G0B1RE) - LPUART1 initialization not working
Port, board and/or hardware
port-stm32 - NUCLEO-L476RG with STM32L476RG
MicroPython version
MicroPython v1.23.0 on 2024-06-02; NUCLEO-L476RG with STM32L476RG
Reproduction
from machine import UART
uart = UART('LP1', baudrate=9600, bits=8, parity=None, stop=1)
or
from machine import UART
uart = UART(6, baudrate=9600, bits=8, parity=None, stop=1)
Expected behaviour
LPUART should initialize without errors
Observed behaviour
ValueError: set baudrate 0 is not within 5% of desired value
Additional Information
Similar issue https://github.com/micropython/micropython/issues/7466
Code of Conduct
Yes, I agree
ports/stm32/boards/NUCLEO_L476RG/mpconfigboard: expose 5 remaining UA…
STM32L476RG mcu of NUCLEO_L476RG board has 6 UART units in total (USART1, USART2, USART3, UART4, UART5 and LPUART1), but only UART2, which is connected to REPL, has been defined and available for Python code. As a result there is no possibility to use serial communication together with REPL.
This pull request resolves the issue with missing UART units in NUCLEO_L476RG board official MicroPython firmware, which affects others, for example:
- Can not initialize STM32L476 UART
- UART(4) doesn´t exist (STM32L476 Nucleo)
- NUCLEO-L476RG firmware has only UART2 defined
Tested on real NUCLEO_L476RG board:
MicroPython v1.14-120-g42cf77f48-dirty on 2021-03-20; NUCLEO-L476RG with STM32L476RG
Type "help()" for more information.
>>> print(pyb.UART(3, 9600).write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79'))
9
>>> print(pyb.UART(1, 9600).write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79'))
9
>>> print(pyb.UART(4, 9600).write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79'))
9
>>> print(pyb.UART(5, 9600).write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79'))
9
>>> print(pyb.UART('LP1',0).write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79'))
9
>>> print(pyb.UART(6, 0).write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79'))
9
>>>
Tested in real scenario using MH-Z19C CO2 sensor with UART interface:
MPY: sync filesystems
MPY: soft reboot
78.723 co2 = 500.00
79.735 co2 = 500.00
80.747 co2 = 500.00
81.759 co2 = 500.00
82.77101 co2 = 500.00
83.784 co2 = 500.00
84.796 co2 = 500.00
85.808 co2 = 500.00
86.82 co2 = 500.00
87.832 co2 = 500.00
88.844 co2 = 500.00
References:
Signed-off-by: Alexander Ziubin aziubin@googlemail.com