sipeed / TangNano-9K-example

TangNano-9K-example project
227 stars 70 forks source link

BL702 UART firmware update on Tang Nano 9k #7

Closed charkster closed 2 years ago

charkster commented 2 years ago

I tried to drive 1Mbps uart to the BL702, but I see incorrect data. I can drive the same uart data to a board pin and look at with my logic analyzer (pulseview) and it looks fine. My Tang Nano 1k board uart works fine after I updated the CH552 firmware. Does the BL702 firmware need to be updated? Thank you.

charkster commented 2 years ago

Looks like it was a Linux driver issue on my setup. I switched to python Ftdi library and had no issues. The normal python serial library would not properly set the baudrate, but the Ftdi library did. I was able to see clean operation up to 3Mbps. Well done Sipeed.

vanbwodonk commented 1 month ago

Hi @charkster , i have problem open UART in Linux, how you solve this problem?

charkster commented 1 month ago

Hi @charkster , i have problem open UART in Linux, how you solve this problem?

@vanbwodonk, Sorry I could not reply earlier as I was on vacation out of the country. At first I switched from serial module to pyftdi.ftdi, but I switched back after I got familiar with bytearray data.

First try this (this is what I presently use):

import serial
port = serial.Serial(port='/dev/ttyUSB1', baudrate=3000000, bytesize=8, parity='N', stopbits=1, timeout=0.01)
port.reset_input_buffer()

bytesToRead = port.in_waiting  # generic read
rx_bytes = port.read(2)                # example of fixed read 
port.write(b'\x0c')                         # example of a write using bytearray data

Here is an example of generic serial usage: https://github.com/charkster/tang_nano-trigger_uart/blob/main/python/scarf_uart_slave.py

Use this if the generic serial module does not work:

from pyftdi.ftdi import Ftdi
import pyftdi.serialext

Ftdi.show_devices() # this will give the url for your device
ftdi_port        = pyftdi.serialext.serial_for_url('ftdi://ftdi:2232:39526AC8FA/2', baudrate=self.ftdi_baudrate, bytesize=8, parity='N', stopbits=1, timeout=0.01)

Here is an example of pyftdi usage: https://github.com/charkster/tang_nano-uart_block_ram/blob/main/python/scarf_uart_slave.py