Detect SD card file system as device over USB cable using LPCXpresso5411?

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

Detect SD card file system as device over USB cable using LPCXpresso5411?

1,281 Views
puddletowntom
Contributor III

I was looking at the USB examples from the SDK of the LPCXpresso5411. Using the example "SDK_2.2.1_LPCXpresso54114/boards/lpcxpresso54114/usb_examples/usb_rom_device_msc_ram" I successfully got a PC to recognise the LPCXpresso5411 as a USB device with a USB cable using the hard coded files in ramdisk.c. eg the code below will show basic files when a usb cable is plugged into a PC.

//ramdisk.c

static const struct FAT12_img
{
    const uint8_t *data;
    int offset;
    int size;
} FAT12_img[] = {
    /* Each sector is of size 512 Bytes i.e., 0x200 Bytes */
    {FAT12_header, 0, sizeof(FAT12_header)},                       /* FAT12 at sector 0,1 */
    {FAT12_root_dir, 0x400, sizeof(FAT12_root_dir)},               /* Root dir at sector 2 */
    {FAT12_file_readme_txt, 0x600, sizeof(FAT12_file_readme_txt)}, /* README.TXT file data */
    {FAT12_file_index_htm, 0xC00, sizeof(FAT12_file_index_htm)},   /* INDEX.HTM file data */
};

void DataRam_Initialize(void)
{
    int i;
    extern uint8_t g_memDiskArea[];
    memset(g_memDiskArea, 0, MSC_MEM_DISK_SIZE);
    for (i = 0; i < sizeof(FAT12_img) / sizeof(FAT12_img[0]); i++)
        memcpy(&g_memDiskArea[FAT12_img[i].offset], FAT12_img[i].data, FAT12_img[i].size);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

However I would like to integrate this with the FatFs for an SD card. With help from this forum, I have the FatFs and SD card working. So instead of the "static struct FAT12_img" I m trying to use the FIL structure from ff.h.

//ff.h

typedef struct {
     _FDID     obj;               /* Object identifier (must be the 1st member to detect invalid object pointer) */
     BYTE     flag;               /* File status flags */
     BYTE     err;               /* Abort flag (error code) */
     FSIZE_t     fptr;               /* File read/write pointer (Zeroed on file open) */
     DWORD     clust;               /* Current cluster of fpter (invalid when fprt is 0) */
     DWORD     sect;               /* Sector number appearing in buf[] (0:invalid) */
#if !_FS_READONLY
     DWORD     dir_sect;          /* Sector number containing the directory entry */
     BYTE*     dir_ptr;          /* Pointer to the directory entry in the win[] */
#endif
#if _USE_FASTSEEK
     DWORD*     cltbl;               /* Pointer to the cluster link map table (nulled on open, set by application) */
#endif
#if !_FS_TINY
     BYTE     buf[_MAX_SS];     /* File private data read/write window */
#endif
} FIL;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Would I do something like 

FIL fil;

memcpy(&g_memDiskArea[fil.obj], fil.buff, fil[i].size);‍‍‍

I m not too sure how to do this, but any point in the right direction would be great.

Thanks,

Ronan

Labels (1)
4 Replies

1,017 Views
mattbrown123
Contributor I

How did this work out?  Although not a developer, this thread is one of the few leads I've located with the hope that the idea turned into a device.

The application I am looking at this for is use in a music sampler.  My hope is to replace the SD card with a device where I can quickly and easily manage samples presented via an SD card physical interface backed by storage on a PC.

Were you able to work this out and make your work commercially available?

Thanks

0 Kudos

1,017 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Matt Brown,

   This case is really very old.

   If you have the question, please create your own lpc question again, then our LPC engineer will help you in your new question post.

   Thanks a lot for your understanding.

Best Regards,

Kerry

0 Kudos

1,017 Views
Edrianocarlos
Contributor IV

Hi Ronan,

i believe if you already have the ramdisk working, the only thing you should change would be the low level io.

Normaly it needs the read block and write block to work.

 i did this with my K64 a long time ago. now i am working with LPC1549.

One thing to take in to account is that when you are with USB connected opening a file with fatfs could be dangerous.

as both will try to access the disk at the same time. and there is none protection in to the code to prevent it.

0 Kudos

1,017 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

    See you again, yes, I help you finished the SD card detect code with fatfs in LPC54114 last month.

   But, associated with the USB, we really don't have any example for your reference now. This is really complicated, you also need to familiar with the USB MSD function.

  You can try to modify the USB MSC code, change the usb received data interface which is stored in the internal flash and RAM to the SD card.

  This post maybe useful to you, you can check it:

How to add SD card support (SPI) to usb composite msc cdc example? 

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos