Page 1 of 1

High Speed USB PHY

Posted: Wed Jul 10, 2019 4:29 pm
by griffitsr
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!

Re: High Speed USB PHY

Posted: Fri Sep 06, 2019 8:23 pm
by mosi
I second that post. ADC logging is one of the most useful features of micropython.

Re: High Speed USB PHY

Posted: Mon Sep 09, 2019 7:54 am
by pythoncoder
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.

Re: High Speed USB PHY

Posted: Mon Sep 09, 2019 1:31 pm
by Damien
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!

Re: High Speed USB PHY

Posted: Tue Sep 10, 2019 3:30 am
by Damien
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.