USB_ MSD_CLASS

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

USB_ MSD_CLASS

Jump to solution
2,690 Views
danielecortella
Contributor V

Hi all, i'm using the USB_ MSD_CLASS Processor Expert library present on the USB Stack 4.11 . The problem is that i have implemented a system with a SDCard connected to a KL25 through the SPI. I can write, read files with the FATFS library and i want to see this files connecting the system to a PC. The problem is that when i connect this i can see and read the file, but i can't write on the SDCard. The function disk_write_block in MSD_Event_Callback() is never called. Why? Someone are using correctly this library ?? Thanks

//---------------------------------------------------------------------------

  case USB_MSC_DEVICE_WRITE_REQUEST: {

  uint8_t tmp = 0;

  lba_data_ptr = (PTR_LBA_APP_STRUCT) val;

  tmp = lba_data_ptr->size / 512;

  tmp = disk_write_block(controller_ID, lba_data_ptr->buff_ptr,

  lba_data_ptr->offset, tmp);

  break;

  }

//---------------------------------------------------------------------------

1 Solution
1,714 Views
danielecortella
Contributor V

Hi,

after many time spend for find the bug and without support from freescale, that responde me that is all working, i found the solution. you have to change two parameter :

  • in USB_MSC.h you have to change the MSC_RECV_DATA_BUFF_SIZE and MSC_SEND_DATA_BUFF_SIZE, i have put 4096
  • in USB_MSC_SCSI.c you have to delete error = USBERR_ENDPOINT_STALLED; (i have comment this) in this position (function msc_thirteen_cases_check)

    }

                /* BULK OUT PIPE TO BE STALLED for status phase */

                //error = USBERR_ENDPOINT_STALLED; HERE!!!!!!!!!!

            }

            else

            {

                /* CASE 13: Host intends less data to send than device

                                                    intends to receive*/

View solution in original post

26 Replies
1,585 Views
danielecortella
Contributor V

I have seen the library but i didn't understand all. I think that there is a missing call to the case USB_MSC_DEVICE_WRITE_REQUEST present in disk.c but i didn't find where.  Thanks

0 Kudos
1,585 Views
mjbcswitzerland
Specialist V

Hi

I still don't understand whether the code/project supports this but all that is needed is to interface the UFI READ(12) and (10) commands to read the requested amount of sectors form the requested sector address and return the content to the PC host, as well as UFI WRITE(12) and (10) command and write the sector data received from the PC host to the sectors (defined). So essentially the SD card interface's sector write/read command need to be called at these locations.

I notice that this problem is open for 2 months now. Does it need a solution or is it just being toyed with?

Regards

Mark

0 Kudos
1,585 Views
danielecortella
Contributor V

Hi,

yes we need a solution because we are developing a new product where we need to read/write on the sd card. Try to understand where is the problem is however very difficult, i don't know the usb protocol. Thanks

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Daniele,

Thanks for your reply. it's long time without your reply.

I've modified the kinetis_k60 by set USE_SDCARD marcro in user_config.h to 1 whose location is in ~\Freescale\Freescale USB Stack v4.1.1\Source\Device\app\msd\cw10.

Now on running the application, the SD card is available as removable dick in Windows and it's support to create/read/copy/write files in the SD card.

So I'd like to suggest that you can refer to the kinetis_k60 for details.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,585 Views
quentinchen
Contributor I

Hi,i have the same problem.

When i use KDS/PE to create a sflash demo with USB_MSD_CLASS, there is a missing call to the case USB_MSC_DEVICE_WRITE_REQUEST present in disk.c.

But if i use the IAR project in C:\Freescale\Freescale USB Stack v4.1.1\Source\Device\app\msd\iar_ew\kinetis_l2k, i can read/write the data in sflash.

I create the same project in CW,and the problem is similar.

0 Kudos
1,715 Views
danielecortella
Contributor V

Hi,

after many time spend for find the bug and without support from freescale, that responde me that is all working, i found the solution. you have to change two parameter :

  • in USB_MSC.h you have to change the MSC_RECV_DATA_BUFF_SIZE and MSC_SEND_DATA_BUFF_SIZE, i have put 4096
  • in USB_MSC_SCSI.c you have to delete error = USBERR_ENDPOINT_STALLED; (i have comment this) in this position (function msc_thirteen_cases_check)

    }

                /* BULK OUT PIPE TO BE STALLED for status phase */

                //error = USBERR_ENDPOINT_STALLED; HERE!!!!!!!!!!

            }

            else

            {

                /* CASE 13: Host intends less data to send than device

                                                    intends to receive*/

1,585 Views
quentinchen
Contributor I

Thanks very much, i will try it later.

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Daniele,

I'm glad to hear that the accomplishment of the project from you.

I was wonder if you could share the project, I think it will be benefical to other guys who want to do the similar application.

Have a nice day!

Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,585 Views
danielecortella
Contributor V

NEWS: the project created from me is taken by the folder \Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx and changed for use the SdCard instead simulate a RAM_DISK. This original code is :

case USB_MSC_DEVICE_WRITE_REQUEST :

    /* copy data from USb buffer to Storage device

        (Called before after recv_data on BULK OUT endpoints)*/

    lba_data_ptr = (PTR_LBA_APP_STRUCT)val;

    /* read data from driver buffer to mass storage device */

#if RAM_DISK_APP

    USB_memcopy(lba_data_ptr->buff_ptr,

    g_disk.storage_disk + lba_data_ptr->offset,

    lba_data_ptr->size);

#elif SD_CARD_APP

          SD_Write_Block(lba_data_ptr);

#endif

where RAM_DISK_APP is declared then USB_memcopy is the function that will be executed. Putting a breakpoint on this the problem is that this is never called. There is then a bug with this library because USB_MSC_DEVICE_WRITE_REQUEST is never called. Someone can help me ?

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Daniele,

I have reproduced this behavior, it is normal. We have been told by USB stack developers that the purpose of the example is to set the MCU as a Mass Storage Device and to be recognized and enumerated by a host. It is not possible to use the example as a usb memory becuase the MCU does not have enough RAM to create a FAT table and a file system.

Wish my support could help.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,585 Views
mjbcswitzerland
Specialist V

Hi

I think that there must be some confusion since it is not necessary to have a FAT table and file system in a pure USB-MSD implementaion since this is performed by the PC host and not by the processor.

Regards

Mark

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mark,

I've had a brief go through the USB protocol document. I think the PC (HOST) can't identify a U-disk (Device) if it doesn't provide relevant FAT table.

So it also need FAT table if you want use KL25's RAM simulate a U-disk.

Wish my support help.

Have a nice day!

Ping

0 Kudos
1,585 Views
danielecortella
Contributor V

In my case the FAT table is stored in the SDCard, in fact i can read the file with the MSD but the problem is when you try to write or format this, the function is never called ... i think that a called is missing for permit to write on this. Thanks

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mark,

Yes, I also think too.

The key point is how to transfer FAT table to PC(HOST)when receive the command READ(10), I'm also studying how to modify this project to simulate U-disk successful.

Howvever I still have no idear with that until now and I will inform you if I work it out.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,585 Views
danielecortella
Contributor V

Rigth, in my project i have the SdCard with FAT table. When i write o read this with the microprocessor i use the FATFS library but when i use USB-MSd this is not necessary, i have only to read or write block of memory with the function :  SD_Write_Block(lba_data_ptr); or  SD_Read_Block(lba_data_ptr); . The problem using the sample could be that because the memory of the micro is very small is impossibble write a file on this, but the fact is that the function is never tried to be executed.

0 Kudos
1,585 Views
danielecortella
Contributor V

Thanks for the info, then my question is if possible to add, in the MSD code, a call in that permit to enter in the USB_MSC_DEVICE_WRITE_REQUEST. For me debug all the library is very hard because is very long and i didn't know very well the usb protocol. A USB stack developer can tell me where add this? Thanks!!!

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Daniele,

To be honest, I've also been confused with how to add FAT table to this project. Since I didn't use this before and I will inform you immediately if I know how to do this.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,585 Views
mjbcswitzerland
Specialist V

Hi Daniele

I can't help with the PE generated project but there is a complete solution for USB-MSD, utFAT and SD card in the uTasker project which works on the KL25 boards and also allows simulating and debugging the complete operation in VisualStudio:
KINETIS Project Code
µTasker Kinetis support

Regards

Mark

0 Kudos
1,585 Views
danielecortella
Contributor V

Thanks, i will see in this day this second options.

0 Kudos
1,585 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Daniele Cortellazzi,

Thank you very much for your focus on Freescale's product. I'm glad to provede service for you.

For solving this issue more quickly, I should confirm some thing from you.

1. Could you tell me the exactly name of the project you use or upload your project to community you used?

2. What's board do you use for test? FRDM-KL25, TWR-KL25 or others?

I'm looking forward to your reply.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos