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.

TMS320F28377S: f_lseek function is not working as expected

Part Number: TMS320F28377S


Dear All,

I am using f_lseek function of chan FATFS to modify the file. I create one file in USB and write some data in it and this is working without any issue (I am  using example MSC in control suite for USB). I want to modify the content of file using f_lseek function. I write this function, it work as expected when I call it first time but second time the data is not modify. So please help me to solve this issue. 

int write_file(int argc, char *argv[])
{
    FRESULT fresult;
    DisableDog();
    DWORD *current_ptr=NULL;
    unsigned short usBytesWrite;
    unsigned short fp;
 
    //
    // Do not attempt to do anything if there is not a drive attached.
    //

    if(g_eState != STATE_DEVICE_READY)
    {
      return(FR_NOT_READY);
    }

    if(strlen(g_cCwdBuf) + strlen(argv[0]) + 1 + 1 > sizeof(g_cTmpBuf))
    {
       UARTprintf("Resulting path name is too long\n");
       return(0);
    }

    strcpy(g_cTmpBuf, g_cCwdBuf);

    fresult = f_open(&g_sFileObject,"test5.csv",FA_OPEN_EXISTING|FA_WRITE|FA_READ);

     if(fresult != FR_OK)
     {
       UARTprintf("Allocation error\n");
       return(fresult);
     }
     else
     {
       UARTprintf("Allocation successful\n");
     }
   
  fresult= f_lseek(&g_sFileObject,10);

    if(fresult==FR_OK)
    {
      UARTprintf("Fseek is ok\n");
    }

   char *w_buf= "6,7,8,9,0"; 
   char no_bytes=5;


   fresult = f_write(&g_sFileObject,w_buf,no_bytes,&usBytesWrite+10);


                   if(fresult != FR_OK)
                   {
                      UARTprintf("write error\n");
                      return(fresult);
                   }
                   else
                   {
                       UARTprintf("write ok\n");

                   }
  

   fresult=f_sync(&g_sFileObject);

                  if(fresult != FR_OK)
                  {
                      UARTprintf("File pointer error \n");
                      return(fresult);
                  }

   fresult= f_close(&g_sFileObject);

                  if(fresult != FR_OK)
                  {
                       UARTprintf("File closed error\n");
                       return(fresult);
                  }



 return;
}