To realize the SD card USB function, you can only experiment with LPC1343 or LPC11U14, because they both have USB functions. Let's talk about the general idea first. Communicate with PC through USB and enumerate a USB disk. The specific operation is to operate the SD card through the SPI bus.
Next, let's look at the USB flash drive simulated by the NXP source code and the SD card USB flash drive we implemented after modification:
NXP emulated USB flash drive
SD card USB flash drive
1. NXP original code is given for free: USBMem.rar (294.52 KB)
2. The SD card USB disk I modified, it is charged: SD card USB disk.rar (1.45 MB)
Let's take a look at the read and write speed of the USB flash drive:
Speed of reading data from USB drive to PC
Speed of writing data from PC to USB flash drive
As can be seen from the above, the reading and writing speeds of SD cards and USB flash drives are very slow, so this experiment is only of experimental value and cannot be used as a real USB flash drive. Of course, it is still very good to use it to implement IAP, etc. As for improving the speed, there should still be some room for improvement, but it will not be very large. . .
Below we explain in detail what has been modified from the simulated USB flash drive to the SD card USB flash drive, and use Beyond Compare software for comparison.
The left side is the simulated USB code, and the right side is the modified code
1. Add two variables:
2. Modify the Read function:
3. Modify the Write function:
4. Modify the MSC_GetCBW function:
5. Modify the macro definition to obtain information such as the actual capacity of the SD card
These are the general modifications. I will not explain some details here. Netizens can download the program for comparison. See if it is very simple! Download it to the hardware and try it out. . . . . . . . . . . . . . . . . .
When I first started using the USB flash drive, I thought that the file system was used to read and write files, format files, etc. So I was a little scared when I thought about supporting long Chinese file names, because the code for supporting long file names alone would take 170K, and LPC11U14 doesn't have such a large space. After studying, I felt that I had completely misunderstood. In fact, the code for the USB flash drive is not complicated, but it is still difficult to commercialize it. Let me briefly talk about the implementation of the USB flash drive.
1. How to read and write files?
There are many commands for USB flash drives, but we only use a few of them. The most important ones are Read (10/12) and Write (10/12). PC uses these two commands to read and write USB flash drives. In these two commands, we only need to know which sector to read and write, and then we can use the SD card's sector read and write functions to implement file read and write operations.
2. So how does the PC know where the files are stored and what files are there?
You should know that the reading and writing of files cannot be separated from the FAT file system, so the storage medium must have a FAT table, and FAT is used to store information such as files and directories (the specific FAT table will not be introduced here, and netizens can search it on the Internet). Therefore, there is an array DiskImage in the NXP source code. This array simulates the FAT table and the boot sector, such as: 0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00. From the first few bytes, you can see that it is the command of the boot sector. . . . .
So, if only our media has the boot sector and FAT table, then we only need to read the corresponding sector according to the PC instructions. After the PC obtains the boot sector and FAT table, it can decode the file's storage format, file size and other information, which is not much different from reading a hard disk. . . .
Previous article:LPC1100 Processor SD Card Upgrade Application
Next article:About STM32 SPI port setting problem
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
- [Xianji HPM6750 Review 5] LittlevGL transplantation using SPI display
- TI Embedded Live Month - Registration starts now to support efficient, intelligent and low-power system design~
- Four input modes of MCU
- How to replace TMS320C6416TGLZ7 chip
- I would like to ask how to connect the ground on the PCB board of the monitoring equipment and the board ground?
- Overvoltage, overcurrent and overtemperature detection circuit
- Recruitment: Assistant Optical Engineer, Assistant Electronic Engineer, Assistant CAE Engineer, Assistant Structural Engineer
- PCB checklist summary
- Detailed explanation of Altera series FPGA chip IP core
- SinlinxA33 Modify the configuration file to change the output serial port