introduction

EZ-USB is a USB interface device with intelligent core of cypress company. It integrates USB communication control engine and improved 8051 core. It has the characteristics of full speed, full sequence, easy development and soft configuration. It is the preferred device to design USB devices. EZ-USB serial interface engine can automatically complete the main USB protocol processing, simplifying the device firmware design. However, the software configuration and enumeration are related to Windows programming, windows PNP technology and the use of windows DDK tools, inf files and registry. Therefore, the software configuration mode and firmware loading technology of EZ-USB interface device are the key issues in the development of EZ-USB interface device.

1. EZ-USB processor

EZ-USB serial interface engine can automatically complete the USB protocol processing such as data receiving and sending control, bit filling, data encoding, CRC verification, PID packet decoding, etc. EZ-USB automatically enumerates when connecting, and establishes the default EZ-USB device. After successful enumeration for the first time, the 8051 kernel can be used to re enumerate the customized devices through soft configuration.

The built-in 8051 processor is improved compared with the standard 8051 processor. Taking AN2131QC as an example, the main improvements are as follows:

Independent address bus and data bus, the bus cycle is four clocks, the average speed is nearly three times higher;

Double data pointer and automatic pointer improve the efficiency of data exchange;

The extended interrupt system supports 13 interrupt sources and automatic interrupt vectors;

1 I2C interface, 2 UART interfaces and 24 configurable I / O ports;

Variable cycle MOVX instructions are suitable for the interface of high and low speed memory chips;

Three 16 bit built-in timer / counter, 256 byte internal register ram;

8 KB external RAM is integrated in the chip, and 8051 core needs to access this RAM area with MOVX instruction.

2. EZ-USB soft configuration features

2.1 soft configuration features

Soft configuration is the most important feature of EZ-USB. Soft configuration features allow unlimited upgrade or reconfiguration of devices. The external RAM integrated in EZ-USB chip can be used to load firmware. When the device is connected to the host, the firmware is loaded from the host and executed here instead of being solidified in ROM. Therefore, different firmware devices present different characteristics, such as device configuration, effective endpoint, working mode, device function, etc. can be reconfigured by changing the firmware to achieve the purpose of software configuration, which is the software configuration characteristics of EZ-USB.

2.2 configuration mode

Soft configuration can be realized in two ways: automatic configuration and command configuration.

Automatic configuration means that when the device is connected, the firmware is automatically loaded to the device by a special loading driver. In this way, the firmware should be bundled in the loading driver, and the firmware and the loading driver should correspond one by one. When the firmware is modified, the loading driver should be regenerated and re installed. After the firmware is loaded, it should be re enumerated to create a custom USB device. If the device is not re installed, the host cannot find the device.

Command configuration refers to loading firmware to device through command operation in application program. This method does not need special loading driver, and can load any firmware at any time. After the firmware is loaded, there is no need to re enumerate. The EZ-USB kernel responds to the host request, which simplifies the firmware design. When the command configuration mode is adopted, the firmware loading code should be written in the application program. The firmware loading code mainly completes the following operations:

Extract effective firmware code from Intel hex format file;

Request EZ-USB to reset 8051 core;

The firmware is downloaded from EZ-USB and sent to the internal RAM of EZ-USB;

Request 8051 kernel to EZ-USB to leave reset state;

⑤ Set EZ-USB peripheral interface and alternate function.

3. Development method of EZ-USB interface device

The general steps and contents of USB device development are shown in Figure 1. The device oriented firmware mainly includes device descriptor information, device function code and communication control function code. Device description information describes the general characteristics and configuration of USB devices, such as device category, interface configuration, vid and PID. When the host enumerates devices, it needs to obtain the USB device descriptor, so as to obtain the device configuration information and related driver information. Users can change the device characteristics by modifying the descriptors in the firmware. The equipment function code is determined by the functional requirements of the equipment. Communication control function code performs host request analysis processing and data exchange processing functions.

The device driver provides the interface for the user to access the device. The development system provides the general device driver of the manufacturer. Users can also customize it with the relevant driver development tools. The customized device driver should conform to WDM driver specification. If the automatic configuration mode is adopted, EZ-USB development system provides a loading driver development template, which is easy to develop. Using command configuration mode requires the user to write firmware loading code in the application program.

The driver is usually installed through INF file, which binds the device’s vid and PID to the device driver, specifies the path to store the driver, and provides information about the driver’s registration and display. Therefore, when Windows detects the connection of EZ-USB device, it can automatically load the device driver into the system environment according to the registry.

4. Design examples

A universal EZ-USB interface module is developed by using AN2131QC. The software and hardware resources of this general module are all open, and test drivers and firmware samples are configured. Using this general module is just like using an IC chip. A special EZ-USB interface device can be formed by slightly modifying the device description information and INF file and adding the device function code.

4.1 firmware design

The firmware of general EZ-USB module includes descriptor table and USB communication test program. Descriptor table is a set of structured information that conforms to the USB specification and describes the characteristics of the device. Given different values of variables, the device presents different characteristics. When the device is connected, the host requests the device to provide a descriptor table, so the descriptor table is a part of the firmware. Five descriptor tables are defined in this general module, and the main parameters of each descriptor are listed in Table 1.

Table 1 general EZ-USB interface module descriptor and main parameters

Configuration characteristics, interface device development method and application of EZ-USB processor

The firmware in this general module is only used for EZ-USB communication test, device driver and firmware loading demonstration. It is found that there are two points in firmware design.

① Adoption ezusb.sys When using the general driver, the host should receive the data from the device in the way of query. If the host can not receive the data uploaded by the device, it will wait for a long time, or even crash. In the design of this paper, the way to solve this problem is that the data upload and download operations occur in pairs. Every time the host transmits a packet, the device uploads a packet. At this time, if the device has data upload, the data will be put into the upload packet, otherwise an empty packet will be returned.

② When initializing, the corresponding endpoint buffer should be cleared once. Otherwise, the first transmission error may occur, which may be due to insufficient reset or internal RAM power down delay. In practice, it is found that the data in EZ-USB ram remains unchanged after a long period of power failure.

4.2 generating device drivers

The general device driver provided by the manufacturer can be used to drive the device directly. But the general device driver can only perform some standard USB device request and data transfer, and only support query mode to communicate with the device. If it can’t meet the needs of users, users can expand the template and use WDM DDK to generate driver again. The general driver is used in the general module Ezusb.sys . It adopts the query mode, and makes the upload and download appear correspondingly, with good real-time performance, which can meet the requirements of general equipment.

4.3 generate load driver

When the automatic configuration mode is adopted, the firmware loading driver can be generated according to the template provided by EZ-USB development system.

The firmware loading in the general module adopts command configuration mode. The operation flow is shown in Figure 2, which mainly defines the following four functions to complete the firmware loading.

Read_ Intel_ Hex () reads the firmware code from the hex file in Intel format to the buffer.

Hex_ To_ Bin () removes the format description part of hex file in Intel format and converts it into pure firmware code.

Download_ Bin() ez-usb8051 kernel reset, firmware loaded to device, 8051 kernel reset and run firmware. Before loading firmware, make ez-usb8051 kernel into reset state, and then load firmware. After loading, make EZ-USB out of reset state and start to run firmware. The three operations share the same function and are distinguished by passing different parameters.

Set_ Interfacealt() sets EZ-USB interface number and alternate function value to establish communication pipeline.

4.4 install driver

The driver must be properly loaded into the windows environment for it to work. Edit the INF file to bind the vid and PID of the first enumerated device to the firmware loading driver, and bind the vid and PID of the re enumerated device to the device driver. Set the path of the driver to C: and set the displayed driver string information. Restart the system and press the prompt to complete the installation process.

4.5 interface between application program and device

The test program of general EZ-USB module provides two ways to access EZ-USB devices. One is to call the access device directly through I / O control, open the device with the function of createfile() and communicate with the device with the function of deviceiocontrol(); the other is to encapsulate the complex access function as DLL, which provides users with a more concise way to access peripherals.

5. Conclusion

Using general EZ_ USB interface module, intelligent sound intensity measurement system and precision CNC engraving machine are developed successfully. The equipment has stable performance and short development cycle.

Editor in charge: GT

Leave a Reply

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