EmbeddedRelated.com
Forums

sdcard as USB mass storage device (arm lpc2388)

Started by faiz1303 5 years ago5 replieslatest reply 5 years ago143 views

Hi,

I am trying to read the sdcard which is connected to the spi port of arm lpc2388 as a mass storage device, I had run the USBMem (RAM) code Keil on my OLIMEX board and its working. But I don't know how I can read the sdcard or both  as a mass storage device. Can you please suggest what changes should I make in  USBMem code to get the sdcard as msd. It will be more helpful if I get some reference code.

Please help

warm regards

[ - ]
Reply by mr_banditJune 26, 2019

Well, first you need to determine what the format of the "mass storage device" is: FAT16, FAT32, etc. How was the directory structure created?

TO start with, you should create an SDCard file structure with one file in it. The file should contain known values, like ABCD.. abcd..

Once you know that, read the first few sectors and dump them out as both hex and ascii, then compare them to the expected format. Do the two sets (expected and reality) make sense? If not, at least one of your assumptions are incorrect.

Rinse/repeat, until the two are in sync

You did not indicate if you are running an RTOS, a linux kernel, bare metal. If you have an OS of whatever sort, see if it supports the file system. If so, follow that breadcrumb trail of attaching that kind of file system.

If you are running bare metal, you own the world. Find the file you want in the directory, get its location on the SDCard, and read it. (This also assumes you know the exact contents of the file for your development sequence so you know you are reading expected values).

Hope this helps ... bandit

[ - ]
Reply by faiz1303June 26, 2019

Thanks mr_bandit,

Sorry for the incomplete information, I am using a FAT32 file system. It is a normal bare metal code tested on windows(RAM as MSD). Sd card and MSD(RAM) working well as a two different entities. I will try as you have suggested.

thanks & regards 

[ - ]
Reply by mr_banditJune 26, 2019

one step at a time - verify and understand each step before going onto the next.. systematic will work....

[ - ]
Reply by faiz1303June 26, 2019

Hi mr_bandit,

Now, firstly I had created the text file in  sdcard. I had copied  all the hex bytes having the information as removable disk name, file name and file content.  

After that in msc_read function I tried to open that file using FAT32 FILE_Open function and I failed. Can you please help. 

[ - ]
Reply by mr_banditJune 26, 2019

It should have returned an error code. They are your friend.

Can you read the FAT itself? Parse through it and verify you are creating it properly. Can you use a PC to read the SDcard && read the FAT? Be systematic. Do a step, verify the step.

Make a file on the SDCard using a PC that is a known pattern, like bytes 0x00 - 0xFF. Verify it. Write the code on the PC and test it on the PC, then use that same code on your target system.

I don't mind giving you direction, but you need to think through the development sequence, and what to do at each step. What options and techniques can you use? The way to become a good problem solver is to solve problems. Don't give up!