introduction
In-Circuit Programming (ICP) is a fast MCU programming method that is widely used. For the 8-bit MCU of Freescale Semiconductor that I use, the speed of in-circuit programming through the serial communication interface of the chip itself is much faster than programming using the MON08 or BDM interface that comes with the chip. In addition to programming using the serial communication interface, the speed of in-circuit programming using the USB interface is faster due to the increase in chips with built-in USB modules. At the same time, since USB power can be used, fewer cables are used.
However, I also found that most online programming systems include two parts: PC program and MCU program. When programming online, you need to run the PC program, but often you will encounter the situation that the PC program cannot run due to the change of the host or operating system platform. To solve this problem, I tried to implement the online programming function of the USB flash drive on the MCF51JM128 chip with USB module newly launched by Freescale Semiconductor: programming can be realized by directly inserting the target file like a USB flash drive, which saves the PC program and facilitates the actual use of users.
MCF51JM128 (hereinafter referred to as "JM128") is a Coldfire V1 core series microcontroller launched by Freescale Semiconductor in 2008. The main feature of this chip is that it contains an integrated USB controller that supports USB2.0 full-speed host, device and On-The-Go. This configuration generally appears in high-end microprocessors and rarely appears in other microprocessors. It can be said that it is a very competitive feature of JM128.
1 Design ideas
To realize the online programming function of the U disk-like method, the main work is to realize the U disk-like function of JM128. During the study period, the author participated in the development of the online programming system, and some existing functional modules can be used for reference. The main idea of this design is to judge whether to enter the online programming state through the status of a certain pin on the development board. If it enters, the USB module is initialized to complete the interaction with the U disk enumeration of the PC. JM128 constantly queries the PC for the operation of the U disk. The user can open the U disk and paste the target file at this time. JM128 receives the target code data packet while analyzing the data packet. If it meets the requirements, it will program the Flash. After the programming is completed, it will receive the next data packet. This kind of U disk can be called a "U disk-like" instead of a real U disk, because it does not have the same storage function as a U disk.
2 Software Design
The software part of the online programming system mainly includes the design of Mass Storage class protocol, FAT16 file system, S19 file parsing and Flash driver module. Mass Storage class protocol and FAT16 file system are used to realize the USB disk function and are the focus of software implementation. The writing of Flash driver code can refer to the "Flash Memory" section of the JM128 reference manual.
2.1 Implementation of Mass Storage Protocol
The Mass Storage class protocol needs to implement the following parts: first, in the device enumeration phase, provide Mass Storage-class protocol descriptors so that the host can identify the device as a mass storage device; second, in the data transmission phase, implement the Bulk-Only protocol; third, implement the SCSI command set.
2.1.1 Mass Storage Class Protocol Descriptor
The USB host obtains the device type and other information through the USB device descriptors obtained during the enumeration process, and establishes communication based on this information. These descriptors include: device descriptors, configuration descriptors, interface descriptors, and endpoint descriptors.
When the JM128 chip USB module is used as a device controller, there are 16 bidirectional endpoints. Each direction of each endpoint uses a double buffer to achieve the maximum transmission throughput. Three endpoints are used in this design. Endpoint 0 is a bidirectional control endpoint, which is used to control transmission. During the enumeration process, the USB host only interacts with this endpoint to obtain information. Endpoints 1 and 2 are used for Bulk-Only transmission: Endpoint 1 is an IN endpoint, which is used to transmit data to the PC; Endpoint 2 is an OUT endpoint, which is used to receive data sent by the PC. These are all reflected in the descriptor.
2.1.2 Implementation of bulk transfer protocol
When the device is identified as a Bulk-Only mass storage device, it enters bulk transfer mode. In this mode, all data between the USB host and the device is transmitted through Bulk-In and Bulk-Out, and no longer transmitted through the control endpoint.
In Bulk-Only transmission mode, three types of data are transmitted between the USB host and the device: CBW (Command Block Wrapper), CSW (Command Status Wrapper) and ordinary data. The command format in CBW complies with the SCSI transmission command set. The USB device needs to decompose the instructions contained in CBW and execute the corresponding commands, and return CSW reflecting the current command execution status to the host. The bulk-only transmission process of the USB device is shown in Figure 1.
2.1.3 Implementation of SCSI command set
SCSI has three word length commands: 6 bytes, 10 bytes, and 12 bytes. Microsoft Windows environment supports 12-byte commands. The SCSI command set includes operation commands for a variety of storage devices. For USB flash drives, not all SCSI commands need to be responded to and processed. The actual SCSI commands used are listed in Table 1.
2.2 Implementation of FAT16 file system
When the development board is plugged into the USB bus and enumerated successfully, the USB host will send the SCSI commands mentioned above. If the return results of these commands are correct, the host will then enter the file identification stage; if the file system information is wrong, the USB bus will be reset and communication will be terminated.
The FAT16 file system is used in this design. FAT stands for "file allocation table", which is a table used to record the location of files in the memory. Once the file allocation table is lost, the data in the memory cannot be used because it cannot be located. The disk of the FAT16 file system can be divided into a reserved area, a FAT area, a root directory area, and a data area. The first sector in the reserved area is called the boot sector, which contains key information for identifying the file system; the FAT area is used to store the file allocation table. Since the FAT table is very important, there is usually a backup with the same content after the FAT area; the root directory area stores directory entries, each of which is 32 bytes and records the information of a file or directory; the data area after the root directory area is the real location for storing file data or directories, occupying most of the data space in the memory.
The functions of this design are relatively fixed, and there is no need to implement a file system as complex as an ordinary USB flash drive. Functions such as file storage and dynamic creation/deletion can be omitted, which saves code space while implementing the functions. The author uses constant arrays to define the boot sector, FAT area, and root directory area.
The operating system allocates disk space by cluster. The FAT table is a list of data area cluster numbers that correspond one to one, reflecting the usage of all clusters. The FAT area structure is listed in Table 2. When designing the array of the FAT area, the author took simplification measures. Since there is no need to store the target S19 file and disk information in Flash, only the table items O and 1 of the FAT table array are set, and the remaining table items are cleared.
Conclusion
MCF51JM128 is a new MCU that integrates USB host, device and OTG functions. It is suitable for data acquisition, data exchange and other fields. It is a highly integrated chip. When using the characteristics of its integrated USB module to implement a USB-disk-like online programming system, the platform adaptability of the online programming system is improved, the usability is improved, and the development cost of the online programming system is reduced. This method can be used as a reference when developing any other online programming system for MCUs with USB modules. At the same time, this method can also be extended to various USB-based programmers, such as the Freescale 56F8xxx series DSP programmer based on MCF51JM128 that the author intends to develop.
Previous article:Design and implementation of digital simultaneous interpretation controller
Next article:Application of MSP430 in Microcomputer Protection Module of Power System
Recommended ReadingLatest update time:2024-11-16 20:55
- Popular Resources
- Popular amplifiers
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- usb_host_device_code
- Image acquisition and processing system for panoramic map applications
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Even if we give the complete set of drawings, Chinese people still cannot build high-end lithography machines?
- System Verilog 1800-2012 Syntax Manual
- aos multithreading and mutex lock
- Now many circuits do not have watchdogs, but some watchdog circuits are necessary. I would like to ask in which applications,...
- Brief discussion: Electromagnetic compatibility (EMC) radio frequency electromagnetic field radiation immunity test plan
- The biggest company in the Metaverse is also laying off employees. It is said to be bigger than Twitter.
- How to improve the frequency accuracy of the resonant circuit?
- [FS-IR02 + D1CS-D54] - 3: Electrical performance index detection (D1CS-D54)
- RF application scenarios——Q value
- Last three days! Apply for the free Zhongke Yihai Micro-Shenzhen series FPGA development board EQ6HL45