Design of USB dual-mode interface based on CH375A control chip

With the reduction of embedded processor design power consumption, more and more devices are developing towards miniaturization and integration. The streamlining of appearance and the increase of functions put forward new requirements for the compatibility and versatility of peripheral interface functions. , How to realize the most functions through the least peripheral interfaces in a limited space is one of the new issues facing the design of embedded systems. Compared with the research and development of new communication protocols, it is more practical to make full use of the existing multiple communication modes for connecting to the U. This article proposes a design idea and implementation method for the multiplexing of USB interface working modes.

Author: Xiong Xuehui

1 Design background

With the reduction of embedded processor design power consumption, more and more devices are developing towards miniaturization and integration. The streamlining of appearance and the increase of functions put forward new requirements for the compatibility and versatility of peripheral interface functions. , How to realize the most functions through the least peripheral interfaces in a limited space is one of the new issues facing the design of embedded systems. Compared with the research and development of new communication protocols, it is more practical to make full use of the existing multiple communication modes for connecting to the U. This article proposes a design idea and implementation method for the multiplexing of USB interface working modes.

2 Design principle of dual-mode interface

Universal Serial Bus (USB) to LJ is one of the most widely used interfaces in the current application field. The main advantages are fast speed, low power consumption, support for hot swapping and good compatibility. According to the design of the USB communication protocol, the USB interface supports two-way communication, but only one host can control the communication process. Therefore, there are two working modes for USB devices: USB. Host mode and USB. Device mode.

The device working in the USB-Host mode includes a USB host controller, and can control the completion of the data transmission between the host and the USB device. The data and command transmission of the USB system are all started by the USB-Host device. Common ones are Computers and other devices with USB master chips. The devices that work in the USB-Device mode can be divided into two types: USB hubs and USB functional devices. Common USB flash drives, MP3 and mobile hard drives are all USB functional devices. Each USB functional device contains configuration information describing its functions and resource requirements, USB. The Host device must be configured before use. The communication interaction mode of the two modes is shown in Figure 1.

Design of USB dual-mode interface based on CH375A control chip

In traditional data communication applications, due to the single function of the device, it is possible to set the interface as Host or Device fixedly to meet the actual needs. However, in the application of embedded systems, it is often necessary to access the USB device and communicate with the computer. In this case, it is necessary to implement two working modes of Host and Device ON the same interface.

3 Design and realization of dual working mode

3.1 Hardware design

The design selection supports USB at the same time. Host and USB. The CH375A in Device mode is used as an interface control chip. The chip has an 8-bit bidirectional data bus and complete read/write and chip selection control signals. It has a full-speed USB-Host host interface, supports dynamic switching of host and device modes, and is compatible with USB 2.0 protocol.

In the USB. In HostI mode, CH375A provides a serial communication mode, which is connected to the embedded main control chip through serial input, output and interrupt output; in USB. In DeviceT mode, CH375A has built-in low-level protocol in USB communication, which can adopt convenient built-in firmware mode or flexible external firmware mode, which fully meets the design requirements.

Since the physical interface is multiplexed, a parallel data interface is used to communicate with the main control chip when connecting. The two modes cannot work at the same time, and the interface cannot automatically identify the working mode of the access device. Therefore, the master-slave device identification needs to be identified by the embedded main control chip based on external input. The hardware connection diagram is shown in Figure 2.

Design of USB dual-mode interface based on CH375A control chip

The input and output interface symbols in the figure are the signals interconnected between CH375A and the main control chip. In order to enhance the USB signal strength, equal-length traces are used for differential signals when designing the circuit, and common mode inductors are connected in series to reduce crosstalk.

3.2 Software design

When the device is powered on, it is in the “unenabled USB device” mode by default, and the main control chip needs to specify a new working mode according to the external input. When the device works on USB. In the Host mode, it is necessary to actively detect and initialize the connected devices. The specific process is shown in Figure 3.

Design of USB dual-mode interface based on CH375A control chip

The program uses a query method to detect device access. After detecting the presence of the device, it first obtains the device interrupt status and clears the interrupt request, initializes the device and queries the storage characteristics of the device, and finally obtains the device capacity information and reads and writes the device. Some functional function codes are as follows:

CheckExist(); //Test the working status of CH375A;
SetUSBMode (USB MODE5); //Set CH375A to work in Host mode;
GetUSBStatus(); //Initialize interrupt status;
USB_DISK_INIT(); //Initialize the USB device;
USB_DISK_INQUIRY() //Query the characteristics of USB storage devices
GetUSBDiskSize(); //Get device capacity;
. ..
WriteUSBCmd (int8 x); // write command to the device;
WriteUSBData (int8 x); //Write data to the device;
. ..
When the device works on USB. In Device mode, the device itself becomes a USB device that needs to be controlled by the host, and the process is shown in Figure 4 after being connected to the upper computer.

Design of USB dual-mode interface based on CH375A control chip

At this time, the communication mode between the device and the host computer adopts the request plus response method, where the host computer actively requests data, and the device passively responds to uploading data. Some functional function codes are as follows:

USB_Reset_ALL(): // Device reset;
CheckExist(); Test the working status of CH375A;
SetUSBMode (USB_MODE2); // Set CH375A to work in the internal firmware Device mode;
GetUSBStatus(); //Initialize interrupt status:
USB Open Device (); // The device must be opened before communication:
USB_GetFirmwareInfo(); //Get the debug firmware program version, and cancel the unfinished upload data block
. ..

When the device needs to switch between Host mode and Device mode, the main control chip accepts the mode switch signal input from the outside, and then sends the mode switch command to CH375A. The process is shown in Figure 5.

Design of USB dual-mode interface based on CH375A control chip

To switch between different modes, first switch to the “unenabled USB device” mode, which is the default mode after power-on reset. After a certain delay, switch to the required working mode. If you consider to further ensure the stability of the system, you can also add a reset command before the delay. The specific functions are as follows:

SetUSBMode (USB_MODE0); // Set CH375A to not enable device mode;
Delay (1000): // Delay
SetUSBMode (USB_MODEn); // Set CH375A as the target mode;
. …

4 Conclusion

Practice has proved that the configuration of the USB interface according to the procedure stipulated by the program works normally on the debug board, and there is no error in the process of switching between the two modes. Due to chip limitation, this system can only work in USB1.1 mode at present, how to further improve the data transmission rate under the two working modes will be the focus of the next step of research.

About the Author:

Xiong Xuehui (1984-), male, 61938 troops, assistant engineer, research direction: embedded system design and data security. Contact address: No. 2, Banbi Street South Road, Haidian District, Beijing, China People’s Liberation Army 61938 Unit Data Backup Room (100089).

Author: Xiong Xuehui

1 Design background

With the reduction of embedded processor design power consumption, more and more devices are developing towards miniaturization and integration. The streamlining of appearance and the increase of functions put forward new requirements for the compatibility and versatility of peripheral interface functions. , How to realize the most functions through the least peripheral interfaces in a limited space is one of the new issues facing the design of embedded systems. Compared with the research and development of new communication protocols, it is more practical to make full use of the existing multiple communication modes for connecting to the U. This article proposes a design idea and implementation method for the multiplexing of USB interface working modes.

2 Design principle of dual-mode interface

Universal Serial Bus (USB) to LJ is one of the most widely used interfaces in the current application field. The main advantages are fast speed, low power consumption, support for hot swapping and good compatibility. According to the design of the USB communication protocol, the USB interface supports two-way communication, but only one host can control the communication process. Therefore, there are two working modes for USB devices: USB. Host mode and USB. Device mode.

The device working in the USB-Host mode includes a USB host controller, and can control the completion of the data transmission between the host and the USB device. The data and command transmission of the USB system are all started by the USB-Host device. Common ones are Computers and other devices with USB master chips. The devices that work in the USB-Device mode can be divided into two types: USB hubs and USB functional devices. Common USB flash drives, MP3 and mobile hard drives are all USB functional devices. Each USB functional device contains configuration information describing its functions and resource requirements, USB. The Host device must be configured before use. The communication interaction mode of the two modes is shown in Figure 1.

Design of USB dual-mode interface based on CH375A control chip

In traditional data communication applications, due to the single function of the device, it is possible to set the interface as Host or Device fixedly to meet the actual needs. However, in the application of embedded systems, it is often necessary to access the USB device and communicate with the computer. In this case, it is necessary to implement two working modes of Host and Device on the same interface.

3 Design and realization of dual working mode

3.1 Hardware design

The design selection supports USB at the same time. Host and USB. The CH375A in Device mode is used as an interface control chip. The chip has an 8-bit bidirectional data bus and complete read/write and chip selection control signals. It has a full-speed USB-Host host interface, supports dynamic switching of host and device modes, and is compatible with USB 2.0 protocol.

In the USB. In HostI mode, CH375A provides a serial communication mode, which is connected to the embedded main control chip through serial input, output and interrupt output; in USB. In DeviceT mode, CH375A has built-in low-level protocol in USB communication, which can adopt convenient built-in firmware mode or flexible external firmware mode, which fully meets the design requirements.

Since the physical interface is multiplexed, a parallel data interface is used to communicate with the main control chip when connecting. The two modes cannot work at the same time, and the interface cannot automatically identify the working mode of the access device. Therefore, the master-slave device identification needs to be identified by the embedded main control chip based on external input. The hardware connection diagram is shown in Figure 2.

Design of USB dual-mode interface based on CH375A control chip

The input and output interface symbols in the figure are the signals interconnected between CH375A and the main control chip. In order to enhance the USB signal strength, equal-length traces are used for differential signals when designing the circuit, and common mode inductors are connected in series to reduce crosstalk.

3.2 Software design

When the device is powered on, it is in the “unenabled USB device” mode by default, and the main control chip needs to specify a new working mode according to the external input. When the device works on USB. In the Host mode, it is necessary to actively detect and initialize the connected devices. The specific process is shown in Figure 3.

Design of USB dual-mode interface based on CH375A control chip

The program uses a query method to detect device access. After detecting the presence of the device, it first obtains the device interrupt status and clears the interrupt request, initializes the device and queries the storage characteristics of the device, and finally obtains the device capacity information and reads and writes the device. Some functional function codes are as follows:

CheckExist(); //Test the working status of CH375A;
SetUSBMode (USB MODE5); //Set CH375A to work in Host mode;
GetUSBStatus(); //Initialize interrupt status;
USB_DISK_INIT(); //Initialize the USB device;
USB_DISK_INQUIRY() //Query the characteristics of USB storage devices
GetUSBDiskSize(); //Get device capacity;
. ..
WriteUSBCmd (int8 x); // write command to the device;
WriteUSBData (int8 x); //Write data to the device;
. ..
When the device works on USB. In Device mode, the device itself becomes a USB device that needs to be controlled by the host, and the process is shown in Figure 4 after being connected to the upper computer.

Design of USB dual-mode interface based on CH375A control chip

At this time, the communication mode between the device and the host computer adopts the request plus response method, where the host computer actively requests data, and the device passively responds to uploading data. Some functional function codes are as follows:

USB_Reset_ALL(): // Device reset;
CheckExist(); Test the working status of CH375A;
SetUSBMode (USB_MODE2); // Set CH375A to work in the internal firmware Device mode;
GetUSBStatus(); //Initialize interrupt status:
USB Open Device (); // The device must be opened before communication:
USB_GetFirmwareInfo(); //Get the debug firmware program version, and cancel the unfinished upload data block
. ..

When the device needs to switch between Host mode and Device mode, the main control chip accepts the mode switch signal input from the outside, and then sends the mode switch command to CH375A. The process is shown in Figure 5.

Design of USB dual-mode interface based on CH375A control chip

To switch between different modes, first switch to the “unenabled USB device” mode, which is the default mode after power-on reset. After a certain delay, switch to the required working mode. If you consider to further ensure the stability of the system, you can also add a reset command before the delay. The specific functions are as follows:

SetUSBMode (USB_MODE0); // Set CH375A to not enable device mode;
Delay (1000): // Delay
SetUSBMode (USB_MODEn); // Set CH375A as the target mode;
. …

4 Conclusion

Practice has proved that the configuration of the USB interface according to the procedure stipulated by the program works normally on the debug board, and there is no error in the process of switching between the two modes. Due to chip limitation, this system can only work in USB1.1 mode at present, how to further improve the data transmission rate under the two working modes will be the focus of the next step of research.

About the Author:

Xiong Xuehui (1984-), male, 61938 troops, assistant engineer, research direction: embedded system design and data security. Contact address: No. 2, Banbi Street South Road, Haidian District, Beijing, China People’s Liberation Army 61938 Unit Data Backup Room (100089).

The Links:   STK621-061 LQ070T5DR06