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.

EK-TM4C1294XL: Writing data to USB Stick/Pen Drive using TM4C129X

Part Number: EK-TM4C1294XL
Other Parts Discussed in Thread: EK-TM4C123GXL

Hi All,


I'am using EK-tm4c1294xl Launchpad. I want to store the ADC data into a pen drive . Initially i was working on SD card( also implemented it) but I thought storing data in pen drive is easier for users than a SD card.

My first concern is likewise in SD Card I had to specify the SPI pins & connections in mmc-ek-tm4c129xl.c file , However in USB I guess the pins & communication mode is UART. So , Do I have to define pins for VBUS,D+,D- ,GND?

Secondly, Is there any reference code for writing data to USB.

I went through the USB_HOST_MSC.c file but it is for reading the data.I already tried the USB_DEV_BULK example and successfully implemented it.

kindly guide me from where to start.

  • Hello Sumit,

    Can you explain what you mean by define pin for USB?

    Reading and writting requires API. The example usb_host_msc does one aspect of the file access, you can use the same to add write to the code.
  • Hello Amit,

    I mean to say that for SD card I have to define Pins for SSI connection.
    The USB port in the launchpad is connected via UART(that's what my understanding says) . I've seen in EKTMC123G launchpad, the USB0 is connected to PB0, PB1. In EK-TM4C1294XL launchpad(which I'am using) I cannot find the default pins connected to USB port.

    I'am sorry for asking this query because I'am trying to learn USB for the first time .
  • Hello Amit,

    elaborating my previous post , I meant that for writing data into SD card, There is mmc-ek-tm4c1294xl.c file in which SPI connections are defined and power_on() & send_initial_clock_train() functions are available to configure SPI connection & start transmitting data by using f_write() function.

    However, there is no such file for USB. How to configure data transmit & receive pins for USB? or is there a default connection in launchpad for the same?
  • Hello Sumit

    The USB data pins are not connected to PB0 and PB1 on the EK-TM4C123GXL. PB0 and PB1 is VBUS and ID pins. To understand which pins to be used for USB on the EK-TM4C1294XL please refer to the datasheet for the device part number
  • Hello Amit,

    Thanks for your suggestions. I tried implementing the USB_HOST_MSC.C file & was successfully able to detect the pen drive and look at the files on the serial terminal.
    I also tried using f_write function in the same way as f_read has been used but could not create a new file and write data into it.
  • Hello Sumit,

    Though the device is different but the function usage should remain the same in example

    D:\ti\TivaWare_C_Series-2.1.3.156\examples\boards\dk-tm4c123g\qs-logger

    File Name: usbstick.c

    Function Name: USBStickOpenLogFile
  • Hello Amit,

    Bingo!!! Finally I 'am able to write the data in the USB stick. Thanks a lot for your help

    But, there is also some garbage value being written. I tried using f_lseek() function but still garbage value is there. below are the lines of code & attached is the excel sheet in which data is written.

    while(1)

       {

    uint32_t a=0;

        if(g_eState == STATE_DEVICE_READY)

                {

                   fresult = f_open(&g_sFileObject, "test47.csv", FA_WRITE|FA_OPEN_ALWAYS);

                        if(fresult != FR_OK)

                        {

              

                        }

                        char fileHeaders[] = "sensor1,sensor2,sensor3,sensor4\r\n";

                        fresult = f_write(&g_sFileObject, fileHeaders, sizeof(fileHeaders), &ui32BytesWrite);

    fresult = f_lseek(&g_sFileObject,f_size(&g_sFileObject));

                        char valueStr[150];

                        for(a=100;a<=249;a++)

                        {

                        usprintf(valueStr,"%d,%d,%d,%d\r\n",a,a,a,a);

                      

                        fresult = f_write(&g_sFileObject, valueStr, sizeof(valueStr), (UINT *)&ui32BytesWrite);

                        }

                        fresult= f_close(&g_sFileObject);

                }

    0654.TEST42.rar

  • Hello Sumit

    Please check the example code for SPMA076 (opus Audio Codec). It shows how to use f_lseek
  • Hello Amit,

    I went through the opus_enc_dec.c file. inside
    int Cmd_decode(int argc, char *argv[]) function the only place where f_lseek() is used as mentioned below

    //
    // Go back to top of the file to update the Size of the file
    //
    f_lseek(&g_sFileWriteObject, 0);
  • Hello Sumit

    And the issue is? You can look at examples provided on the FatFS on elm-chan.org/.../00index_e.html
  • Hello Amit,

    I studied how to use the f_lseek() function & also applied it in my code. I was able to append new data in the file , Move to top of file , add no. of BYTES.

    However, I'am still not able to get rid of garbage data. Is there some other reason for the unwanted data being displayed.

    Could you try the same code at your end. Iam just not able to debug it.
  • Hello Sumit,

    Please explain what do you mean by garbage data?
  • hello amit,

    kindly see the attached excel file. The first row of "sensor1" contains garbage data.

    4118.0654.TEST42.rar

  • Hello Sumit,

    What does the variable containing the sensor1 data show when you debug the program?