UART(4) doesn´t exist (STM32L476 Nucleo)

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
cyrano1960
Posts: 39
Joined: Fri Mar 29, 2019 7:08 pm

UART(4) doesn´t exist (STM32L476 Nucleo)

Post by cyrano1960 » Sun May 26, 2019 2:08 pm

Hello, I have another newbie answer. I have written a very simple program which only sends some messages via UART. The code is:

from pyb import UART
import utime

uart = UART(4, 9600)
counter = 0

while True:
for counter in range(10):
uart.write(str(counter))
utime.sleep_ms(100)

But after uploading and resetting I will get the message:

Traceback (most recent call last):

File "main.py", line 4, in <module>

ValueError: UART(4) doesn't exist

MicroPython v1.10-381-g4f4477872 on 2019-05-23; NUCLEO-L476RG with STM32L476RG

Type "help()" for more information.

I will get this message also using an other index for UART. Could you please help me?
Thanks in advanve!
Last edited by cyrano1960 on Sun May 26, 2019 3:43 pm, edited 1 time in total.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: UART(4) doesn´t exist (STM32L476 Nucleo)

Post by shaoziyang » Sun May 26, 2019 3:16 pm

Nucelo-L476 firmware has only define UART2 default.

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

You may add these lines (from PYBV10) to mpconfigboard.h and recompile the firmware.

Code: Select all

#define MICROPY_HW_UART1_NAME   "XB"
#define MICROPY_HW_UART1_TX     (pin_B6)
#define MICROPY_HW_UART1_RX     (pin_B7)
#define MICROPY_HW_UART2_TX     (pin_A2)
#define MICROPY_HW_UART2_RX     (pin_A3)
#define MICROPY_HW_UART2_RTS    (pin_A1)
#define MICROPY_HW_UART2_CTS    (pin_A0)
#define MICROPY_HW_UART3_NAME   "YB"
#define MICROPY_HW_UART3_TX     (pin_B10)
#define MICROPY_HW_UART3_RX     (pin_B11)
#define MICROPY_HW_UART3_RTS    (pin_B14)
#define MICROPY_HW_UART3_CTS    (pin_B13)
#define MICROPY_HW_UART4_NAME   "XA"
#define MICROPY_HW_UART4_TX     (pin_A0)
#define MICROPY_HW_UART4_RX     (pin_A1)
#define MICROPY_HW_UART6_NAME   "YA"
#define MICROPY_HW_UART6_TX     (pin_C6)
#define MICROPY_HW_UART6_RX     (pin_C7)

cyrano1960
Posts: 39
Joined: Fri Mar 29, 2019 7:08 pm

Re: UART(4) doesn´t exist (STM32L476 Nucleo)

Post by cyrano1960 » Sun May 26, 2019 3:49 pm

Thanks a lot for your fast response. Do you know the reason why only UART2 is defined? If I am right, UART2 is the serial port for the ST-Link VCOM port? So there is no UART I could use for applications.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: UART(4) doesn´t exist (STM32L476 Nucleo)

Post by shaoziyang » Mon May 27, 2019 1:19 am

It maybe there are too many Nucleo boards with different MCU. You may modify mpconfigboard.h to customize your firmware.

Post Reply