reading/writing SDCARD using USB

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

reading/writing SDCARD using USB

733 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by GuusReijnders_CG on Tue Jul 29 05:18:39 MST 2014

I am using the development board MCB1800 (lp1856) from Keil.
I can compile and the examples usb_rom_msc_ram and periph_sdmmc.

But the first example uses RAM instead of an SDCARD, so I want to combine these two examples.
I can read the number of sector and size of the SDCARD, so I can set the right settings for USB.
In windows the right size of the SDCARD is shown.

But now I want to read and write the Card using USB. I see the functions translate_rd and translate_wr.

I tried several things but nothing is working yet. What code do I need to add to let the SDCARD work with USB.
I have seen the gunctions diskr_read and disk_write. However when I use these functions in the USB routines the application gangs.


Thanks in advance
Labels (1)
0 Kudos
9 Replies

645 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ChewTP on Wed Oct 15 02:40:24 MST 2014
Hi I need some help here . I would like to implement SDMMC as a Mass storage device media when connected to the PC . I am looking at the msc_ram and perish_sdmmc examples in the LPCOpen . Same examples that you are looking . I would like to implement read , write , change directory , rename in the SDMMC card when view from PC .

I think using the USBD ROM driver in the mass storage class , they only have translate_wr , translate_rd , verify ..etc but with just these two callback function , how can I implement those functionn like change directory , rename delete ...

Maybe it can implement read and write but to use it like a normal storage device , it is more than just read and write . Any idea how to do that .
0 Kudos

645 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Sun Aug 17 07:17:15 MST 2014
I'm trying to do the same thing but with a LPC4088, the first part seems to be ok, the pc recognize the Mass Storage Device when connected over USB, but what about the function to be wrapped?

static void translate_rd(uint32_t offset, uint8_t * *buff_adr, uint32_t length, uint32_t hi_offset)
{
*buff_adr =  &g_memDiskArea[(((uint64_t) offset) | (((uint64_t) hi_offset) << 32))];
}

/* USB device mass storage class write callback routine */
static void translate_wr(uint32_t offset, uint8_t * *buff_adr, uint32_t length, uint32_t hi_offset)
{
        *buff_adr =  &g_memDiskArea[(((uint64_t) offset) | (((uint64_t) hi_offset) << 32)) + length];
}

/* USB device mass storage class get write buffer callback routine */
static void translate_GetWrBuf(uint32_t offset, uint8_t * *buff_adr, uint32_t length, uint32_t hi_offset)
{
*buff_adr =  &g_memDiskArea[(((uint64_t) offset) | (((uint64_t) hi_offset) << 32))];
}

/* USB device mass storage class verify callback routine */
static ErrorCode_t translate_verify(uint32_t offset, uint8_t *src, uint32_t length, uint32_t hi_offset)
{
if (memcmp((void *) &g_memDiskArea[(((uint64_t) offset) | (((uint64_t) hi_offset) << 32))], src, length)) {
return ERR_FAILED;
}

return LPC_OK;
}


How I should replace the function?
0 Kudos

645 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Erwins on Sun Aug 03 22:45:38 MST 2014
Thanks for your replies!
We also figured out the interrupt problem.
0 Kudos

645 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Erwins on Sun Aug 03 22:43:25 MST 2014
Thanks for your replies!
We also figured out the interrupt problem.
0 Kudos

644 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by goffi on Fri Aug 01 12:47:50 MST 2014
right!
0 Kudos

644 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TaGUNil on Fri Aug 01 08:33:52 MST 2014
It's about interrupt priorities. Mass Storage callbacks are called inside USB interrupt handler. Therefore you should set SD/MMC interrupt priority higher than USB's.
0 Kudos

644 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by goffi on Fri Aug 01 08:06:32 MST 2014
i lose about two hours to understand and fix that problem!! :((
0 Kudos

645 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Erwins on Wed Jul 30 06:38:29 MST 2014
Hi goffi,

Great to hear you had it working!

I'm also trying to get MSC on the SD Card running on the LPC1857.

I tried to merge msc_ram and periph_sdmmc examples.
When calling disk_read() from the main loop, it works fine. If disk_read() is called from the translate_rd() USB call back function, the program hangs in sdmmc_irq_driven_wait(), in the while loop:

while (sdio_wait_exit == 0) {}


Apparently the SDIO IRQ doesn't work.

Any idea?
0 Kudos

645 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by goffi on Wed Jul 30 01:11:46 MST 2014
Few weeks ago i tried to do the same things with my lpc1837 (just for fun), using two examples (msc and sdcard example). I mixed both and it worked.
0 Kudos