• USB interface and upper computer software design

    • source: ivan;
    • Time: 6/16/2020 7:14:49 AM
  • USB interface is generally used for high-speed data acquisition or transmission. It is the communication channel between the computer and the hardware equipment system. It can not only complete the data transmission task, but also realize the control of the equipment system by the computer. This paper designs and develops the universal USB interface working in Slave FIFO mode and the supporting man-machine interface software of upper computer, so as to meet the demand of high-speed and stable data transmission between single chip microcomputer, DSP, FPGA and other microprocessors and upper computer. The man-machine interface of the upper computer developed by this design can realize the function of sending down special control instructions, and the experimental results show that this design can meet the requirements of high-speed data transmission and can be used for general measurement and transmission。

    In modern scientific research, industrial production and working environment, it is essential to collect, process and transmit data generated by various electronic devices. As a high-speed, stable and flexible bidirectional data channel between peripherals and hosts, USB interface is widely used in data acquisition, industrial control and daily life. Thanks to its support for hot plugging and low cost, it has become the preferred solution for peripherals of various computer and electronic devices。

    USB2.0 supports three rates: low speed 1.5 Mb/s, full speed 12 Mb/s, and high speed 480 Mb/s. This paper combines USB2.0 Slave FIFO working mode and high speed transmission rate, and takes Cypress CY7C68013 chip as the core to design and develop firmware programs and upper computer human-machine interface programs that meet the requirements of general microprocessors for data transmission and control。

    1 USB chip selection

    USB chip encapsulates the underlying protocol of USB bus and provides instructions for users to use, so that users can get away from the complex underlying logic and directly realize the communication and control between host and device by sending instructions to control data transmission. In order to realize complex data transmission and command control functions, USB chips generally need to drive peripheral logic circuits through multiple I/O interfaces。

    USB interface chips can be divided into two types according to whether the microcontroller is embedded inside. USB interface chip without embedded microcontroller can only handle usB-related communication work, but the price is relatively low. Such chips as USBN9602/9603 of National Semiconductor and PDIUSB11/11A/12 series of Philips etc. For USB interface chip types that have embedded microcontroller internally, they can complete the extended BASIC FUNCTIONS of USB. Such chips are rich in data and generally have official routines to provide API functions to realize USB functions, which is easy to develop chips. For example, Cypress's EZ-USB FX2 series based on enhanced 8051 kernel and Atmel's AT76C711 based on AVR。

    CY7C68013A chip manufactured by Cypress was selected in this design. The chip provides rich data, complete function, wide application, can meet the requirements of data transmission speed, the price is reasonable. In addition, CY7C68013A, which has an embedded microprocessor, can download USB firmware programs to on-chip RAM memory via USB without the need for additional devices, making development easier。

    2 USB firmware program design

    2.1 Slave FIFO working mode introduced

    Ez-usb series chips have Slave FIFO and GPIF modes in batch data transmission. Slave FIFO mode is relatively more common, this working mode will see the data transmission as the common FIFO read and write, external logic circuit as the USB master controller, the upper computer as the Slave controller, USB chip as the transmission channel out. External logic circuit to produce Slave FIFO needs the transmission sequence, you can communicate with the upper computer. Wherein, FD data bus serves as the transmission channel of external logic and USB chip, FIFOADR[1:0] is used to select the endpoint of buffer, FLAGA, FLAGB and FLAGC are used to give the flag of empty buffer, SLRD and SLWR are FIFO read/write communication number and SLOE control output respectively。

    Since the read and write of Slave FIFO is controlled by the external logic, it is necessary to design the read and write state machine on the external logic chip to control the read and write pin logic. In order to facilitate the control of the whole system, the design of FIFO data between the endpoints of the asynchronous way to read and write. The read-write logic can be implemented externally logically by state machine programming according to the empty full flag of FIFO。

    2.2 Firmware program function design

    The purpose of designing firmware program is to control the hardware equipment to achieve the predetermined target. The normal work of hardware equipment based on microcontroller and its peripheral circuit requires the participation and control of firmware. This design adopts the automatic data transmission mode based on Slave FIFO, which can automatically send or receive the data in the configured endpoint FIFO to USB host, and only the corresponding register needs to be configured. The firmware of THE USB chip is mainly responsible for processing the USB device request from the upper computer, and also controlling the peripheral circuit of the chip for data transmission. There are five aspects:

    (1)Assigns values to special function registers, initializes the device;

    (2)Respond to the device request of the host to complete the control of the device;

    (3)Device enumeration, data transmission, standard host request and other actions will apply to the microcontroller interrupt, respond to these interrupts to ensure the normal work of the USB chip;

    (4)Configure and control the endpoints of sending and receiving data to realize the correct sending and receiving of data;

    (5)Control the peripheral circuit to ensure the normal operation of the equipment。

    2.3 Firmware program framework

    Cypress's official website provides a framework and a wealth of information for designers to develop firmware. Based on these frameworks, designers can add the appropriate code in place to fulfill specific user requirements, allowing USB firmware to complete and implement relevant designs。

    The firmware framework controls and USES USB transport through a task loop that initializes all device internal state variables, then calls the user initialization function TD_Init (), followed by a reenumeration, after which the firmware program begins task scheduling. The main tasks are the user task function TD_Poll (), standard device requests, and pending events. The TD_Init () function needs to define the initialization of global variables and parameters, and set the clock frequency, transmission direction, endpoint selection, and endpoint depth of Slave FIFO. The TD_Poll () function implements the scheduling and implementation of the task, including the main part of the user's expected work task, through the main loop is constantly called, this design endpoint works for automatic read and write, so this function has no corresponding Settings。

    3 Upper computer human-machine interface design

    3.1 Application development

    USB data cable acquisition system has many applications and wide fields. The development of interface program is different from the special requirements of other parts. Users generally hope that the interface can realize the functions of device management and data processing and be as intuitive and simple as possible. From the user's needs in the upper computer interface has the following ideas:

    (1)The role of upper computer is generally assumed by PC, working in the Windows operating system, so the design of upper computer interface needs the development tools under the Windows platform, such as VB, VS, LabVIEW, DELPHI, etc., this design USES Visual Studio 2010 (VS2010)。

    (2)The application software adopts the dialog box program interface developed on the basis of MFC framework. MFC is short for Microsoft base Class Library and encapsulates most of the Windows API functions. In essence, MFC class library is the interface between C++ language and Windows operating system. MFC programming is to select the appropriate class in the class library and realize corresponding functions by calling the member functions in the class. Using the MFC framework program interface makes it easier for users to learn and become familiar with the use of the program。

    (3)By using the CyAPI control function class library in the development kit provided by Cypress, on the basis of the universal USB driver of Cypress, cyAPi. h and Cyapi. lib are added to the interface project of VS2010 to call the USB device control function and complete the USB transmission task.

    3.2 Introduction to Functional Modules

    The basic process of a Windows application is to interact with commands issued by the user and then output the results of the interaction to the screen. This process requires a user interface, a dialog box, a window that can receive messages, feedback messages, be moved, and be closed. The modules of the interface are divided according to the functional requirements of users. The whole interface is divided into four parts: setting area, device area, path saving area and execution area。

    The setting area selects the endpoint of the USB device, and sets the maximum size of each packet transmission, the initial value of transmission and the stop in case of error. The drop-down menu in the device area selects the USB device connected to the host computer and refreshes the program. Click the button to select the file storage path. The execution area can start and stop USB transfer tasks, reset USB devices, and view information during USB task execution。

    4 Use of USB device drivers

    4.1 An introduction to the driver

    An application needs to use a driver as a software interface when it accesses a hardware device. The driver lets the application mask the physical connection and underlying protocol of the specific device when accessing the hardware device. USB bus device drivers follow the Win32 driver model WDM as defined by Microsoft, generally with the extension.sys. The WDM driver is responsible for communication between the application and the operating system at a privileged level, such as a driver that responds to hardware interrupts and DMA transfers by allowing or preserving an application's access to the hardware. Developing a driver is the most difficult part of USB development, involves the most knowledge, and is implemented in a lower level. However, Cypress provides a set of universal drivers for EZ-USB chips, which can accomplish common USB tasks. Unless special USB capabilities are required in the project, a generic driver is usually used.

    4.2 Driver loading

    Windows USES the manufacturer ID and product ID in the USB device descriptor to find drivers that match the device. The INF file describes the connection between the driver and the VID and PID. When Windows finds that a new device is connected, it will scan all INF files that can be selected, and select the INF file that best matches the ID. If it cannot be found, the user needs to specify the address. Once the INF file is found, the driver executable is copied to the correct address, the driver is loaded into memory, and the normal I/O operation can be performed。

    5 The experimental results

    Verify the results of data collection, select the USB device in the upper computer program and input the start button characteristic value, click the start button, the external circuit or analog signal receives the start characteristic value packet, analyzes its parameters, and determines the experiment time and number according to the parameters in the start packet. After the system starts working, the data received by the upper computer will be directly stored in TXT file. It can be seen from the actual test that the data transmission is accurate and there is no data packet loss, confusion and other errors. The transmission rate can reach more than 30 MHz/s to meet the design requirements.

    6 conclusion

    Based on the research of data transmission and command control between the digital signal acquisition platform of external circuit and PC, this paper designs and implements the data transmission system of Slave FIFO based on USB bus technology, and makes a detailed research and analysis on the function and module of this system. USB controller CY7C68013 has been widely used in many data transmission fields. USB improves system reliability and scalability due to its flexible interface and programmable features. It is hoped that this paper can provide some reference and inspiration for the researchers of data acquisition and transmission.