NUCLEO-L476RG firmware has only UART2 defined

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
aziubin
Posts: 3
Joined: Sun Feb 21, 2021 6:46 pm

NUCLEO-L476RG firmware has only UART2 defined

Post by aziubin » Fri Feb 26, 2021 12:17 pm

Hello,
I have loaded MicroPython firmware to my NUCLEO-L476RG board, which has several UART units available. Unfortunately MicroPython firmware only defines single UART currently:

Code: Select all

// UART config
#define MICROPY_HW_UART2_TX     (pin_A2)
#define MICROPY_HW_UART2_RX     (pin_A3)

#define MICROPY_HW_UART_REPL        PYB_UART_2
#define MICROPY_HW_UART_REPL_BAUD   115200
(see in ports\stm32\boards\NUCLEO_L476RG\mpconfigboard.h). Would it be OK if I add remaining UART units to mpconfigboard.h and push to github.com/micropython/micropython, are such changes welcomed?
Please also let me know if any additional code changes are necessary for remaining UART units to be accessible from Python scripts.
Thanks!

Update: I built MicroPython 1.14 for NUCLEO-L476RG with corrected mpconfigboard.h, loaded to my board and verified that additional UART units work (using MH-Z19B CO2 sensor). Now UART 1, 2 and 3 are available for Python scripts. According to the datasheet, https://www.st.com/resource/en/datashee ... l476rg.pdf, stm32l476rg microcontroller also contains UART4 and UART5, but they are labeled differently, not "USART" as the first, the second and the third, but "UART". Not sure that they may work as well if I add them to mpconfigboard.h too.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: NUCLEO-L476RG firmware has only UART2 defined

Post by dhylands » Sat Feb 27, 2021 9:36 pm

The USARTs support synchronous and asynchronous modes, where the UARTs only support asynchronous mode. Asynchronous mode is the mode that you use for typical serial ports.

You should just keep using MICROPY_HW_UARTx_TX/RX regardless.

See: https://github.com/micropython/micropyt ... art.c#L236

aziubin
Posts: 3
Joined: Sun Feb 21, 2021 6:46 pm

Re: NUCLEO-L476RG firmware has only UART2 defined

Post by aziubin » Sun Mar 14, 2021 3:10 pm

Thank you, I defined all available UARTs as you suggested, which work wihtout errors in python script. Can you please also help me with LPUART configuration? I found existing LPUART configuration for NUCLEO-WB55 (https://github.com/micropython/micropyt ... oard.h#L25), but it is not clear how to use it in python script. pyb.LPUART() does not work even though I have neccessary definitions of TX and RX in my mpconfigboard.h. How to use LPUART in python script?

Post Reply