write to sd card via mass storage class using nxpusblib

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

write to sd card via mass storage class using nxpusblib

696 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Madara on Sun Nov 24 08:09:02 MST 2013
I am able to read and browse the sd card via usb mass storage but when i try to write the process fails and the card gets corrupted.

I am using bulk only transport and SCSi protocol. I am using nxpusblib
The read and write code is

if (IsDataRead == DATA_READ)
{   while(TotalBlocks--){
sdmmc_read(Buffer,BlockAddress,1);
while(!Endpoint_IsReadWriteAllowed());
Endpoint_Write_Stream_LE((void *)Buffer, 512, ((void *)0));
Endpoint_ClearIN();
BlockAddress++;
}
}
else
{  
while(TotalBlocks--){
while(!Endpoint_IsReadWriteAllowed());
Endpoint_Read_Stream_LE((void *)Buffer, 512, ((void *)0));
sdmmc_write(Buffer,BlockAddress,1);
BlockAddress++; ;
}
}

Can some body help me

Labels (1)
0 Kudos
3 Replies

655 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Thu Jan 29 08:07:44 MST 2015
Hi Madara
I've been able to write my sd, I had to  make some modifications to usblibrary.
I post this here http://www.lpcware.com/content/forum/sample-code-lpc1347-and-usb-msd-sd-card#comment-1143210
Regards
0 Kudos

655 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Wed Dec 31 07:09:12 MST 2014
HI!!
I have the same problem, I can read my Sd card without problem but I can´t write on it.
Any news about it? Have you been able to write files in the SD?

Regards
0 Kudos

655 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Madara on Mon Nov 25 03:29:33 MST 2013
I changed the code to following where instead of requesting 512 bytes of data using Endpoint_Read_Stream_LE((void *)Buffer, 512, ((void *)0)); I am using Endpoint_Read_8() inside USB_get_data to reveive 16 bytes of out transfer.But the result is the same.I have ran out of options.

while(TotalBlocks--){
offset = 0;
length = 512;
memset(Buffer,0,512);
while(!Endpoint_IsReadWriteAllowed());
while(length > 0){
bytestowrite = USB_get_data(temp);
TRACE("B%d",bytestowrite);
if(!bytestowrite)
break;
memcpy(Buffer + offset, temp, bytestowrite);
offset += bytestowrite;
length -= bytestowrite;
            }
sdmmc_write(Buffer, BlockAddress,1);
if (MSInterfaceInfo->State.IsMassStoreReset)
  return 0;
BlockAddress++;
}
if (!(Endpoint_IsReadWriteAllowed()))
Endpoint_ClearOUT();
0 Kudos