Utilize USBXpress development kit to simplify application program and realize USB communication design

Traditional USB device driver programming is extremely complicated, and it is often difficult for programmers to get started. The USBXpress development kit provided by SILICON Laboratories greatly simplifies the development of USB communication applications and related driver programs. As long as preparations are made before development, the USBXpress development kit can fully implement all the functions of USB communication. This article introduces the whole process of USB communication development, as well as the matters needing attention in the development process. (

Traditional USB device driver programming is extremely complicated, and it is often difficult for programmers to get started. The USBXpress development kit provided by SILICON Laboratories greatly simplifies the development of USB communication applications and related driver programs. As long as preparations are made before development, the USBXpress development kit can fully implement all the functions of USB communication. This article introduces the whole process of USB communication development, as well as the matters needing attention in the development process. (Mainly explain the USB communication on the device side)

1. Introduction to USBXpress

The USBXpress development kit launched by SILICON Laboratories covers all the functions of the host side and the device side, and supports the USB communication of C8051F32X, C8051F34X and CP210X devices. The USBXpress development kit contains the host-side device driver, host-side device driver installation program, host-side dynamic link library (DLL) and device-side function library files.

The function library file on the device side provides API functions that support USB communication between C805IF32X and C8051F34X devices. These functions can be compiled under the Keil uVision3 compilation environment. Related files need to be added to the project before compilation, see below for details.

The main API functions in the device-side function library are as follows:

USB Clock Start()-Initialize the USB clock
USB Init ()-USB interface initialization
Block Write ()-write data to the Buffer
Block Read ()-read data from Buffer
Get Interrupt Source ()-Get the interrupt flag value of the API function USB Int Enable ()-Allow API function interrupt
USB Int Disable()-API function interrupt is not allowed
USB Disable ()-does not allow USB interface communication
USB Suspend()-Suspend USB interruption

2. Circuit design on the equipment side

(1) USB socket pin identification

In the process of designing the circuit of the non-standby terminal, the pins of the USB socket must be connected correspondingly, otherwise it will directly affect the communication with the host terminal. USB sockets are generally divided into A-type sockets and B-type sockets, as shown in Figure 1, and their pin descriptions are listed in Table 1.

Utilize USBXpress development kit to simplify application program and realize USB communication design

(2) USB communication circuit based on C8051F340

Utilize USBXpress development kit to simplify application program and realize USB communication design

The USB communication circuit based on C8051F340 is shown in Figure 2.

Utilize USBXpress development kit to simplify application program to realize USB communication design (3) USB communication circuit description

①D- and D+ in the circuit should not be connected to other load circuits, because any load will affect the current on the data line, thereby affecting data transmission, and the direct consequence will cause the host to fail to recognize the device.

②The VDD pin in the JTAG port line is +3 V input. If the input voltage is too large, the device will be damaged. The pins of the USB socket and the pins of C8051F340 should be connected correspondingly, don’t make mistakes.

③There are many ways to connect the VBUS, REGIN and VDD pins of C8051F340 (voltage regulator configuration), see Table 2 for details.

Utilize USBXpress development kit to simplify application program and realize USB communication design

3. Design of device driver

Under the Keil uVision3 compilation environment, use the API function in the USBXpress toolkit to design the USB communication on the device side, provided that C8051F340 is added to the project. h, USB_API. h and USBX_F34X. LIB files (related files provided by the USBXpress toolkit).

The following describes the data transmission of the device end USB. Before data transmission, the USB clock and USB interface must be initialized:

Utilize USBXpress development kit to simplify application program and realize USB communication design

Utilize USBXpress development kit to simplify application program to realize USB communication design (1) USB interface initialization parameter definition

①USB_VID, 16-bit binary vendor ID number, usually SILICONLab ID number (OXl0C4).

②USB_PID, 16-bit binary product ID number, generally specified as OXEA61 by USBXpress.

Use the USBXpress development kit to simplify the application to realize the USB communication design. ④USB_ProductStr, a BYTE pointer, points to a character string describing the product, and cannot be empty.

⑤USB_SerialStr, BYTE pointer, points to the character string describing the serial number, and cannot be empty.

⑥USB_MaxPower, BYTE type, indicates the maximum bus current, and the limit is 500 mA. If the value is 0x32, it means that the maximum current is 100 mA.

⑦USB_PwAttributes, BYTE type, used for power supply configuration. The sixth position is “1” if the device is powered by itself, and “O” if it is powered by the bus. If the device provides a weak pull-up function, the fifth position is “1”, bits 0 to 4 must be “O”, and bit 7 must be “1”.

⑧USB_bcdDevice, unsigned int type, uses BCD code to indicate the version number of the device, for example, version 2.13 is Ox0213.

(2) USB interrupt function

The functions of the API functions in the device-side USB communication are all implemented in an interrupt module, for which an interrupt vector must be provided. Among them, 0x008B (Interrupt 17) is the interrupt vector of the F34X device. In the main function, the interrupt can only be entered if the USB interrupt is allowed (the USB Int Enable function is called). Once you enter the interrupt service routine, you must first obtain the interrupt flag (call the Get_Interrupt_Source function and return the BYTE type interrupt flag), and the subsequent operations will be executed according to the obtained interrupt flag value and the interrupt flag value defined by the toolkit. The custom interrupt flag values ​​mainly include: USB_RESET (reset interrupt), TX_COMPLETE (transmission completion interrupt), RX_COMPLETE (allow to receive interrupt), DEVICEOPEN (device instance is opened on the host side), DEVICE SUSPEND (delay signal), etc.

The interrupt function is as follows:

Utilize USBXpress development kit to simplify application program and realize USB communication design

After the initialization in the main function, if the interrupt is allowed, the data is sent through the function Block_write, and the number of bytes of the sent data cannot exceed 4096. After sending, it will trigger an interrupt and enter the interrupt service routine for judgment operation. If the host side writes data to the Buffer on the device side, an interrupt will also be triggered, and it will be judged to execute the Block_Read operation to store the data in the Buffer into the designated storage unit.

The function prototype for sending data is: Block_write (the first address of the data storage unit, the number of bytes sent).

(3) Host USB application design

In VC++6. To develop the USB communication application program on the host side under the O compiling environment, you need to pay attention to adding SiUSBXp provided by the development kit to the project before compiling. dll, SiUSBXp. h and SiUSBXp. lib file.

In order to allow the host to recognize the USB device and communicate with it, before running the application, it is necessary to install the driver of the host (the development kit is provided). After the driver is installed, the host can recognize the USB device, and the relevant description information of the USB device can be found in the device manager.

For the description information of the USB device, in addition to modifying the descriptor sent from the device side, it can also be modified under the driver installation directory on the host side*. Information in the inf file.

Concluding remarks

This article introduces the USB communication development process, circuit design and device-side driver design in detail, and briefly explains the condition settings of the USBXpress development kit on the host side. All design ideas and methods have passed experimental verification and can be directly used for engineering project development. Through this method, programmers can easily design and program a series of USB communication applications.

The Links:   LM170E03-TLG5 CM100DY-12H

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *