adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.04k stars 1.19k forks source link

Print read value from UART in a loop leads to crash bug #5477

Closed python36 closed 2 years ago

python36 commented 2 years ago

CircuitPython version

Adafruit CircuitPython 7.0.0 on 2021-09-20; Teensy 4.1 with IMXRT1062DVJ6A
Board ID:teensy41

Code/REPL

import busio
import board

ser = busio.UART(board.D20, board.D21, baudrate=115200)

for i in range(20):
  print(ser.read(1))

Behavior


Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
b'%'
b'\xbe'
b'\x1f'
Traceback (most recent call last):
  File "code.py", line 7, in <module>
NameError: name 'ser' is not defined

Code done running.```

### Description

Print read value from UART in a loop leads to crash bug or re-initializating of the board.

### Additional information

_No response_
DavePutz commented 2 years ago

I was able to reproduce this using an imxrt1010_evk. It appears that there is a buffer overrun when receiving more (or faster?) bytes on the UART than specified in the ser.read(). Symptoms vary depending on what gets stepped on. A workaround would be to increase the size in ser.read(); I'm looking at what is needed for a real fix.

tannewt commented 2 years ago

Fixed by #5541