Embedded USB Host Design and Application Based on ARM and µCOS-II
2026-04-06 06:21:39··#1
Abstract: This paper studies and designs an embedded USB host, elucidating its working mechanism and implementation architecture, and presenting its specific implementation on hardware and software platforms. First, a real-time operating system (RTOS) – µC/OS-II – is ported to the Samsung ARM7 processor S3C44B0X. Then, considering the specific needs of medical devices, the USB host function is implemented using the SL811HS chip. Based on this, embedded drivers for USB interface EPSON printers and mass storage devices (USB flash drives, portable hard drives) are developed. Keywords: Universal Serial Bus (USB), SL811HS, µC/OS-II, Mass Storage, Printing, Language 1 Introduction Typically, printers, mass storage devices, etc., are driven by ordinary PCs. Since many measurement and control, medical, and other systems require data storage and printing, developing embedded drivers for these devices is of great practical value. Currently, various embedded devices primarily use floppy disks for storage and parallel port printing, but their storage capacity and data transfer speed are far behind the needs of current embedded systems. Therefore, developing drivers for USB interface-based embedded mass storage devices and printers has become an urgent task. USB (Universal Serial Bus) is a new serial interface technology that has gradually gained widespread application in the PC field in recent years. Its advantages, such as good versatility, strong real-time performance, diverse transmission methods, low cost, and ease of expansion and use, have made it popular among many hardware manufacturers, leading to a surge of various types of USB devices entering the market. USB communication requires communication between the host and the peripheral; each communication is initiated by the host, and the peripheral passively executes the commands sent by the host. The USB mobile devices available and used on the market are all USB peripherals, such as USB external hard drives, USB digital cameras, and printers. These devices typically can only exchange files and data with a PC; without a PC, these devices cannot exchange data. However, not every location has a PC or is suitable for using one, thus the industry and users demand the embedding of USB hosts—that is, the development and design of embedded USB hosts. Based on the specific needs of the medical instrument (ELISA reader), we ported the real-time operating system (RTOS) – µC/OS-II – onto Samsung's ARM7 processor S3C44B0X and wrote a low-level driver based on the USB host controller chip SL811. To save the data detected by the ELISA reader to peripherals (such as USB flash drives and external hard drives), we studied the corresponding file system and UFI transmission protocol, realizing read and write operations on massive storage devices with the FAT file system. Simultaneously, to print the ELISA reader's detection results, we studied the ESC/P printing language of EPSON printers and implemented embedded printer drivers for EPSON C63 series, C65 series, and ME1 printers based on USB communication. 2. Hardware Design of the Embedded USB Host The core hardware platform of the ELISA reader is Samsung's S3C44B0X (with a maximum clock speed of 66MHz), which integrates an ARM7TDMI core and an LCD controller, making it a microcontroller suitable for mid-range applications. System expansion includes hardware resources such as memory (8MB SRAM, 2MB NOR Flash), USB host/slave (SL811HS), and buttons. The USB hardware connection is shown in Figure 1. The SL811HS is an embedded USB Host/Slave chip from Cypress. It supports both full-speed and low-speed USB 1.1 devices. It provides the hardware interface for the USB host and the physical mechanism for bus management. It includes an on-chip SIE, a USB transmitter, and an on-chip root hub. Therefore, it meets the functional requirements of an embedded USB host system, namely, the host interface chip handles the sending and receiving of low-level physical data packets on the bus, detects bus status, and issues interrupt requests. Therefore, choosing the SL811HS as the USB interface chip for this system is appropriate. Figure 2: USB driver stack. As shown in Figure 2, the ARM determines the base address of the SL811HS through the Cs3 chip select. D0-D7 are multiplexed lines for data and address, and are distinguished by A0. When A0 is "0", the offset address is transmitted on D0-D7; otherwise, when A0 is "1", D0-D7 are used as data lines. 3 Software Design of Embedded USB Host3.1 Overall Software Framework of Embedded USB Host The core of the system's software platform is µC/OS-II, which is an open-source, preemptive multitasking real-time operating system kernel. Its performance is fully competitive with many commercial products and has been successfully applied in many systems. It is a kernel that has been proven to be stable and reliable in practice, and its core code is concise, simple and easy to learn. The functions provided by the USB host to the USB system are: (1) detecting the access and removal of USB peripherals; (2) managing the USB standard flow control between the host and peripherals; (3) enumerating peripherals; (4) managing the data flow between the host and peripherals; (5) collecting statistical information on system status and performance; (6) electrical interface between the host and peripherals, including power supply. The USB protocol defines a series of device types, including HID (Human Interface Device), Mass Storage, Audio, and Printing, to support different devices. Based on actual needs, we developed a USB-interface mass storage device and an embedded driver for an EPSON printer based on the ESC/P printing language. The specific driver stack is shown in Figure 2. This system supports hot-plugging, can identify the type of device plugged in, and calls the corresponding driver. 3.2 Implementation of the USB Mass Storage Class Protocol Framework The USB Mass Storage class is defined by the USB protocol for disk management and large-capacity data transfer. USB defines two mass storage transmission protocols: Buck-only Transport and Control/Bulk/Interrupt (CBI) Transport. Since most mass storage devices on the market currently use the former transmission protocol, data reading and writing are achieved through block transfer. The Command Block Wrapper (CBW) contains flag information, data length, and UFI commands. The UFI commands include a series of disk management commands such as formatting the disk, reading the disk, writing to the disk, and reading the disk capacity. Most portable storage devices use the FAT file system to manage files. The entire file system establishes a connection with the external disk via Mass Storage's UFI commands. The FAT file system roughly divides the data on the mass storage device into five parts: MBR (Master Boot Record), DBR (System Boot Record), FAT (File Allocation Table), FDT (File Directory Table), and DATA (Data Area). When a mass storage device with a USB interface is plugged in, the system reads the MBR and DBR to obtain basic file system information such as the number of bytes per sector, the number of sectors per cluster, and the number of FAT tables. The process of reading a file from the mass storage device after obtaining this basic information is shown in Figure 3. Since the process of writing and reading files is not significantly different, it will not be elaborated here. Figure 3 File Reading Flowchart 3.3 Printer Driver Design Based on ESC/P Printing Control Language EPSON printers are basically based on the ESC/P printing control language, and there is not much difference in the control language between different series of printers. Therefore, our driver program has strong versatility; the driver developed for EPSON's C63 series printers is fully compatible with the C65 series and ME1 printers. Programming manuals for various printer models can be downloaded from EPSON's development website. The programming manual provides a detailed introduction to various control commands, such as initializing the printer (ESC @), selecting the graphic mode (ESC(C nL nH m), setting the cell size (ESC(U nL nH m), and printing raster image commands (ESC . cvhm N1 Nh d1 ⋯dk), etc. EPSON printers offer two printing modes: one for printing text files (English letters, Arabic numerals, etc.), where sending the corresponding control command to the printer directly outputs the ASCII code of the content to be printed; and another for printing raster graphics, often used when printing tables, images, and Chinese characters. Here are some key API functions with explanations: `print_image_init ( void )`: Because the printer defaults to text mode after initialization, raster graphics must be initialized before printing. `print_image_command(unsigned int horiz_position, unsigned int verti_position, unsigned char rows, unsigned int columns, char ...` `color`: This function must be called at least once beforehand using `print_image_init()`, which sends a print command to the printer. The first and second input parameters are the horizontal and vertical coordinates of the print image; the third and fourth input parameters are the number of rows and columns of the print image, respectively (it's worth noting that C63 and C65 series printers can print a maximum of 16 lines at a time, while the EPSON M1 can only print 15 lines at a time); the fifth input parameter `color` selects the print color. After calling this function, simply sending the print data to the printer will print the image. Since printing text mode is essentially the same as printing graphics and is simpler, it will not be explained here. 3.4 USB Protocol Implementation This is the foundation of the entire USB software system, responsible for data transmission between the host and the device. Its code is contained in the file `sl811host.c`, and the API functions available for upper-layer drivers to call are mainly: EnumUsbDev(): This function mainly implements the function of enumerating devices. When a USB device is plugged in, the system calls this function to obtain the standard descriptor (interface, configuration, endpoint) of the device and identify whether it is a mass storage device or a printer. Setting the address (SetAddress), setting the configuration descriptor (SetDecriptor), setting the configuration value (SetConfiguration), and setting the interface (SetInterface) are also implemented in this function. BuckSend(): This function mainly implements the sending of data from the host to the device via block transfer; BuckReceive(): Block transfer receiving function; BuckSend() and BuckReceive() are the two most frequently scheduled functions because reading and writing to mass storage devices, sending control commands to printers, and printing data are all done through block transfer communication, which is achieved by calling these two functions. The functions for the processor to read and write a single register or data memory of the SL811HS are as follows: void SL811Write(char a, char d) {SL811_ADDR = a; SL811_DATA = d;} char SL811Read(char a) {SL811_ADDR = a; return (SL811_DATA); } These two functions are the cornerstone of data interaction between the ARM processor and the SL811 chip. All read and write operations on control registers and data memory can be implemented through these two functions. When continuous read and write operations are required in the SL811's memory, the following method can be used to speed up the read and write process: void SL811BufWrite(BYTE addr, BYTE *s, BYTE c) {SL811H_ADDR = addr; while (c—) SL811H_DATA = *s++; } 4. Conclusion Based on the real-time kernel µC/OS-II and the 32-bit RISC architecture ARM7 On the Core system board, we implemented an embedded USB host design and development, providing read/write and printing capabilities for the ELISA reader, a specific medical device. Testing showed that this system can read data from the mass storage device at speeds up to 750kB/s and write data at speeds up to 450kB/s. The printing function also fully meets system requirements, demonstrating stable and reliable performance and ease of use, making it a feasible and practical solution.