1587 views|0 replies

501

Posts

4

Resources
The OP
 

Feiling OK3568-C development board USB application development based on libusb [Copy link]

1. Introduction

This article introduces the application development based on libusb for OK3568-C development board, and introduces two ways: building libusb library, linking application to libusb library, and directly compiling libusb source code and application source code together. It also introduces the use of GDB for debugging.

2. How to build the library

2.1 Component Library

Download source code

git clone https://github.com/libusb/libusb.git

Enter the source code path

cd libusb/

Automatic generated

./autogen.sh

Configuration

./configure

Build and Install

make && make install

2.2 Testing

Sample code testing using source code

Enter the sample code path

cd examples/

Compile

make

Running the test program

Make compiles many test programs, such as running listdevs

./listdevs

Print as follows

root@ok3568:~/Desktop/libusb/examples# ./listdevs

1d6b:0003 (bus 8, device 1)

1d6b:0002 (bus 7, device 1)

1d6b:0003 (bus 6, device 1)

1d6b:0002 (bus 5, device 1)

1d6b:0001 (bus 4, device 1)

1d6b:0002 (bus 2, device 1)

1d6b:0001 (bus 3, device 1)

1d6b:0002 (bus 1, device 1)

2.3 Manual compilation

The examples directory above provides a Makefile for compiling all the examples. We can also manually compile our own applications or a sample program. For example, -lusb-1.0 links to the libusb library, -I specifies the header file path, and -L specifies the library file path.

gcc listdevs.c -I../libusb -lusb-1.0 -L../libusb

2.4 Debugging

Install gdb

apt install gdb

-g compile

gcc listdevs.c -I../libusb -lusb-1.0 -L../libusb-g -o listdevs

Debugging with gdb

gdb listdevs

3. Use source code directly

The above method of building the library first and then linking the library does not allow you to see the source code of libusb during debugging. We can directly use the source code of libusb and compile it together with our own application code, which makes it easier to debug and read the source code.

Copy the contents to your own project directory

Copy the following content under libusb

core.c

descriptor.c

hotplug.c

I.c

libusb.h

libusbi.h

sync.c

version.h

version_nano.h

strerror.c

Copy the following content under libusb/os

events_posix.c

events_posix.h

linux_udev.c

linux_usbfs.c

linux_usbfs.h

threads_posix.c

threads_posix.h

listdevs.c under examples

At the same time, copy the config.h file

The final directory is as follows

.

|-- examples

| |-- config.h

| `-- listdevs.c

`-- libusb

|-- core.c

|-- descriptor.c

|-- hotplug.c

|-- i.c

|-- libusb.h

|-- libusbi.h

|-- the

| |-- events_posix.c

| |-- events_posix.h

| |-- linux_udev.c

| |-- linux_usbfs.c

| |-- linux_usbfs.h

| |-- threads_posix.c

| `-- threads_posix.h

|-- strerror.c

|-- sync.c

|-- version.h

`-- version_nano.h

3 directories, 19 files

The compilation command is as follows

cd examples

gcc ../libusb/*.c ../libusb/os/events_posix.c ../libusb/os/linux_udev.c ../libusb/os/linux_usbfs.c ../libusb/os/threads_posix.c ./listdevs.c -I../libusb -I../libusb/os -I./ -lpthread -ludev -g -o listdevs

gcc libusb/*.c libusb/os/events_posix.c libusb/os/linux_udev.c libusb/os/linux_usbfs.c libusb/os/threads_posix.c ./examples/listdevs.c -Ilibusb -Ilibusb/os -Iexamples - lpthread -ludev -g -o listdevs

Debugging with GDB

gdb listdevs

Print as follows

root@ok3568:~/Desktop/libusbtest/examples# gdb listdevs

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2

Copyright (C) 2020 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Type "show copying" and "show warranty" for details.

This GDB was configured as "aarch64-linux-gnu".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

Find the GDB manual and other documentation resources online at:

<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".

Type "apropos word" to search for commands related to "word"...

Reading symbols from listdevs...

(gdb)

layout srcOpen source view

b main breaks the function in main

(gdb) b main

Breakpoint 1 at 0x178cc: file ./listdevs.c, line 53.

(gdb)

Enter run and press Enter to execute to the breakpoint

Press s to run in single step to enter the source code of libusb for debugging

  • Summarize

It is relatively simple to use libusb under Linux. There is not much source code for libusb. In the development stage, it is recommended to compile it directly with the application code for easy debugging. It depends on libpthread libudev.

From the above, we can see that thanks to the powerful performance and perfect environment of OK3568-C, USB application development can be carried out conveniently.

This post is from ARM Technology
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Some experience summary on AD conversion design

I saw a blog post about the basic issues in AD conversion design, so I reposted it here to share with you. Understanding ...

On the last day of 2019, make a New Year’s wish for 2020!

Today is the last day of 2019. Have all your wishes come true and all your plans completed this year? It doesn’t matter ...

Application of Dacai UART screen in environmental testing equipment

1. Product Overview Environmental monitoring instruments are a general term for instruments used to monitor various para ...

Understand the development principle of WiFi endoscope HD wireless camera in wireless communication module function in one article

When it comes to wifi video transmission, do you first think of the need for a core module with video compression SOC, a ...

Encoder counting principle and motor speed measurement principle - multi-picture analysis

This post was last edited by DDZZ669 on 2021-2-14 23:30 Encoder is a sensor used to measure mechanical rotation or displ ...

As an RF engineer, do you really know how to use "dB"?

In our work, we often use the unit "dB". For example, insertion loss, return loss, power, we often use xx dB, or xx dBm ...

31 "Millions of Miles" Raspberry Pi Car——Ubuntu MATE System Installation

Next, I was going to start learning ROS, but it was particularly difficult to install it on the Raspberry Pi operating ...

When studying the working principle of RCD circuit, what is the energy accumulated in the parasitic inductance?

Is it the parasitic inductance of the switch? 626540 Then I saw a circuit similar to RCD function in the PFC circuit. Is ...

The colorful version of the ESP32C3 development board has arrived

I placed the order the day before yesterday and received it today. I’ll take a few pictures to show you. 761291 7612 ...

TI BQ24610 charging chip usage issues

The 24V power supply charges the 5-series lithium battery pack, and the charging current is 2-6A. Now there are a few qu ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list