adafruit / circuitpython

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

IMXRT1062DVJ6A - busio.UART - REPL bits error in 8.0.0-beta-6 #7389

Closed Olzeke51 closed 1 year ago

Olzeke51 commented 1 year ago

CircuitPython version

adafruit-circuitpython-teensy41-en_US-8.0.0-beta.6.hex
AND
adafruit CircuitPython 8.0.0-beta.6-6-g785ebe1f4 on 2022-12-27
# 
I apologize for posting here, couldn't find a way to post in the 'beta' section.

Code/REPL

# Just a sstart....
import time
import microcontroller
import adafruit_ticks  # import time
import board
import busio
# from analogio import AnalogIn
import digitalio
# import displayio
# import adafruit_ili9341
# import terminalio  # Just a font
# from adafruit_display_text import label
# import simpleio
# import pwmio
# from adafruit_motor import motor
# from robot_inits_defs import *

UPDATE_INTERVAL = 3000      # using millisecs for time - 3 second pause
last_time_sent = 0

CPU_TEMP = microcontroller.cpu.temperature * (9 / 5) + 32
print("sending cpu temp ",
      (microcontroller.cpu.temperature * (9 / 5) + 32))

# Wait fodr the beginning of a message.
message_started = False
now = adafruit_ticks.ticks_ms()  # time.monotonic()
future = now + 15000    # reload

uart_bits = 8
# Use a timeout of zero so we don't delay while waiting for a message.
uart = busio.UART(board.TX1, board.RX1, baudrate=115200, bits=uart_bits, timeout=0)
# /*/*/ I have put bits=7  bits=8  , I have put bits=8 in front of baudrate= */*/*/

print(future)

/ ***** R E P L *********  !! also happens on this version !!
/ *****  https://downloads.circuitpython.org/bin/teensy41/en_US/adafruit-circuitpython-teensy41-en_US-8.0.0-beta.6.hex
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Hello World!
from Teensy??
sending cpu temp  112.81
Traceback (most recent call last):
  File "code.py", line 35, in <module>
ValueError: bits must be 7-8

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 8.0.0-beta.6-6-g785ebe1f4 on 2022-12-27; Teensy 4.1 with IMXRT1062DVJ6A
>>> 
IMXRT1062DVJ6A
>>> import busio
>>> dir(busio.UART)
['__class__', '__enter__', '__exit__', '__name__', 'read', 'readinto', 'readline', 'write', '__bases__', '__del__', '__dict__', 'Parity', 'baudrate', 'deinit', 'in_waiting', 'reset_input_buffer', 'timeout']
>>>

Behavior

Traceback (most recent call last):
  File "code.py", line 35, in <module>
ValueError: bits must be 7-8
REPL - via MU Editor
IMXRT1062DVJ6A
>>> import busio
>>> dir(busio.UART)
['__class__', '__enter__', '__exit__', '__name__', 'read', 'readinto', 'readline', 'write', '__bases__', '__del__', '__dict__', 'Parity', 'baudrate', 'deinit', 'in_waiting', 'reset_input_buffer', 'timeout']
>>> 
!!!!!! notice - no 'bits' def
#
uart_bits=8
uart = busio.UART(board.TX1, board.RX1, baudrate=115200, bits=uart_bits, timeout=0)
# /*/*/ I have put bits=7  bits=8  , I have put bits=8 in front of baudrate= */*/*/
I tried 4 different 'bits=' options

Description

Teensy 4.1 board Version 7.3.3 works okay without the need for 'bits' never had any reference to it.; never specified it. # this is for serial1 default pin assignments on 0 and 1

Additional information

No response

RetiredWizard commented 1 year ago

I'm not sure this is the correct fix but I changed line 116 of circuitpython/ports/mimxrt10xx/common-hal/busio/UART.c

from: self->character_bits = (uint8_t)mp_arg_validate_int_range(self->character_bits, 7, 8, MP_QSTR_bits); to: self->character_bits = (uint8_t)mp_arg_validate_int_range(bits, 7, 8, MP_QSTR_bits);

and the error no longer occurs.