This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28377D: USB write not working

Part Number: TMS320F28377D


Tool/software: Code Composer Studio

Hi ,

I am trying to write into a usb file . It seems to be getting stuck in USBHCDPipeRead().

In f_write, it calls create_chain at line 1000 of ff.c and stepping through calls get_cluster() at line 290. The file system is FAT32, so it jumps to line 162 and calls move_window. In move_window, it goes to line 88 and calls disk_read (contained in fat_usbmsc.c). Count == 1 . The program gets stuck in USBHMSCBlockRead. I think inside USBHCDPipeRead() function . I am unable to debug this file , as it doesnt step through properly. 

Is there any version of code which works? Could this be related to :

https://e2e.ti.com/support/microcontrollers/c2000/f/171/p/482787/1741556 

Regards

Anish

  • Anish,

    Are you able to write anything to the file in the mass storage class? Are you trying to write to flash drive?

    sal
  • Hi Sal, 

    Yes I am able to write to the file in the flash drive. It is formatted to Fat as well. 

    However It does not write reliably into the file.  It takes 3-5 tries to write some data into it. 

    Also could you tell me if it writes upto 4GB in one go ? or do I need to write a fixed byte length and repeat  the process for large files ?

    I have attached my code below : 

    #define USB_BUFF_SIZE 50
    char usb_buffer[USB_BUFF_SIZE] = {0};
    
    
    uint16_t
    Write_usb_master(void)
    {
      static uint16_t usb_local_flag = FLG_BUSY ;
      static uint16_t usb_status = USB_W_OPEN;
      static uint16_t flg;
      char usb_file_name[50] = "info.txt";
    
      static uint16_t num_byte_written = 0;
    
      uint16_t flag = 0;
    
    
      f_open(&g_sFileObject, usb_file_name, FA_WRITE);
    
      usb_buffer[0] = '1';
      usb_buffer[1] = '2';
      usb_buffer[2] = '3';
      usb_buffer[3] = '4';
      usb_buffer[4] = '5';
      usb_buffer[5] = '6';
      usb_buffer[6] = '7';
      usb_buffer[7] = '8';
      usb_buffer[8] = '9';
      usb_buffer[9] = '0';
    
      usb_buffer[10] = '1';
      usb_buffer[11] = '2';
      usb_buffer[12] = '3';
      usb_buffer[13] = '4';
      usb_buffer[14] = '5';
      usb_buffer[15] = '6';
      usb_buffer[16] = '7';
      usb_buffer[17] = '8';
      usb_buffer[18] = '9';
    
      Write_usb_file(usb_buffer , USB_BUFF_SIZE , &num_byte_written);
    }
    

    uint16_t
    Write_usb_file(char usb_data[] ,
                   uint16_t USB_BS,
                   uint16_t *usBytesWritten)
    {
      FRESULT fresult;
    static uint16_t ruf_cmpt = FLG_BUSY; fresult = f_write(&g_sFileObject, usb_data, (WORD)(USB_BS), (WORD*)(usBytesWritten)); /* If there was an error reading, then print a newline and return the error to the user */ if(fresult != FR_OK) { ruf_cmpt = FLG_ERROR; } else { ruf_cmpt = FLG_CMPT; f_close(&g_sFileObject); } return ruf_cmpt; }

    Anish

  • Hi Anish,

    Currently I cannot dig into this much right now. Unfortunately, I am the owner of USB and am not very familiar with this example and use case since not many customers use USB this way.

    I may have some time to look at it in a week or so. Please ping back then if you are still having issues.

    Until then, if you have more specific questions regarding the USB protocol or USBlib, I may be of assistance.

    Sorry for any inconvenience.
    sal
  • Hi Sal ,
    Is there any example project which you may have for writing into a file in a mass storage device which I may be able to refer to ?

    Regards
    Anish
  • There is the usb_host_msc example.

    Are you using this already? If not, it will be helpful. We want to add support for this example in the future.

    sal
  • Hi Sal,

    Yes I am using this example to read and write . I am able to read . Its just writing which I am not sure of .
    Please have a look whenever you get the time and let me know what the issue may be.

    Anish
  • Hi Sal , I'm still not sure how to write reliably to the USB . Would you be able to have a look at it .

    Regards
    Anish
  • Unfortunately, we do not have a schedule to look into this yet. I have filed a bug for us to address this.

    sal