LPCxxxx as MassStorageDevice using external memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPCxxxx as MassStorageDevice using external memory

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by diegotrex on Tue Apr 23 10:11:27 MST 2013
Hi
I want my uC application behaves as a simple  USB stick when connected to a USB host as a PC.
I implemented the example in NXPUSBLib(http://www.lpcware.com/content/project/nxpusblib) for LPC11U14  on LPCxpresso EVB stick..It works,i can see on PC the new drive  and open the example text file 
I need to read a bigger file,it could be 10MB in size,and it should reside in an EEPROM,or in a RAM with backup battery.
I don't have any idea on how doing it,despite i already did Filesystem stuff using other uCs. I ask for hints or links,please.

About the above example:

In DataRam.c i found thedisk image and the txt file content
in DataRam.h i have
#if  defined(__LPC11UXX__)

[COLOR=Sienna]#define DATA_RAM_START_ADDRESS  0x20080000
#define DATA_RAM_PHYSICAL_SIZE 0xa00
#define  DATA_RAM_VIRTUAL_SIZE 0x4000 /*fake size to trick windows*/[/COLOR]

but i can't find nowhere else [COLOR=Sienna]DATA_RAM_START_ADDRESS[/COLOR]  or 0x[COLOR=Sienna]20080000[/COLOR]
My question is:how can the linker place the virtual disk and the txt file without this reference?

At the address i hav just empty locations
Instead i found data having to do with FAT table at address
0x1000 0000,at the beginning of 4KBi SRAM

Can i have some help to understand it?
Many thanks
0 Kudos
Reply
3 Replies

1,257 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Wed Dec 31 05:34:59 MST 2014
Dear Tsuneo,

I'm trying to read and write a SD card using USBmassStoragedevice. I have modified the library as you say and I can  read my SD card without problem but when I try to write  the library goes into an infinity loop.
Have you been able to write files without problems?

Regards
0 Kudos
Reply

1,257 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by diegotrex on Tue Apr 30 04:25:18 MST 2013
Many thanks,by now Tsuneo
0 Kudos
Reply

1,257 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Thu Apr 25 08:51:35 MST 2013
Firstly, you have to touch to "#if 0" in this routine, so that the stack reads/writes your media calling MassStorage_Read() / MassStorage_Write()

nxpUSBlib v0.98b\applications\examples\LPCUSBlib\Example_MassStorageDevice\Lib\SCSI.c

static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
                                      const bool IsDataRead)
{
    ...
    ...
    /* Determine if the packet is a READ (10) or WRITE (10) command, call appropriate function */
#if 0   // <---------------------- 1    enable this #if clause
    if (IsDataRead == DATA_READ)
    {
        ...


And then, implement MassStorage_Read() / MassStorage_Write() routines, so that they accesses to your media.

nxpUSBlib v0.98b\libraries\BSP\bsp.c

void MassStorage_Write(uint32_t diskpos, void* buffer, uint32_t size)
{
    // write to your media: diskpos - start address in byte on your media
}

void MassStorage_Read(uint32_t diskpos, void* buffer, uint32_t size)
{
    // read from your media: diskpos - start address in byte on your media
}

/** Get Mass Storage Size */
uint32_t MassStorage_GetCapacity(void)
{
    return DATA_RAM_VIRTUAL_SIZE;
         //  return the size of your media in bytes, instead of DATA_RAM_VIRTUAL_SIZE
}


Also, modify MassStorage_GetCapacity(), so that it returns the size of your media.

Optionally, you may change the serial number and INQUIRY strings, to make your device unique.

The example gives hard-coded MBR, boot sector, FAT and directories on its media (DiskImage[] RAM array on \libraries\BSP\DataRam.c). As you have an external media, DiskImage[] is not needed any more. You may make up the disk format (including MBR) using PC utilities on your media, for example,

- Windows disk management utility
"How to Manage Your Disks using the Disk Management Utility"
http://www.7tutorials.com/how-manage-your-disks-using-disk-management-utility

- SD Formatter on sdcard.org (by Panasonic)
https://www.sdcard.org/downloads/formatter_3/

etc.

Tsuneo
0 Kudos
Reply