lpcware

Combining EFSL and USB Mass Storage Access

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by scs on Tue Sep 27 09:30:01 MST 2011
We are fairly new to the LPCXpresso 1769 and need to access files on a SD flash card and also to allow USB access to those files from a PC. I'd bet many others have similar needs.  The RDB1768cmsis2.zip sample projects RDB1768cmsis2_efsl_lib, RDB1768cmsis2_efsl_demo, RDB1768cmsis2_usbstack, and RDB1768cmsis2_usb_msc do both, but need combining. Plus we wished that those and other samples explained how to wire the required hardware, an SD card and USB connector in this case.

So I created EfsUsb.c which combines EFSL links and USB MSC in a single source file, linking to the RDB1768cmsis2_efsl_lib and RDB1768cmsis2_usbstack library projects, and combining all of the necessary RDB1768cmsis2_usb_msc sources in that single file. It uses the EFSL low level block read and write functions instead of blockdev_sd.c and lpc2000_spi.c.

EfsUsb.c also includes detailed comments at the top explaining how to wire your SD card and USB connection, and also where to change the USB product ID's and such. I'm not the one who actually did that wiring here (I mostly just type for a living), but tried to make the wiring information very clear and hopefully error free. 

EfsUsb.c also has information and a simple API for coordinating local EFSL file access with USB connections, since having both occur at the same time can easily scramble your SD data.

The attached EfsUsb.zip is a sample project with EfsUsb.c, EfsUsb.h and a main.c that demonstrates writing and reading an SD file and then waits forever for USB connections. There is a ReadMe.txt and similar information in the main.c comments, in addition to the documentation in EfsUsb.c.

To install on the Code Red IDE, unzip into a new folder outside your workspace and use "Import project(s)" and Browse to that "Project directory (unpacked)". This may result in two Debug build choices and you can just choose the first. I'm unsure whether unziping directly into your workspace would also work.

This code is free to use as you like, but check the copyright information in the EfsUsb.c header comments. If anyone from Code Red is reading this, it would be great if you guys could include this in a future release, possibly in the RDB1768cmsis2.zip sample projects.

(The attached EfsUsb.zip was updated 9 Jan 2012 to call efs_init via a new SDsetup(1) mode, used to clear the state after EFS file access. This seems to be required for successful USB access after you have written a file via EFS in many cases. My own code now routinely calls SDsetup(1) after closing a file, but before using SDlock(NOT_USING) to release the EFS lock on the SD. SDsetup(0) is now called with a 0 argument for initialization.)

Steve Simonoff
SporTraq

Outcomes