MCF51JM128 online programming design in the form of USB flash drive

Publisher:caoda143Latest update time:2009-07-17 Source: 单片机与嵌入式系统应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Bulk-Only Transfer Process on USB Devices

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.

The actual SCSI commands used

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.

FAT area structure

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.

Reference address:MCF51JM128 online programming design in the form of USB flash drive

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

Mouse circuit diagram with USB and RS-232 interface
Mouse circuit diagram with USB and RS-232 interface The main chip is composed of FT8U232AM , as well as USB interface circuit, MAX213 CAJ chip, 93C46 chip and other circuits.
[Analog Electronics]
Mouse circuit diagram with USB and RS-232 interface
Using CY7C68013A to implement USB control system
introduction Universal Serial Bus (USB) is a new interface technology on computers, which is becoming more and more popular. Compared with the previous RS 232, RS 485, ISA, PCI and parallel interfaces, USB avoids the defects of large interface size, inconsistent interface specifications, and lack of support for
[Microcontroller]
Using CY7C68013A to implement USB control system
Japanese manufacturer launches EVANGELION Unit-01 USB hub
    According to foreign media reports, Japan's TOPS company has launched a "Neon Genesis Evangelion" themed USB hub, which adopts the design of EVANGELION Unit-01. The product has a beautiful shape and a high degree of restoration. It is expected to be released in September 2021.   The size of this product is 8×9×1
[Mobile phone portable]
Catching up with USB4 2.0 standard: Intel demonstrates new 80Gbps Thunderbolt interface
Not long ago, USB-IF officially announced the latest USB4 2.0 standard, with a maximum speed of 80Gbps, which is twice that of USB4 and twice that of Thunderbolt 4 interface, but the cable needs to be upgraded to active. Now Intel is not to be outdone and has also demonstrated a new 80Gbps Thunderbolt interface. Accor
[Mobile phone portable]
Catching up with USB4 2.0 standard: Intel demonstrates new 80Gbps Thunderbolt interface
Development of embedded physiological measurement system based on USB transmission
    The information industry is developing rapidly. With the rise of the computer industry, the transmission of information and data is becoming more and more convenient and fast. From the earliest UART (RS-232) port, Internet (Ethernet) and other wired transmission to the current USB transmission (low speed, full spe
[Microcontroller]
Development of embedded physiological measurement system based on USB transmission
Simple circuit to prevent USB current overshoot when plugged in
When a 5V USB port is generated, this circuit limits the peak inrush current (at the USB port) at the moment of insertion, and simultaneously limits the operating current up to 500mA, as required by the port. You can trigger a simple insertion of a pen drive or an unwanted system reset of other peripherals in
[Power Management]
Simple circuit to prevent USB current overshoot when plugged in
FAN5400 Series USB Compatible Li-Ion Battery Switching Charger
When charging single or dual-cell lithium-ion (Li-Ion) batteries through a USB port or AC/DC adapter, designers need solutions that can increase charging speed and solve the thermal issues associated with linear chargers. To meet this need, Fairchild Semiconductor has developed the FAN5400 series of USB- compati
[Power Management]
FAN5400 Series USB Compatible Li-Ion Battery Switching Charger
Implementation of USB-CAN Adapter Based on ATmega8515
  CAN (Controller Area Network) bus is a multi-host local network field bus. Due to its flexibility and convenience in networking, high efficiency and reliability of communication, and low cost, it has been widely used in the field of decentralized control of factories. Today's factory automation control requires both
[Microcontroller]
Implementation of USB-CAN Adapter Based on ATmega8515
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号