- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
Iam tring to communicate with the cypress device using libusb and the cypress wrapper. But the libusb_init() function always return -1(LIBUSB_ERROR_IO).
The android device is rooted. I can not use any of the libusb commands.
Cypress device -CYUSB3014-BZXC
Anybody help me to resolve this issue?
Regards,
Sarath
Solved! Go to Solution.
- Tags:
- android_usb_driver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Yatheesh,
Always thank you for your support.
libusb integration problem is solved. ( Successfully tested on Android 10, 9 and 6)
Use libusb from the below link.
https://github.com/libusb/libusb/tree/master/android
Change SELinux to permissive --> #setenforce 0
By default it is in enforcing mode.
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sarath,
Please refer to this link:
Also, can you please let me know which IDE you are using to build the project and where are you seeing the error.
Thanks,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
1.Builded libusb for android and generated the libusb1.0.so files for multiple architecure.(Using Ubuntu 20.04 LTS)
Where architecure mean:
arm64-v8a
armeabi-v7a
x86
x86_64
2.Also linked these libraries to my android studio project (Native C++ Project (NDK)) [Windows 10 machine]
Android studio 4.0
##############################################################################################
cmake_minimum_required(VERSION 3.4.1)
add_library( libusb1.0
SHARED
IMPORTED )
set_target_properties( # Specifies the target library.
libusb1.0
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
"C:/Users/xxxx/AndroidStudioProjects/androidUsb/app/src/main/libs/${ANDROID_ABI}/libusb1.0.so" )
add_library( # Sets the name of the library.
native-lib
SHARED
native-lib.cpp listdevs.cpp)
target_link_libraries( # Specifies the target library.
native-lib
libusb1.0 )
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
##############################################################################################
Then, Trying to list the connected cypress device using my test application
But the libusb_init() function is always returns -1 (LIBUSB_ERROR_IO).
My test code shown below.
/*************************************listdev.cpp*******************************************/
#include <stdio.h>
#include <android/log.h>
#include "listdevs.h"
#define LOG_TAG "usb_driver"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
void print_devs(libusb_device **devs)
{
libusb_device *dev;
int i = 0, j = 0;
uint8_t path[8];
while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
LOGD("failed to get device descriptor");
return;
}
LOGE("%04x:%04x (bus %d, device %d)",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev), libusb_get_device_address(dev));
r = libusb_get_port_numbers(dev, path, sizeof(path));
if (r > 0) {
LOGE(" path: %d", path[0]);
for (j = 1; j < r; j++)
LOGE(".%d", path
}
LOGD("\n");
}
}
int listdevs_init(void)
{
libusb_device **devs;
int r;
ssize_t cnt;
r = libusb_init(NULL); ///////////////***************libusb_init() call****************/////////////////
if (r < 0) {
LOGD("Failed to Initialize- libusb_init");
LOGE(" Return Value: %d", r);
return r;
}
cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0){
libusb_exit(NULL);
return (int) cnt;
}
print_devs(devs);
libusb_free_device_list(devs, 1);
libusb_exit(NULL);
return 0;
}
/**********************************************************************************************/
/*************************************native-lib.cpp*******************************************/
#include <jni.h>
#include <string>
#include "listdevs.h"
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_androidusb_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
int r ;
r = listdevs_init();
std::string status = std::to_string(r);
return env->NewStringUTF(status.c_str());
}
/**********************************************************************************************/
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sarath,
Can you please share your android studio project with us?
Thanks,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
Please download it from the below link.
https://drive.google.com/file/d/1DeZGxQxZom3sYoBABN_t7PccMqHjIaQQ/view?usp=sharing
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
For your information (Shared project details)
libusb version i used: " libusb-1.0.23 "
Android studio 4.0.
Android Device used to test the application - Samsung Galaxy S20 5G (rooted)
Build libusb-1.0.23 using latest NDK(android-ndk-r21d) in Windows 10 machine (Power shell).
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sarath,
I tried building and debugging the project with a change in the library path in CMakeLists.txt.
libusb_init() returned success (r = 0) and the libusb_open_device_with_vid_pid returns NULL as no devices are attached.
The APK runs fine on emulator and my mobile device (Samsung M31)
I have attached the Debug Signed APK using key store.
Please try it on your side.
Thanks,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
Sorry to inform you regarding this ,While using libusb-1.0.23 the libusb_init() function issue is resolved. It return zero.
But "libusb_open_device_with_vid_pid" returns -19.
printf("Device not found\n");
return -ENODEV;
I tried to connect my phone with the cypress device and a sandisk pendrive.
But always it return -19.
I expecting the return value 1.
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
cypress device details.
vid=0x04B4
pid=0x00F3
Note:
While using the sandisk pendrive,i passed its on VID and PID to the function.
/***********************
h = libusb_open_device_with_vid_pid(NULL, vid, pid);
if ( !h ) {
printf("Device not found\n");
return -ENODEV;
}
cydev[0].dev = libusb_get_device(h);
cydev[0].handle = h;
cydev[0].vid = cyusb_getvendor(h);
cydev[0].pid = cyusb_getproduct(h);
cydev[0].is_open = 1;
cydev[0].busnum = cyusb_get_busnumber(h);
cydev[0].devaddr = cyusb_get_devaddr(h);
nid = 1;
return 1;
After getting the handle only i can use the rest of the cypress wrapper API's.
**********************/
Could you please check it?
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Yatheesh,
Always thank you for your support.
JFYI:
I tried libusb-1.0.22 and libusb-1.0.21 versions too.
But in both the cases libusb_init function returns -99 error.
Summary:
In short now i tried 4 libusb versions.
1.libusb
Download path : https://community.cypress.com/message/184458#184458
Download libusb from the above thread(This thread is shared by you)
Result : libusb_init() returns -1 [FAIL]
---------------------------------------------------------------------
2.libusb-1.0.21
Download path : https://github.com/libusb/libusb/releases
Result :libusb_init() returns -99 [FAIL]
---------------------------------------------------------------------
3.libusb-1.0.22
Download path : https://github.com/libusb/libusb/releases
Result :libusb_init() returns -99 [FAIL]
---------------------------------------------------------------------
4.libusb-1.0.23
Download path : https://github.com/libusb/libusb/releases
Result :libusb_init() returns 0. [SUCCESS]
But libusb_open_device_with_vid_pid() returns NULL [FAIL]
Also this Andriod studio project and the complete error cases are already shared to you.
----------------------------------------------------------------------
Could you please help me to resolve this issue?
Please let me know if you need any additional info.
Thanks and regards,
sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sarath,
Can you please let me know if there is any update on this issue.
This issue is specific to libusb and we only provide the wrapper around libusb.
We have an Android SDK for USB-Serial, which also uses libusb. It also has the pre-built apk in the bin folder on the SDK.
Please download the Android SDK from this page: https://www.cypress.com/documentation/software-and-drivers/usb-serial-software-development-kit and refer to the start.chm in the doc folder.
Hope this will be helpful.
Thanks,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
Thanks for the Update.
Findings are based on libusb1.0.22
Unable to access the usb mount path /dev/bus/usb/*. Which is the root cause of all the issues.
- Actually USB devices mounted on /dev/bus/usb. But while opening the path opendir() function returns NULL as it is unable to open the location.
- As opendir() function returns NULL op_init function returning -99 (LIBUSB_ERROR_OTHER).
- Then libusb_init() return -99.
Note:
- Permission given to that location(/dev/bus/usb) is 777(read, write, execute permission for all users).
Any suggestions are welcome...
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sarath,
Please refer to the document in the Android SDK for USB Serial.
As per the document:
The usb device node created in kernel does not have read/write permission. The permission can be changed by adding following instruction in ueventd.rc file.
/dev/bus/usb/* 0660 root usb.
Thanks,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
It is already the part of that file(ueventd.rc) "/dev/bus/usb/* 0660 root usb"
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
firmware_directories /etc/firmware/ /odm/firmware/ /vendor/firmware/ /firmware/image/
uevent_socket_rcvbuf_size 16M
subsystem graphics
devname uevent_devpath
dirname /dev/graphics
subsystem drm
devname uevent_devpath
dirname /dev/dri
subsystem input
devname uevent_devpath
dirname /dev/input
subsystem sound
devname uevent_devpath
dirname /dev/snd
# ueventd can only set permissions on device nodes and their associated
# sysfs attributes, not on arbitrary paths.
#
# format for /dev rules: devname mode uid gid
# format for /sys rules: nodename attr mode uid gid
# shortcut: "mtd@NN" expands to "/dev/mtd/mtdNN"
/dev/null 0666 root root
/dev/zero 0666 root root
/dev/full 0666 root root
/dev/ptmx 0666 root root
/dev/tty 0666 root root
/dev/random 0666 root root
/dev/urandom 0666 root root
# Make HW RNG readable by group system to let EntropyMixer read it.
/dev/hw_random 0440 root system
/dev/ashmem 0666 root root
/dev/binder 0666 root root
/dev/hwbinder 0666 root root
/dev/vndbinder 0666 root root
/dev/pmsg0 0222 root log
# kms driver for drm based gpu
/dev/dri/* 0666 root graphics
# these should not be world writable
/dev/uhid 0660 uhid uhid
/dev/uinput 0660 uhid uhid
/dev/rtc0 0640 system system
/dev/tty0 0660 root system
/dev/graphics/* 0660 root graphics
/dev/input/* 0660 root input
/dev/v4l-touch* 0660 root input
/dev/snd/* 0660 system audio
/dev/bus/usb/* 0660 root usb
/dev/mtp_usb 0660 root mtp
/dev/usb_accessory 0660 root usb
/dev/tun 0660 system vpn
/dev/qbt2000_fd 0660 system system
/dev/qbt2000_ipc 0660 system system
/dev/qbtspi 0660 system system
/dev/power_on_alarm 0220 system radio
# CDMA radio interface MUX
/dev/ppp 0660 radio vpn
# sysfs properties
/sys/devices/platform/trusty.* trusty_version 0440 root log
/sys/devices/virtual/input/input* enable 0660 system radio
/sys/devices/virtual/input/input* poll_delay 0660 system radio
/sys/devices/virtual/usb_composite/* enable 0664 root system
/sys/devices/system/cpu/cpu* cpufreq/scaling_max_freq 0664 system system
/sys/devices/system/cpu/cpu* cpufreq/scaling_min_freq 0664 system system
/sys/devices/virtual/thermal/cooling_device* cur_state 0664 system system
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Can i change it to any other location/place in this file?
Regards,
Sarath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Yatheesh,
Always thank you for your support.
libusb integration problem is solved. ( Successfully tested on Android 10, 9 and 6)
Use libusb from the below link.
https://github.com/libusb/libusb/tree/master/android
Change SELinux to permissive --> #setenforce 0
By default it is in enforcing mode.
Regards,
Sarath