Sample code for LPC1347 and USB-MSD with a SD Card ?

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

Sample code for LPC1347 and USB-MSD with a SD Card ?

876 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kanestro on Wed Dec 17 02:43:00 MST 2014
hello, I am a new user of LPC processor.
I need help to write a mass storage device to read and write a sd card with fat32 ?
Thank You
Labels (1)
0 Kudos
3 Replies

827 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Thu Jan 29 08:01:40 MST 2015
Hello Kanestro
Were you able to make it work? I have done some others modifications to the usblibrary and now I can read and write my sd card from windows explorer (I've tried this on windows xp, 7, 8 and ubuntu linux) Below I show  a piece of code where I did  modifications.
I hope this can help you.

On EndpointCommon.h file

#define USB_DATA_BUFFER_TEM_LENGTH      512

and I changed this to
#define USB_DATA_BUFFER_TEM_LENGTH      600


On Endpoint_LPC17xx.c file, DMAEndTransferISR() function
if ((usb_data_buffer_OUT_size[0] + tem + dmaDescriptor[PhyEP].MaxPacketSize) > 512)
{
USB_REG(0)->DMAIntEn &= ~(1 << 1);
}

and I changed this to
if ((usb_data_buffer_OUT_size[0] + tem + dmaDescriptor[PhyEP].MaxPacketSize) > 550)
{
USB_REG(0)->DMAIntEn &= ~(1 << 1);
}


and finally on SCSI.c file, SCSI_Command_ReadWrite_10() function

.......
else
{
int i;
for(i=0;i<TotalBlocks;i++)
{
while(!Endpoint_IsReadWriteAllowed(0));

Endpoint_Read_Stream_LE(0,buffer,VIRTUAL_MEMORY_BLOCK_SIZE, NULL)

Endpoint_ClearOUT(0);
MassStorage_Write((BlockAddress+i),buffer, VIRTUAL_MEMORY_BLOCK_SIZE);

}
}......


I changed this to

.......
else
{
int i;
for(i=0;i<TotalBlocks;i++)
{
while(!Endpoint_IsReadWriteAllowed(0));

bytes = Endpoint_BytesInEndpoint(0);

if(bytes > VIRTUAL_MEMORY_BLOCK_SIZE)
{
Endpoint_Read_Stream_LE(0,buffer,bytes - VIRTUAL_MEMORY_BLOCK_SIZE, NULL);
bytes = VIRTUAL_MEMORY_BLOCK_SIZE;
}


Endpoint_Read_Stream_LE(0,buffer,bytes,NULL);
Endpoint_ClearOUT(0);
MassStorage_Write((BlockAddress+i),buffer, VIRTUAL_MEMORY_BLOCK_SIZE);

}
}.......
0 Kudos

827 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kanestro on Tue Jan 06 04:49:35 MST 2015

Hello Gonzalo
thanks, I start to work immediately
0 Kudos

827 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Wed Dec 31 06:47:10 MST 2014
Kanestro, there is an example which perform a mass storage device using the internal RAM. If you Modify this example you  will be able to read and write a SD card (in theory) . I've been able to read my SD card but I haven't been able to write into it. Despite my problem, it  maybe helps you to start your code.
You have to modify SCSI_Command_ReadWrite_10() function which is in SCSI.c file.

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     [color=#c33]here you have to chage this for #if 1[/color]

......

}


Then you will have to modify MassStorage_GetCapacity(void) function so that  it can  return  SD size and you will also  have to modify MassStorage_Write()  and MassStorage_Read() functions to write and read blocks of your SD card.

I hope it helps you.
Regards
0 Kudos