I'm trying to work with an FTDI-based USB device and I'm getting a -32 (EPIPE) error:
08-06 16:32:16.328: WARN/System.err(15547): ftdi_usb_open_dev()
08-06 16:32:16.328: WARN/System.err(15547): usb_detach_kernel_driver_np()libusb: 0.029116 debug [libusb_detach_kernel_driver] interface 0
08-06 16:32:16.328: WARN/System.err(15547): ftdi claim interface ...
08-06 16:32:16.328: WARN/System.err(15547): libusb-compat debug: usb_claim_interface: interface 0
08-06 16:32:16.328: WARN/System.err(15547): libusb: 0.030246 debug [libusb_claim_interface] interface 0
08-06 16:32:16.328: WARN/System.err(15547): claiming interface using fd = 4
08-06 16:32:16.328: WARN/System.err(15547): ftdi_usb_reset ...
08-06 16:32:16.328: WARN/System.err(15547): libusb-compat debug: usb_control_msg: RQT=40 RQ=0 V=0 I=0 len=0 timeout=300
08-06 16:32:16.328: WARN/System.err(15547): libusb: 0.031222 debug [libusb_get_next_timeout] next timeout in 0.300000s
08-06 16:32:16.328: WARN/System.err(15547): libusb: 0.031527 debug [libusb_handle_events_timeout_completed] doing our own event handling
08-06 16:32:16.328: WARN/System.err(15547): libusb: 0.032046 debug [handle_events] poll() 2 fds with timeout in 300ms
08-06 16:32:16.328: WARN/System.err(15547): libusb: 0.033023 debug [handle_events] poll() returned 1
08-06 16:32:16.338: WARN/System.err(15547): libusb: 0.033389 debug [reap_for_handle] urb type=2 status=-32 transferred=0
08-06 16:32:16.338: WARN/System.err(15547): libusb: 0.033755 debug [handle_control_completion] handling completion status -32
08-06 16:32:16.338: WARN/System.err(15547): libusb: 0.034091 debug [handle_control_completion] unsupported control request
08-06 16:32:16.338: WARN/System.err(15547): libusb: 0.034366 debug [usbi_handle_transfer_completion] transfer 0x2915e0 has callback 0x5ccb4
08-06 16:32:16.338: WARN/System.err(15547): libusb: 0.034732 debug [ctrl_transfer_cb] actual_length=0
The USB request seems to be exactly as it is required according to FTDI Chip Commands.
FTDI context is initialized without errors, usb_dev is not null and it seems to be okay. The cable is okay as I can use it for uploading Arduino sketches to Duemilanove (FTDI) boards.
So I'm completely stuck.. What should I do?
My code
struct ftdi_context *ftdi_ctx;
struct usb_device *dev;
usb_dev_handle *udev;
// ...
ftdi_ctx = ftdi_new();
if (ftdi_ctx == NULL) {
fprintf(stderr, "error init ftdi context\n");
return 1;
}
ftdi_ctx->usb_write_timeout = 0;
ftdi_ctx->usb_read_timeout = 0;
// ...
udev = usb_open(dev);
int ret = ftdi_usb_open_dev(ftdi_ctx, dev, udev);
if (ret < 0) {
fprintf(stderr, "error opening ftdi device\n");
return ret;
}
ftdi_usb_open_dev()
is slightly modified to get ready usb_device
and don't do usb_open inside:
libftdi-0.1 code (ftdi.c):
int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev, struct usb_dev_handle *usb_dev)
{
int detach_errno = 0;
int config_val = 1;
fprintf(stderr, "ftdi_usb_open_dev()\n");
if (ftdi == NULL) {
fprintf(stderr, "ftdi context invalid\n");
ftdi_error_return(-8, "ftdi context invalid");
}
// 4ntoine (no need to open device if usb_dev is already passed)
if (usb_dev == NULL) {
if (!(ftdi->usb_dev = usb_open(dev)))
ftdi_error_return(-4, "usb_open() failed");
} else {
ftdi->usb_dev = usb_dev;
}
#ifdef LIBUSB_HAS_GET_DRIVER_NP
// Try to detach ftdi_sio kernel module.
// Returns ENODATA if driver is not loaded.
//
// The return code is kept in a separate variable and only parsed
// if usb_set_configuration() or usb_claim_interface() fails as the
// detach operation might be denied and everything still works fine.
// Likely scenario is a static ftdi_sio kernel module.
fprintf(stderr, "detaching kernel driver... \n");
if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
{
fprintf(stderr, "usb_detach_kernel_driver_np() ...\n");
if (usb_detach_kernel_driver_np(ftdi->usb_dev, ftdi->interface) != 0 && errno != ENODATA) {
fprintf(stderr, "failed to detach\n");
detach_errno = errno;
}
}
#endif
fprintf(stderr, "ftdi claim interface ...\n");
if (usb_claim_interface(ftdi->usb_dev, ftdi->interface) != 0)
{
fprintf(stderr, "failed to claim interface\n");
ftdi_usb_close_internal (ftdi);
if (detach_errno == EPERM)
{
ftdi_error_return(-8, "inappropriate permissions on device!");
}
else
{
ftdi_error_return(-5, "unable to claim usb device. Make sure the default FTDI driver is not in use");
}
}
fprintf(stderr, "ftdi claimed interface\n");
fprintf(stderr, "ftdi_usb_reset ...\n");
if (ftdi_usb_reset (ftdi) != 0)
{
ftdi_usb_close_internal (ftdi);
ftdi_error_return(-6, "ftdi_usb_reset failed");
}
I've tested it with another FTDI-board (Arduino Nano v3) and still the same error, so the problem is not in the board most likely...
I've tested it on another Android device with USB host support too and another Android OS version (4.0.x) and still the same error...