USB mass storage device from SD card with TWR-K60

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

USB mass storage device from SD card with TWR-K60

Jump to solution
2,114 Views
danielchai
Senior Contributor I

Hi All,

I edit the code for msd_usb from RAM to SD card. Now my problem is that every time when I plug in the USB cable to my PC, it asks me to format. But I can not format it. It seems there is something wrong.

I just edit

From

case USB_MSC_DEVICE_READ_REQUEST :         
    lba_data_ptr = (PTR_LBA_APP_STRUCT)val;
    #if RAM_DISK_APP
        USB_mem_copy(g_disk.storage_disk + lba_data_ptr->offset,
                lba_data_ptr->buff_ptr,
                lba_data_ptr->size);
    #endif        
    break;
case USB_MSC_DEVICE_WRITE_REQUEST :
    lba_data_ptr = (PTR_LBA_APP_STRUCT)val;
    #if RAM_DISK_APP
    USB_mem_copy(lba_data_ptr->buff_ptr,
                    g_disk.storage_disk + lba_data_ptr->offset,
                    lba_data_ptr->size);
    #endif                         
    break;

TO

case USB_MSC_DEVICE_READ_REQUEST :    

    lba_data_ptr = (PTR_LBA_APP_STRUCT)val;

    fread(lba_data_ptr->buff_ptr, 1, 1, filesystem_handle);

    break;

case USB_MSC_DEVICE_WRITE_REQUEST :

    lba_data_ptr = (PTR_LBA_APP_STRUCT)val;

    fwrite(lba_data_ptr->buff_ptr, 1, 1, filesystem_hanlde);

    break;

I am new to this, any ideas will be appreciated.


Thank you.


-Daniel

Tags (2)
1 Solution
909 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi Daniel,

Attached you can find a simple SD card reader via USB using MQX. It is working but I just want you to know that the format is really slow. This one does not implement multi read/write blocks, and the performance may vary depending on the SD you are using.

This project is a little bit old, because it works in CW10.1 and K60 with MQX v3.7, but you can use it as reference.

Hope this will be useful for you.

Best regards!

/Carlos

View solution in original post

0 Kudos
11 Replies
910 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi Daniel,

Attached you can find a simple SD card reader via USB using MQX. It is working but I just want you to know that the format is really slow. This one does not implement multi read/write blocks, and the performance may vary depending on the SD you are using.

This project is a little bit old, because it works in CW10.1 and K60 with MQX v3.7, but you can use it as reference.

Hope this will be useful for you.

Best regards!

/Carlos

0 Kudos
909 Views
danielchai
Senior Contributor I

Hi Carlos,

I tried this code based on MQX4.0.2. It does not work.

After I change it to using SD card, the PC can not detect it.

Thank you.

-Daniel

0 Kudos
909 Views
LJK1
Contributor I

Hi Daniel,

did you get this going?

I tried it on the K64F120 and get the format problem.

When I read sector by sector using USB, each time I do it the data is different and not always the the same as what is on the SD.

Cheers,

Lisa

0 Kudos
909 Views
danielchai
Senior Contributor I

Hi Lisa,

Actually, this code does not work. I contacted the one of the Freescale engineer, he said the read/write on the SD card can not be called in the USB reading/writing request, because all the functions in USB reading/writing function should be non-blocking function. When you debug into very deep level, it

will show you the Errorcode which indicate the function can not be called in current context.

-Daniel

0 Kudos
909 Views
LJK1
Contributor I

Hi Daniel,

many thanks. Did you work out a solution?

I found that I

read most of the data but some is corrupted or appears to be in the

wrong place.

If USB reads should be non blocking, what should be

returned from the function? I assume there is some other way that the

data can be sent then rather than return from the function.

I will need

to investigate further.

Cheers,

Lisa

On 14/04/2014 21:07, Daniel Chai

wrote:

USB MASS STORAGE DEVICE FROM SD CARD WITH TWR-K60

reply

from Daniel Chai in _ Kinetis Microcontrollers_ - View the full

discussion

0 Kudos
909 Views
waynelai
Contributor I

May I know if there any progress about this feature ?

I've tried the code on K60, but it does not work.

Thanks.

0 Kudos
909 Views
danielchai
Senior Contributor I
0 Kudos
909 Views
pramodk_g_
Contributor III

Hi Carlos,

                             I tried your code and it is working on my k60. Thanks for your help. But it has slow data rate as you mentioned, how we can improve this?

Any thoughts?

Thanks,

Pramod.

0 Kudos
909 Views
mircopizzichini
Contributor III

Hi pramodk.g.,

I also was able to make it work. But as you stated, data rate is really really slow... Have you been able to improve it?

Thanks

Mirco

0 Kudos
909 Views
danielchai
Senior Contributor I

Hi Carlos,

Thank you. I will try it and post the update here.

-Daniel

909 Views
CarlosCasillas
NXP Employee
NXP Employee

Hello Daniel.

Could you please specify which example are you using? Are you using Freescale USB Stack or MQX RTOS?

Best regards!

/Carlos

0 Kudos