High Speed USB PHY

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
griffitsr
Posts: 5
Joined: Wed Jul 10, 2019 3:50 pm

High Speed USB PHY

Post by griffitsr » Wed Jul 10, 2019 4:29 pm

Hello all,

I am currently programming a Pyboard D SF3W for MHz ADC datalogging. I am writing data continuously to the PC over the USB serial connection, receiving it using Pyserial and writing to a numpy array on the PC, the code I am using for this operation is below.

1) main.py code:

Code: Select all

*imports

usb = USB_VCP()
adc = ADC(Pin('X12'))
reads = 1000
buf = array("H",[0]*1000)
t = pyb.Timer(1,freq=1000000)

for term in range(reads):
    adc.read_timed(buf,t)
    usb.write(buf)
2) receiving.py code:

Code: Select all

*imports

reads = 1000
data = numpy.zeros((reads,1000),dtype='uint16')
ser = serial.Serial('COM7', 115200,timeout=0.5)
read = bytearray(2000)

for x in range(reads):
    ser.readinto(read)
    data[x,:] = numpy.frombuffer(read,dtype='uint16')
The issue I am facing is that this operation takes 2.2 seconds to write/receive 1 second of data (time writing to the numpy array is negligible). It seems that the USB transfer rate ~7Mb/s, which appears typical of the USB FS connection from checking previous forum posts.

I have installed the pybcdc.inf drivers that come with the board and have included the

pyb.usb_mode('VCP+MSC', port=1)

line in boot.py. However switching between port = 0/1 makes no difference to the transfer rate. The USB port I am using on the PC is USB 3.0 l, version of MicroPython is v1.10-445-ga9b1d3ca3, baudrate is 115200 and hardware flow control is enabled on windows COM port properties.

Is there something I am missing to be able to use the HS USB PHY that comes with the board or is it the method of transfer which could be improved, what speeds should be achievable with HS enabled/optimised?

Thanks!

mosi
Posts: 26
Joined: Tue Oct 07, 2014 12:07 am

Re: High Speed USB PHY

Post by mosi » Fri Sep 06, 2019 8:23 pm

I second that post. ADC logging is one of the most useful features of micropython.

User avatar
pythoncoder
Posts: 3708
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: High Speed USB PHY

Post by pythoncoder » Mon Sep 09, 2019 7:54 am

This strikes me as an important issue as it's a key selling point of the SF3W. If there is no response from @Damien or @jimmo it might be worth raising on GitHub.
Peter Hinch

Damien
Site Admin
Posts: 623
Joined: Mon Dec 09, 2013 5:02 pm

Re: High Speed USB PHY

Post by Damien » Mon Sep 09, 2019 1:31 pm

To enable high-speed USB you need to pass "high_speed=True" when setting the USB mode, eg

Code: Select all

pyb.usb_mode('VCP+MSC', high_speed=True)
This definitely needs to be added to the documentation!

Damien
Site Admin
Posts: 623
Joined: Mon Dec 09, 2013 5:02 pm

Re: High Speed USB PHY

Post by Damien » Tue Sep 10, 2019 3:30 am

Docs for pyb.usb_mode() have now been updated.

Regarding fast data transmission over USB: there has been some (not publicly available) work done to use MSC to communicate between a board and a PC, by essentially memory mapping an MSC block on both the PC and pyboard and then writing/reading the block to communicate. Due to caching issues it's not easy to do this on the PC side but it is possible and can give very fast and robust communication.

Post Reply