AnsweredAssumed Answered

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

Question asked by Ronan O'Driscoll on Jul 12, 2018
Latest reply on Jul 19, 2018 by Edriano Araujo

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

Outcomes