Hang when reading from UART and writing to filesystem on RPI Pico
When reading from UART and trying to write the read line to a file the board has a hard hang. I've confirmed the following code causes the issue on both an RPI Pico and a Pimorini Pico Lipo. The hang occurs anywhere from the first iteration of the loop, most often early, but can run to 10 or 20.
*Note: I'm not sure if this is the same issue as (https://github.com/micropython/micropython/issues/7204) but thought I'd raise anyway.
I've run the same code on an ESP-32 board (Firebeetle v4) with no issue. The UART is read and line written to file with no issues.
Sample code that draws the error (apologies I'm not the best coder so apologies for the quality of the code):
import os
import machine
#print sys info
print(os.uname())
f_debug = open('debug_test116.log', 'a')
f_debug.write('=======STARTED =======\n')
f_debug.flush()
#print uart info
uart = machine.UART(1, baudrate=9600, txbuf=1024, rxbuf=1024, timeout=1000, timeout_char=4 )
print(uart)
i = 0
while i < 1000:
line = uart.readline()
f_debug.write(str(line))
f_debug.flush()
print(line)
i = i + 1
print()
print("- bye -")
UART.init() not working correctly on Raspberry Pi Pico W
Using UART.init() on RPi Pico W breaks UART functionality for the respective port when changing pins. (Even when changing back to the original pins.)
>>> from machine import UART, Pin
>>> uart = UART(0, baudrate=2400, tx=Pin(0), rx=Pin(1))
>>> uart.readline()
b'\x00Data on Pin 1\r\n'
>>> uart.readline()
b'\x00Data on Pin 1\r\n'
>>> uart.init(baudrate=2400, tx=Pin(12), rx=Pin(13))
>>> uart.readline()
>>> uart.readline()
>>> uart.init(baudrate=2400, tx=Pin(0), rx=Pin(1))
>>> uart.readline()
>>> uart.readline()
>>> uart2 = UART(1, baudrate=2400, tx=Pin(4), rx=Pin(5))
>>> uart2.readline()
b'\x00Data on Pin 5\r\n'
I would expect that I can change the pins on the fly (as per the note in the documentation of UART init: https://docs.micropython.org/en/latest/library/machine.UART.html#machine.UART.init).
External wiring is between RPi Pico W and Arduino Nano with the following wires:
RPi Pico W | Arduino Nano
------------+----------------------------
1 (GP0) | (19) A00 (configured as RX)
2 (GP1) | (22) A03 (configured as TX)
16 (GP12) | (20) A01 (configured as RX)
17 (GP13) | (23) A04 (configured as TX)
21 (GP16) | (21) A02 (configured as RX)
22 (GP17) | (24) A05 (configured as TX)
11 (GP8) | (19) A00 (configured as RX)
12 (GP9) | (22) A03 (configured as TX)
18 (GND) | (29) GROUND
(UART1, first ports, deliberately connected to the same ports on the Nano as UART0, second ports.)
firmware file: RPI_PICO_W-20231005-v1.21.0.uf2
version information: MicroPython v1.21.0 on 2023-10-06; Raspberry Pi Pico W with RP2040