The main control chip of the system adopts 32-bit high-performance embedded ARM microprocessor S3C44B0X, and the USB dedicated control chip is USBN9603. USBN9603 has 7 built-in FIFO ports, including 1 bidirectional control port, 3 sending ports and 3 receiving ports, each with 64 bytes.
The interface circuit between USB controller and S3C44B0X is shown in Figure 1. The USB controller is designed as Bank2, that is, the nGCS2 bank selection line is used as the chip select line of USBN9603, and the chip select address of the chip is 0x4000000. This article adopts a parallel data interface, and the lower 8-bit data lines D0~D7 of the two chips are connected to transmit communication data in parallel. Both MODE0 and MODE1 pins are grounded, and USBN9603 is configured as non-multiplexed mode. Since this working mode requires address line A0 as the selection line for accessing the USBN9603 on-chip registers DATA_IN, DATA_OUT and ADDR registers, it is necessary to connect A18 in the 32-bit address bus to A0 of the USB controller. When reading and writing USBN9603, it is divided into two bus cycles: first, set the address line A0 high, that is, set the bus address to 0x4040000, and write the address of the register to be accessed from the data line D[0:7], so that the address is sent to the chip in the first bus cycle; then, in the second cycle, set A0 low, that is, set the bus address to 0x4000000, and read and write D[0:7] to realize the read and write operation of the register. The entire USB communication process mainly handles various interrupt events including receiving and sending data. Connect the INT pin of USBN9603 to the external interrupt EINT0 pin of S3C44B0X, and set the USB interrupt to the vector interrupt request mode. Since the DMA mode is not used, DACK needs to be set high, and the DMA request line DRQ is suspended. The USB cable has 4 wires, D+ and D- are USB differential signal lines, and the other two are 5V power line and ground line. USBN9603 supports low-speed and full-speed USB communication. Connect a 1.5KΩ pull-up resistor to the D+ signal line to make it work in full-speed mode.
USB interface firmware implementation of monitor
The operation of the USB communication process starts from the host. According to the agreed timing, a token packet is first sent out, which contains information such as the operation type, direction, peripheral address and endpoint number. Then the data sender is specified in the token to send a data packet or indicate that there is no data transmission. The USB peripheral responds with a confirmation packet to indicate that the transmission is successful.
This paper adopts the master-slave USB communication structure. The host computer realizes the collection of ECG and blood pressure data and the initialization of system equipment by sending various pre-agreed protocol commands. The main data include the following: ECG data is in segments, each segment includes 32KB ECG data and 6B acquisition time information, and several segments are transmitted each time. The data volume is large and the transmission reliability requirement is also high; blood pressure data includes diastolic and systolic pressure and their acquisition time, a total of 10B. Since blood pressure monitoring is relatively frequent, blood pressure monitoring data within a period of time will be transmitted each time, and the data volume is also relatively large; download the upgraded version of the firmware and other file information. The data flow of these three types of data is relatively large, and the reliability requirements are relatively high. All three types of data use the block transmission channel type. In addition, each USB transmission must have a control transmission channel. Therefore, three channels are required, namely the control channel, BulkIN channel and BulkOUT channel.
USB firmware data structure
This article deals with the four types of descriptors that the host computer requires the device to transmit in the control transmission during the USB device configuration enumeration phase. They are hierarchically: device descriptor, configuration descriptor, interface descriptor and endpoint descriptor. Among them, higher-level descriptors will notify the host of any other lower-level descriptor information.
The device descriptor is the first descriptor that the host reads when the device is connected. Each device can only have one device descriptor, which contains the information of the entire device and the configuration number supported by the device, with a total of 18 fields. Each USB device has one or more configuration descriptors, which contain the power management of the device and the interface number supported by the device configuration. When the device receives the request to obtain the configuration descriptor, it transmits the configuration descriptor and all its interfaces, endpoints and other subsidiary descriptors to the host. This article sets a configuration, and its descriptor has a total of 8 fields. The interface contains a group of endpoints. This article sets an interface, and its descriptor has 9 fields, which provides the host computer with information such as the number and type of endpoints used by the device. Each interface descriptor has zero or more endpoint descriptors, which contain the information required for the host to communicate with the endpoint. Endpoint 0 is used as a control endpoint for communication, and endpoint 1 and endpoint 2 are block transfer modes respectively. Its descriptor contains information such as endpoint number, transfer direction, endpoint transfer type, and maximum transfer bytes of data packets.
USB firmware communication flow
After entering the communication module, the USB firmware framework process first calls the initialization routine to configure the USB interface device and put it into operation, and then enables the interrupt. The main function of USB communication is implemented in the interrupt service. The main program just waits in a loop for an exit button. When an interrupt signal is detected, it enters the interrupt service subroutine, determines the interrupt type based on the value of register MAEV, and enters the corresponding processing process.
The USB communication of the device mainly realizes the Bulk transmission function of ECG and blood pressure data. Based on the communication protocol of USB bus receiving and sending data, the monitor also has a specific application layer communication protocol. After receiving the user communication command, the firmware parses the control command and executes the corresponding routine. For example, when transmitting ECG and blood pressure data, the command 0x10, after receiving the command code 0x10, the firmware obtains the length of the data to be transmitted, the transmission flag of ECG or blood pressure selection and its record number from the command parameters, calls GetRecordData() according to the record number, searches for data from the Flash storage area and stores it in the sending buffer of BulkState. If ECG data is transmitted, the acquisition time of the ECG data segment must be obtained through GetTIme(). After all the data to be transmitted are ready, the transmission begins. Since the maximum buffer of Bulk transmission is 64B, 64B data is sent first, and then the host computer is judged in the TX_EV routine whether it is received successfully. If successful, the next batch of block input transactions is transmitted, otherwise it needs to be retransmitted. The above process is repeated until the data is sent.
USB firmware module routines
initialization
The initialization routine of the USB interface includes the initialization operation of the USBN9603 chip and the initialization of user variables, and then the device enumeration operation begins. During the initialization phase, the firmware needs to operate the registers of the USBN9603 in strict order.
USB device enumeration process
Connect the system's USB cable to a USB port (hub or host root hub), and the device is powered on; there are two 15KΩ pull-up resistors between the USB D+ and D- data lines and the connected hub port or host root hub. At this time, the pull-up resistor will cause the level on the data signal line to rise, notifying the hub that a new device has been connected; then, the hub uses the interrupt channel to report the event to the host. When a new device is indeed connected, the host sends a Set_Port_Feature request to the hub connected to the device, causing the hub to send a USB hardware reset command to the port for 10ms, and then identify the speed of the device. At this point, the device has completed the initialization operation. When the host proves that the device has left the reset state, it starts USB control transmission on the default channel of endpoint 0 and enters the enumeration phase.
USB interface circuit design for monitor
The main control chip of the system adopts 32-bit high-performance embedded ARM microprocessor S3C44B0X, and the USB dedicated control chip is USBN9603. USBN9603 has 7 built-in FIFO ports, including 1 bidirectional control port, 3 sending ports and 3 receiving ports, each with 64 bytes.
The interface circuit between USB controller and S3C44B0X is shown in Figure 1. The USB controller is designed as Bank2, that is, the nGCS2 bank selection line is used as the chip select line of USBN9603, and the chip select address of the chip is 0x4000000. This article adopts a parallel data interface, and the lower 8-bit data lines D0~D7 of the two chips are connected to transmit communication data in parallel. Both MODE0 and MODE1 pins are grounded, and USBN9603 is configured as non-multiplexed mode. Since this working mode requires address line A0 as the selection line for accessing the USBN9603 on-chip registers DATA_IN, DATA_OUT and ADDR registers, it is necessary to connect A18 in the 32-bit address bus to A0 of the USB controller. When reading and writing USBN9603, it is divided into two bus cycles: first, set the address line A0 high, that is, set the bus address to 0x4040000, and write the address of the register to be accessed from the data line D[0:7], so that the address is sent to the chip in the first bus cycle; then, in the second cycle, set A0 low, that is, set the bus address to 0x4000000, and read and write D[0:7] to realize the read and write operation of the register. The entire USB communication process mainly handles various interrupt events including receiving and sending data. Connect the INT pin of USBN9603 to the external interrupt EINT0 pin of S3C44B0X, and set the USB interrupt to the vector interrupt request mode. Since the DMA mode is not used, DACK needs to be set high, and the DMA request line DRQ is suspended. The USB cable has 4 wires, D+ and D- are USB differential signal lines, and the other two are 5V power line and ground line. USBN9603 supports low-speed and full-speed USB communication. Connect a 1.5KΩ pull-up resistor to the D+ signal line to make it work in full-speed mode.
USB interface firmware implementation of monitor
The operation of the USB communication process starts from the host. According to the agreed timing, a token packet is first sent out, which contains information such as the operation type, direction, peripheral address and endpoint number. Then the data sender is specified in the token to send a data packet or indicate that there is no data transmission. The USB peripheral responds with a confirmation packet to indicate that the transmission is successful.
This paper adopts the master-slave USB communication structure. The host computer realizes the collection of ECG and blood pressure data and the initialization of system equipment by sending various pre-agreed protocol commands. The main data include the following: ECG data is in segments, each segment includes 32KB ECG data and 6B acquisition time information, and several segments are transmitted each time. The data volume is large and the transmission reliability requirement is also high; blood pressure data includes diastolic and systolic pressure and their acquisition time, a total of 10B. Since blood pressure monitoring is relatively frequent, blood pressure monitoring data within a period of time will be transmitted each time, and the data volume is also relatively large; download the upgraded version of the firmware and other file information. The data flow of these three types of data is relatively large, and the reliability requirements are relatively high. All three types of data use the block transmission channel type. In addition, each USB transmission must have a control transmission channel. Therefore, three channels are required, namely the control channel, BulkIN channel and BulkOUT channel.
USB firmware data structure
This article deals with the four types of descriptors that the host computer requires the device to transmit in the control transmission during the USB device configuration enumeration phase. They are hierarchically: device descriptor, configuration descriptor, interface descriptor and endpoint descriptor. Among them, higher-level descriptors will notify the host of any other lower-level descriptor information.
The device descriptor is the first descriptor that the host reads when the device is connected. Each device can only have one device descriptor, which contains the information of the entire device and the configuration number supported by the device, with a total of 18 fields. Each USB device has one or more configuration descriptors, which contain the power management of the device and the interface number supported by the device configuration. When the device receives the request to obtain the configuration descriptor, it transmits the configuration descriptor and all its interfaces, endpoints and other subsidiary descriptors to the host. This article sets a configuration, and its descriptor has a total of 8 fields. The interface contains a group of endpoints. This article sets an interface, and its descriptor has 9 fields, which provides the host computer with information such as the number and type of endpoints used by the device. Each interface descriptor has zero or more endpoint descriptors, which contain the information required for the host to communicate with the endpoint. Endpoint 0 is used as a control endpoint for communication, and endpoint 1 and endpoint 2 are block transfer modes respectively. Its descriptor contains information such as endpoint number, transfer direction, endpoint transfer type, and maximum transfer bytes of data packets.
USB firmware communication flow
After entering the communication module, the USB firmware framework process first calls the initialization routine to configure the USB interface device and put it into operation, and then enables the interrupt. The main function of USB communication is implemented in the interrupt service. The main program just waits in a loop for an exit button. When an interrupt signal is detected, it enters the interrupt service subroutine, determines the interrupt type based on the value of register MAEV, and enters the corresponding processing process.
The USB communication of the device mainly realizes the Bulk transmission function of ECG and blood pressure data. Based on the communication protocol of USB bus receiving and sending data, the monitor also has a specific application layer communication protocol. After receiving the user communication command, the firmware parses the control command and executes the corresponding routine. For example, when transmitting ECG and blood pressure data, the command 0x10, after receiving the command code 0x10, the firmware obtains the length of the data to be transmitted, the transmission flag of ECG or blood pressure selection and its record number from the command parameters, calls GetRecordData() according to the record number, searches for data from the Flash storage area and stores it in the sending buffer of BulkState. If ECG data is transmitted, the acquisition time of the ECG data segment must be obtained through GetTIme(). After all the data to be transmitted are ready, the transmission begins. Since the maximum buffer of Bulk transmission is 64B, 64B data is sent first, and then the host computer is judged in the TX_EV routine whether it is received successfully. If successful, the next batch of block input transactions is transmitted, otherwise it needs to be retransmitted. The above process is repeated until the data is sent.
USB firmware module routines
initialization
The initialization routine of the USB interface includes the initialization operation of the USBN9603 chip and the initialization of user variables, and then the device enumeration operation begins. During the initialization phase, the firmware needs to operate the registers of the USBN9603 in strict order.
USB device enumeration process
Connect the system's USB cable to a USB port (hub or host root hub), and the device is powered on; there are two 15KΩ pull-up resistors between the USB D+ and D- data lines and the connected hub port or host root hub. At this time, the pull-up resistor will cause the level on the data signal line to rise, notifying the hub that a new device has been connected; then, the hub uses the interrupt channel to report the event to the host. When a new device is indeed connected, the host sends a Set_Port_Feature request to the hub connected to the device, causing the hub to send a USB hardware reset command to the port for 10ms, and then identify the speed of the device. At this point, the device has completed the initialization operation. When the host proves that the device has left the reset state, it starts USB control transmission on the default channel of endpoint 0 and enters the enumeration phase.
Previous article:Development of a bioimpedance analyzer based on USB2.0 interface
Next article:Learning STM32 general timer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- [Sipeed LicheeRV 86 Panel Review] 11- Audio Recording and Playback Test
- Reduce the allegro brd layout file version from 17.2 to 16.6
- UWB Market Outlook
- FPGA Design Rules
- Can single-threaded applications develop asynchronous tasks? How does the ACE JS framework do it?
- Protel/AD design software removes text
- 【FAQ】How to quickly understand LP50xx devices?
- 【GD32L233C-START Review】6. Make a simple host computer for HID devices
- Inventory of common problems and solutions of crystal oscillators
- MicroPython Hands-on (18) - Sound and light sensor on the control board