Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

USB superspeed peripherals Forum Discussions

amulya_nr
Level 2
Level 2
10 replies posted First like received 10 sign-ins

Hi, Thanks in advance. My hardware is FX3 USB super Speed device with vendorId 04b4 and product Id 00f2. My OS is Ubuntu 18.04. version.  I have installed Autoslave and Automaster code in hardware. I am running controlcenter code using Qt 5.15.2. which is provided by cypress. i am trying to do bulk transfer from from slave write to master read, but getting error  "LIBUSB_ERROR_IO". The code has complete root access.  Apart from this i also tried in my own simple code getting the same error. The below is the code and output. 

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <libusb-1.0/libusb.h>

#define EP_DATA_IN 0x81
#define EP_DATA_OUT 0x01
#define DEVICE_CONFIGURATION 0
#define MASTER 0x00f4
#define SLAVE 0x00f2

void writeButtonClicked()
{
int rc;
libusb_context *ctx = NULL;
libusb_device_handle *dev_handle;

QString writeData = "Slave writing !!!";
int actual = writeData.length();
unsigned char *sendData;

sendData = (unsigned char *)malloc(actual);
memcpy(sendData, writeData.toLocal8Bit(), actual);

rc = libusb_init(&ctx);
if(rc < 0) {
std::cout << "Init Error " << rc << std::endl;
}

libusb_set_debug(ctx, 6);


dev_handle = libusb_open_device_with_vid_pid(ctx, 0x04b4, SLAVE); // Give SLAVE or MASTER to perform write operation
if (!dev_handle) {
fprintf(stderr, "Error finding USB device\n");
}

if(libusb_kernel_driver_active(dev_handle, DEVICE_CONFIGURATION) == 1) {
std::cout << "Kernel Driver Active" << std::endl;
if(libusb_detach_kernel_driver(dev_handle, DEVICE_CONFIGURATION) == 0)
std::cout << "Kernel Driver Detached!" << std::endl;
}

rc = libusb_claim_interface(dev_handle, DEVICE_CONFIGURATION);
if(rc != 0) {
std::cout << "Cannot Claim Interface" << std::endl;
rc = libusb_set_interface_alt_setting(dev_handle, DEVICE_CONFIGURATION, 1);
if(rc!=0)
{
std::cout <<"Cannot configure alt setting "<<std::endl;
}
else
{
std::cout <<"configured alt setting "<<std::endl;
}
}

std::cout << "Data->" << sendData << "<-" << std::endl;
std::cout << "Writing Data..." << std::endl;

std::cout << "Trying endpoint " << EP_DATA_OUT << "." << std::endl;
rc = libusb_bulk_transfer(dev_handle, EP_DATA_OUT, sendData, sizeof(sendData), &actual, 1000);

if(rc == 0)
{
std::cout << "Writing Successful!" << std::endl;
}
else
{
std::cout << "Write Error! Rc: " << rc << " Actual transfered bytes: " << actual << "." << std::endl;
std::cout << "Error code means: " << libusb_error_name(rc) << std::endl;
}

rc = libusb_release_interface(dev_handle, 0);
if(rc!=0) {
std::cout << "Cannot Release Interface" << std::endl;
}

if (dev_handle)
libusb_close(dev_handle);

libusb_exit(ctx);
}

void readButtonClicked()
{
int rc;
libusb_context *ctx = NULL;
libusb_device_handle *dev_handle;

int actual = 0;
unsigned char *readData = new unsigned char[512];

rc = libusb_init(&ctx);
if(rc < 0) {
std::cout << "Init Error " << rc << std::endl;
}

libusb_set_debug(ctx, 6);

dev_handle = libusb_open_device_with_vid_pid(ctx, 0x04b4, MASTER); // Give SLAVE or MASTER to perform Read operation
if (!dev_handle) {
fprintf(stderr, "Error finding USB device\n");
}

if(libusb_kernel_driver_active(dev_handle, DEVICE_CONFIGURATION) == 1) {
std::cout << "Kernel Driver Active" << std::endl;
if(libusb_detach_kernel_driver(dev_handle, DEVICE_CONFIGURATION) == 0)
std::cout << "Kernel Driver Detached!" << std::endl;
}

rc = libusb_claim_interface(dev_handle, DEVICE_CONFIGURATION);
if(rc != 0) {
std::cout << "Cannot Claim Interface" << std::endl;
rc = libusb_set_interface_alt_setting(dev_handle, DEVICE_CONFIGURATION, 1);
if(rc!=0)
{
std::cout <<"Cannot configure alt setting "<<std::endl;
}
else
{
std::cout <<"configured alt setting "<<std::endl;
}
}

std::cout << "Trying endpoint " << EP_DATA_IN << "." << std::endl;
rc = libusb_bulk_transfer(dev_handle, EP_DATA_IN, readData, sizeof(readData), &actual, 1000);

if(rc >=0)
{
std::cout << "Read Success! Rc: " << libusb_error_name(rc) << " Actual transfered bytes: " << actual << "." << std::endl;
}
else
{
std::cout << "Read Error! Rc: " << rc << " Actual transfered bytes: " << actual << "." << std::endl;
std::cout << "Error code means: " << libusb_error_name(rc) << std::endl;
}

rc = libusb_release_interface(dev_handle, 0);
if(rc!=0) {
std::cout << "Cannot Release Interface" << std::endl;
}

if (dev_handle)
libusb_close(dev_handle);

libusb_exit(ctx);
}

//Output  Slave writing Master reading
libusb: debug [libusb_get_device_list]
libusb: debug [discovered_devs_append] need to increase capacity
libusb: debug [libusb_get_device_descriptor]
libusb: debug [libusb_get_device_descriptor]
libusb: debug [libusb_get_device_descriptor]
libusb: debug [libusb_open] open 2.16
libusb: debug [usbi_add_pollfd] add fd 26 events 4
libusb: debug [libusb_kernel_driver_active] interface 0
libusb: debug [libusb_claim_interface] interface 0
Data->Slave writing !!!<-
Writing Data...
Trying endpoint 1.
Writing Successful!
libusb: debug [libusb_alloc_transfer] transfer 0x563230a5b760
libusb: debug [libusb_submit_transfer] transfer 0x563230a5b760
libusb: debug [add_to_flying_list] arm timerfd for timeout in 1000ms (first in line)
libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 8
libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
libusb: debug [handle_events] poll fds modified, reallocating
libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
libusb: debug [handle_events] poll() returned 1
libusb: debug [reap_for_handle] urb type=3 status=0 transferred=8
libusb: debug [handle_bulk_completion] handling completion status 0 of bulk urb 1/1
libusb: debug [handle_bulk_completion] last URB in transfer --> complete!
libusb: debug [disarm_timerfd]
libusb: debug [usbi_handle_transfer_completion] transfer 0x563230a5b760 has callback 0x7f2537dfbb30
libusb: debug [sync_transfer_cb] actual_length=8
libusb: debug [libusb_free_transfer] transfer 0x563230a5b760
libusb: debug [libusb_release_interface] interface 0
libusb: debug [libusb_close]
libusb: debug [usbi_remove_pollfd] remove fd 26
libusb: debug [libusb_exit]
libusb: debug [libusb_exit] destroying default context
libusb: debug [libusb_get_device_list]
libusb: debug [discovered_devs_append] need to increase capacity
libusb: debug [libusb_get_device_descriptor]
libusb: debug [libusb_get_device_descriptor]
libusb: debug [libusb_open] open 2.17
libusb: debug [usbi_add_pollfd] add fd 26 events 4
libusb: debug [libusb_kernel_driver_active] interface 0
libusb: debug [libusb_claim_interface] interface 0
Trying endpoint 129.
libusb: debug [libusb_alloc_transfer] transfer 0x563230a35450
libusb: debug [libusb_submit_transfer] transfer 0x563230a35450
libusb: debug [add_to_flying_list] arm timerfd for timeout in 1000ms (first in line)
libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 8
libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
libusb: debug [handle_events] poll fds modified, reallocating
libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
Master Read Error! Rc: -1 Actual transfered bytes: 0.
Error code means: LIBUSB_ERROR_IO
libusb: debug [handle_events] poll() returned 1
libusb: debug [reap_for_handle] urb type=3 status=-71 transferred=0
libusb: debug [handle_bulk_completion] handling completion status -71 of bulk urb 1/1
libusb: debug [handle_bulk_completion] low level error -71
libusb: debug [disarm_timerfd]
libusb: debug [usbi_handle_transfer_completion] transfer 0x563230a35450 has callback 0x7f2537dfbb30
libusb: debug [sync_transfer_cb] actual_length=0
libusb: debug [libusb_free_transfer] transfer 0x563230a35450
libusb: debug [libusb_release_interface] interface 0
libusb: debug [libusb_close]
libusb: debug [usbi_remove_pollfd] remove fd 26
libusb: debug [libusb_exit]
libusb: debug [libusb_exit] destroying default context

 

0 Likes
1 Solution
amulya_nr
Level 2
Level 2
10 replies posted First like received 10 sign-ins

Hi Thank you for the reply. Actually the auto master and auto slave code was corrupted. I reburned it to firmware. Now its working fine.

However I would like to add few more points.

For LibUSB_TIMEOUT_ERROR use libusbpolltimeout inbuilt function.

For LIBUSB_BUFFER_OVERFLOW set the max buffer size to 39936.  

For LIBUSB_ERROR_IO unplug the firmware and connect back because the device goes to infinite loop of not finding the device.

However My current problem is, I have made an application which will be open for continuous USB poll. I transfer huge data files (in GBs) but the time taken by firmware(cypress USB FX3 Super speed device) is too slow. i dont know whether it is firmware error or my software error. I am not able to attain USB 3.0 speed in Ubuntu OS. code i can mail you in private only.

View solution in original post

0 Likes
5 Replies
Biren
Moderator
Moderator
Moderator
First like given 250 sign-ins 50 solutions authored

Hello,

can you please try cyfxbulksrcsink firmware onboard and test? so we can narrow down debug points whether it is related to the host app or firmware.

And please provide error details which are shown when you click on show details on the error popup box in the current scenario.

Best Regards,
Biren

amulya_nr
Level 2
Level 2
10 replies posted First like received 10 sign-ins

Hi Thank you for the reply. Actually the auto master and auto slave code was corrupted. I reburned it to firmware. Now its working fine.

However I would like to add few more points.

For LibUSB_TIMEOUT_ERROR use libusbpolltimeout inbuilt function.

For LIBUSB_BUFFER_OVERFLOW set the max buffer size to 39936.  

For LIBUSB_ERROR_IO unplug the firmware and connect back because the device goes to infinite loop of not finding the device.

However My current problem is, I have made an application which will be open for continuous USB poll. I transfer huge data files (in GBs) but the time taken by firmware(cypress USB FX3 Super speed device) is too slow. i dont know whether it is firmware error or my software error. I am not able to attain USB 3.0 speed in Ubuntu OS. code i can mail you in private only.

0 Likes
Biren
Moderator
Moderator
Moderator
First like given 250 sign-ins 50 solutions authored

Hello,

can you please test with the Streamer app and check how much speed you get and compare it with your app.

Best Regards,

Biren

0 Likes

Dear,

           Streamer application is not working in ubuntu. I have run my own application the wireshark output is attached below.

0 Likes
Biren
Moderator
Moderator
Moderator
First like given 250 sign-ins 50 solutions authored

Hello,

Please use FX3 SDK for Linux  and, in that we have cyusb_linux which you can use, or you can FX3_SDK_Linux\cyusb_linux_1.0.5\src\09_cyusb_performance.cpp and use it.

Best Regards,
Biren

0 Likes