主题 : 关于向mini2440上安装libusb方法!!急等回复!!! 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 10676
精华: 0
发帖: 10
金钱: 75 两
威望: 30 点
综合积分: 20 分
注册时间: 2009-11-12
最后登录: 2010-04-29
楼主  发表于: 2009-12-23 17:55

 关于向mini2440上安装libusb方法!!急等回复!!!

我想把libusb加到ARM开发板中,该怎么操作啊??
是重新编译板子的内核??
还是把libusb编译好的文件直接拷到板子的某个目录下就可以用呢??
能给个步骤么??谢谢
这个阶段正是我事业的上升期,我怎么能走得开呢?
级别: 精灵王
UID: 3197
精华: 3
发帖: 770
金钱: 6995 两
威望: 5398 点
综合积分: 1600 分
注册时间: 2008-12-30
最后登录: 2010-12-31
1楼  发表于: 2009-12-23 21:04
首先要交叉编译。。。
另外libusb本身是无法运行使用的。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
2楼  发表于: 2009-12-23 22:02
是重新编译板子的内核??

libusb是用户空间的东西,和内核没有直接关系,一般不需要重新编译内核

还是把libusb编译好的文件直接拷到板子的某个目录下就可以用呢??

通常情况下,把交叉编译好的libusb放到板子上的/usr/lib目录下就可以了。如果出现依赖libusb的应用程序无法找到libusb.so的情况,用export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib命令将/usr/lib目录加到动态链接器搜索共享库的路径上就可以了。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 10676
精华: 0
发帖: 10
金钱: 75 两
威望: 30 点
综合积分: 20 分
注册时间: 2009-11-12
最后登录: 2010-04-29
3楼  发表于: 2009-12-24 14:12
我按照您说的实验了下:
我用的是官方最新的libusb-1.0.6.tar.bz2
交叉编译后生成include/libusb-1.0/libusb.h以及lib文件夹下有libusb-1.0.so文件和其他一些文件
但是没有usb.h文件。网上有人贴出了测试libusb的程序
如下面:
http://hi.baidu.com/proudboy_linux/blog/item/f9d806ca28b87216bf09e67f.html

始终编译找不到usb.h啊???
级别: 新手上路
UID: 10676
精华: 0
发帖: 10
金钱: 75 两
威望: 30 点
综合积分: 20 分
注册时间: 2009-11-12
最后登录: 2010-04-29
4楼  发表于: 2009-12-24 14:14
引用第2楼kasim于2009-12-23 22:02发表的  :

通常情况下,把交叉编译好的libusb放到板子上的/usr/lib目录下就可以了。

是不是include可以不要啊??
级别: 新手上路
UID: 10676
精华: 0
发帖: 10
金钱: 75 两
威望: 30 点
综合积分: 20 分
注册时间: 2009-11-12
最后登录: 2010-04-29
5楼  发表于: 2009-12-24 14:20
移植好libusb之后可以测试一下该包工作是否正常,这样可以用来排除故障。一下是一个基于libusb的测试程序,如果可以检测到端口表示包没问题。

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>

void print_endpoint(struct usb_endpoint_descriptor *endpoint)
{
printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize);
printf(" bInterval: %d\n", endpoint->bInterval);
printf(" bRefresh: %d\n", endpoint->bRefresh);
printf(" bSynchAddress: %d\n", endpoint->bSynchAddress);
}


void print_altsetting(struct usb_interface_descriptor *interface)
{
int i;

printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber);
printf(" bAlternateSetting: %d\n", interface->bAlternateSetting);
printf(" bNumEndpoints: %d\n", interface->bNumEndpoints);
printf(" bInterfaceClass: %d\n", interface->bInterfaceClass);
printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass);
printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol);
printf(" iInterface: %d\n", interface->iInterface);

for (i = 0; i < interface->bNumEndpoints; i++)
print_endpoint(&interface->endpoint);
}


void print_interface(struct usb_interface *interface)
{
int i;

for (i = 0; i < interface->num_altsetting; i++)
print_altsetting(&interface->altsetting);
}


void print_configuration(struct usb_config_descriptor *config)
{
int i;

printf(" wTotalLength: %d\n", config->wTotalLength);
printf(" bNumInterfaces: %d\n", config->bNumInterfaces);
printf(" bConfigurationValue: %d\n", config->bConfigurationValue);
printf(" iConfiguration: %d\n", config->iConfiguration);
printf(" bmAttributes: %02xh\n", config->bmAttributes);
printf(" MaxPower: %d\n", config->MaxPower);

for (i = 0; i < config->bNumInterfaces; i++)
print_interface(&config->interface);
}


int main(void)
{
struct usb_bus *bus;
struct usb_device *dev;

usb_init();
usb_find_busses();
usb_find_devices();

printf("bus/device idVendor/idProduct\n");

for (bus = usb_busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
int ret, i;
char string[256];
usb_dev_handle *udev;

printf("%s/%s %04X/%04X\n", bus->dirname, dev->filename,
dev->descriptor.idVendor, dev->descriptor.idProduct);

udev = usb_open(dev);
if (udev) {
if (dev->descriptor.iManufacturer) {
ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string));
if (ret > 0)
printf("- Manufacturer : %s\n", string);
else
printf("- Unable to fetch manufacturer string\n");
}

if (dev->descriptor.iProduct) {
ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string));
if (ret > 0)
printf("- Product : %s\n", string);
else
printf("- Unable to fetch product string\n");
}

if (dev->descriptor.iSerialNumber) {
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string));
if (ret > 0)
printf("- Serial Number: %s\n", string);
else
printf("- Unable to fetch serial number string\n");
}

usb_close (udev);
}

if (!dev->config) {
printf(" Couldn't retrieve descriptors\n");
continue;
}

for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
print_configuration(&dev->config);
}
}

return 0;
}

编译的时候记得加上-lusb选项,交叉编译还要加上libusb包的路径-I/.../include和-L/.../lib

我试过将usb.h换成libusb.h还是报错!!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
6楼  发表于: 2009-12-24 14:31
引用第4楼xianyu于2009-12-24 14:14发表的  :

是不是include可以不要啊??

是的,include目录下的东西只有在交叉编译时才需要,在板子上运行依赖于libusb的应用程序不需要这些。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
7楼  发表于: 2009-12-24 14:35
引用第5楼xianyu于2009-12-24 14:20发表的  :
移植好libusb之后可以测试一下该包工作是否正常,这样可以用来排除故障。一下是一个基于libusb的测试程序,如果可以检测到端口表示包没问题。

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
.......

问题不在于头文件的名字,而在于你必须让你的.c文件里所有声明的宏,类型等等在它包含的头文件里找得到定义。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 10676
精华: 0
发帖: 10
金钱: 75 两
威望: 30 点
综合积分: 20 分
注册时间: 2009-11-12
最后登录: 2010-04-29
8楼  发表于: 2009-12-24 17:08
哦,,谢谢。我再试试。。。。