LPC11U14 implements SD card USB disk

Publisher:快乐旅途Latest update time:2016-07-14 Source: eefocusKeywords:LPC11U14 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This experiment was successfully verified on the LPC1114/LPC1343/LPC11U14 development board designed by me: Let me show you the pictures first. Here are three types of chips and three types of development boards. The SD card is on the back. . .

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

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:

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

NXP emulated USB flash drive

 

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

 

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

 

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

 

 

 

 

 

 

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:

 

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

 

2. Modify the Read function:

 

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

 

3. Modify the Write function:

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

4. Modify the MSC_GetCBW function:

LPC11U14 implements SD card USB disk (original) - My Heart Will Go On - ARM-Practitioner

 

 

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. . . .

Keywords:LPC11U14 Reference address:LPC11U14 implements SD card USB disk

Previous article:LPC1100 Processor SD Card Upgrade Application
Next article:About STM32 SPI port setting problem

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号