[Android Q&A, Help & Troubleshooting] 4ntoine:
Hi guys.

I'm developing ArduinoDroid app - Arduino IDE for Android.

At this time i'm working on sketches uploading using modified avrdude and i have some problems with interaction with FTDI-based usb devices (Arduino boards).

I've described my problem in android issue tracker as it seems to be android issue (can't add link)

libftdi code:

/**

Opens a ftdi device given by an usb_device.

\param ftdi pointer to ftdi_context

\param dev libusb usb_dev to use

\retval 0: all fine

\retval -3: unable to config device

\retval -4: unable to open device

\retval -5: unable to claim device

\retval -6: reset failed

\retval -7: set baudrate failed

\retval -8: ftdi context invalid

*/

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) {

fprintf(stderr, "opening usb_dev in ftdi..\n");

if (!(ftdi->usb_dev = usb_open(dev)))

ftdi_error_return(-4, "usb_open() failed");

} else {

fprintf(stderr, "using udev: %i\n", (int)usb_dev);

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)

{

if (usb_detach_kernel_driver_np(ftdi->usb_dev, ftdi->interface) != 0 && errno != ENODATA) {

fprintf(stderr, "failed to detach\n");

detach_errno = errno;

}

}

#endif

//#ifdef __WIN32__

// set configuration (needed especially for windows)

// tolerate EBUSY: one device with one configuration, but two interfaces

// and libftdi sessions to both interfaces (e.g. FT2232)

fprintf(stderr, "ftdi set configuration\n");

if (dev->descriptor.bNumConfigurations > 0)

{

// libusb-win32 on Windows 64 can return a null pointer for a valid device

if (dev->config) {

config_val = dev->config[0].bConfigurationValue;

fprintf(stderr, "trying to set configuration %i\n", config_val);

}

if (usb_set_configuration(ftdi->usb_dev, config_val) && errno != EBUSY)

{

ftdi_usb_close_internal (ftdi);

if (detach_errno == EPERM)

{

ftdi_error_return(-8, "inappropriate permissions on device!");

}

else

{

ftdi_error_return(-3, "unable to set usb configuration. Make sure the default FTDI driver is not in use");

}

}

}

//#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");

}

// Try to guess chip type

fprintf(stderr, "Try to guess chip type ...\n");

// Bug in the BM type chips: bcdDevice is 0x200 for serial == 0

if (dev->descriptor.bcdDevice == 0x400 || (dev->descriptor.bcdDevice == 0x200 && dev->descriptor.iSerialNumber == 0))

ftdi->type = TYPE_BM;

else if (dev->descriptor.bcdDevice == 0x200)

ftdi->type = TYPE_AM;

else if (dev->descriptor.bcdDevice == 0x500)

ftdi->type = TYPE_2232C;

else if (dev->descriptor.bcdDevice == 0x600)

ftdi->type = TYPE_R;

else if (dev->descriptor.bcdDevice == 0x700)

ftdi->type = TYPE_2232H;

else if (dev->descriptor.bcdDevice == 0x800)

ftdi->type = TYPE_4232H;

else if (dev->descriptor.bcdDevice == 0x900)

ftdi->type = TYPE_232H;

fprintf(stderr, "finished try to guess chip type\n");

// Set default interface on dual/quad type chips

switch(ftdi->type)

{

case TYPE_2232C:

case TYPE_2232H:

case TYPE_4232H:

if (!ftdi->index)

ftdi->index = INTERFACE_A;

break;

default:

break;

}

// Determine maximum packet size

fprintf(stderr, "calc _ftdi_determine_max_packet_size ...\n");

ftdi->max_packet_size = _ftdi_determine_max_packet_size(ftdi, dev);

fprintf(stderr, "ftdi_set_baudrate 9600 ...\n");

if (ftdi_set_baudrate (ftdi, 9600) != 0)

{

ftdi_usb_close_internal (ftdi);

ftdi_error_return(-7, "set baudrate failed");

}

fprintf(stderr, "ftdi device opened\n");

ftdi_error_return(0, "all fine");

}

error log:

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

So i'm getting EPIPE error (32) all the time.

I wonder if anyone can help me in any way as i'm completely stuck.

Thanks in advance.