I am trying to set a USBFS (USB full speed) communication between Pi 4 and cypress PSoC 5 (https://media.digikey.com/pdf/Data%20Sh ... CY8C55.pdf). Reading the data from Psoc5 works fine, but if I try to send data from raspberrypi (or ubuntu from my laptop) the following timeout error comes (receiving end is the Psoc device):-
Traceback (most recent call last):
File "/home/aman/Downloads/attitude_est_usb.py", line 57, in <module>
epOut.write(packed) # send it
File "/home/aman/.pyenv/versions/3.10.4/lib/python3.10/site-packages/usb/core.py", line 408, in write
return self.device.write(self, data, timeout)
File "/home/aman/.pyenv/versions/3.10.4/lib/python3.10/site-packages/usb/core.py", line 989, in write
return fn(
File "/home/aman/.pyenv/versions/3.10.4/lib/python3.10/site-packages/usb/backend/libusb1.py", line 837, in bulk_write
return self.__write(self.lib.libusb_bulk_transfer,
File "/home/aman/.pyenv/versions/3.10.4/lib/python3.10/site-packages/usb/backend/libusb1.py", line 938, in __write
_check(retval)
File "/home/aman/.pyenv/versions/3.10.4/lib/python3.10/site-packages/usb/backend/libusb1.py", line 602, in _check
raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBTimeoutError: [Errno 110] Operation timed out
However the same code is working completely fine in windows in my same laptop (for both sending and receiving), which is-
import usb.core
import usb.util
# search for our device by product and vendor ID
dev = usb.core.find(idVendor=0x4B4, idProduct=0x8051)
print(dev)
#raise error if device is not found
if dev is None:
raise ValueError('Device not found')
for cfg in dev:
for intf in cfg:
if dev.is_kernel_driver_active(intf.bInterfaceNumber):
try:
dev.detach_kernel_driver(intf.bInterfaceNumber)
except usb.core.USBError as e:
sys.exit("Could not detatch kernel driver from interface({0}): {1}".format(intf.bInterfaceNumber, str(e)))
# set the active configuration (basically, start the device)
dev.set_configuration()
# get interface 0, alternate setting 0
intf = dev.get_active_configuration()[(0, 0)]
# find the first (and in this case only) OUT endpoint in our interface
epOut = usb.util.find_descriptor(
intf,
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
# find the first (and in this case only) IN endpoint in our interface
epIn = usb.util.find_descriptor(
intf,
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
# make sure our endpoints were found
assert epOut is not None
assert epIn is not None
packed = np.uint8(np.zeros(10))
while True:
epOut.write(packed) # send it
data_raw = epIn.read(40,5000) # timeout = 5s
Output of print(dev) comes as -
DEVICE ID 04b4:8051 on Bus 001 Address 007 =================
bLength : 0x12 (18 bytes)
bDescriptorType : 0x1 Device
bcdUSB : 0x200 USB 2.0
bDeviceClass : 0xff Vendor-specific
bDeviceSubClass : 0x0
bDeviceProtocol : 0x0
bMaxPacketSize0 : 0x8 (8 bytes)
idVendor : 0x04b4
idProduct : 0x8051
bcdDevice : 0x0 Device 0.0
iManufacturer : 0x1 cypress
iProduct : 0x2 PSoC5
iSerialNumber : 0x0
bNumConfigurations : 0x1
CONFIGURATION 1: 50 mA ===================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x20 (32 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x3 main
bmAttributes : 0xc0 Self Powered
bMaxPower : 0x19 (50 mA)
INTERFACE 0: Vendor Specific ===========================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x2
bInterfaceClass : 0xff Vendor Specific
bInterfaceSubClass : 0x0
bInterfaceProtocol : 0x0
iInterface : 0x3 main
ENDPOINT 0x81: Bulk IN ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0xa
ENDPOINT 0x2: Bulk OUT ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x2 OUT
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0xa
Code for the reciever's (PSoC) end is as follows:-
#include <project.h>
uint8 buffer[512], length;
int main()
{
CyGlobalIntEnable; // Enable interrupts
USB_Start(0, USB_5V_OPERATION); // Start the USB peripheral
while(!USB_GetConfiguration()); // Wait until USB is configured
USB_EnableOutEP(2); // Enable our output endpoint (EP2)
for(;;){
while(USB_GetEPState(2) == USB_OUT_BUFFER_EMPTY); // Wait until we have data
length = USB_GetEPCount(2); // Get the length of received data
USB_ReadOutEP(2, buffer, length); // Get the data
while(USB_GetEPState(1) != USB_IN_BUFFER_EMPTY); // Wait until our IN EP is empty
USB_LoadInEP(1, buffer, length); // Echo the data back into the buffer
}
}
Here all the functions starting with 'USB' are inbuilt functions. Endpoint 2 is OUT and 1 is IN.
I tried different versions of python and pyusb package as well but got no improvement. Also giving more timeout for writing doesn't help. I am new to usb communication so the error may be very trivial but I'm not able to figure out. I believe that there is some problem with libusb or pyusb (as both are being used) in linux.
I am following a documentation from mit for the same (codes are there towards the end of document) - http://web.mit.edu/6.115/www/document/u ... xample.pdf.
I found one previous post in stackoverflow, there it mentions something about EHCI and xCHI controllers, which i am not familar about, so i tried with raspberrypi 3, hoping that it is older and has only USB 2.0 (so may have EHCI controllers), but again it didn't work. Link for the post https://stackoverflow.com/questions/550 ... er-windows
I am stuck with this error, hence any kind of help will be deeply appreciated.