0

I'm trying to write data to usb memory stick with stm32f107. Main function is:

 while (1)
  {
    /* USER CODE END WHILE */
MX_USB_HOST_Process();

/* USER CODE BEGIN 3 */
 switch(Appli_state)
            {
                case APPLICATION_IDLE:
                    break;
                case APPLICATION_START:
                    counter_start++;
                    if(f_mount(&myUsbFatFS, (TCHAR const*)USBH_Path, 0) == FR_OK)
                        {
                           UsbTest_Write();
                        }
                    break;
                case APPLICATION_READY:
                    break;

                case APPLICATION_DISCONNECT:
                    break;
            }

  }

Write function is :

bool UsbTest_Write(void)
{
    //Open or Create file for writing
    if(f_open(&myFile, "a.csv", FA_WRITE | FA_OPEN_ALWAYS ) != FR_OK)
    {
        return 0;
    }
    //Copy test Text to my temporary read/write buffer
    f_lseek(&myFile,myFile.fsize);
    sprintf(rwtext, "test\n");
    //Write to text file
    res = f_write(&myFile, (const void *)rwtext, strlen(rwtext), &byteswritten);
    if((res != FR_OK) || (byteswritten == 0))
    {
        return 0;
    f_close(&myFile);
}
f_close(&myFile);
return 1; //Success

}

I have 2GB usb memory stick and it works without any problem. When i try to write the other memory sticks that 8GB and 16GB it's not write. I debugged and

f_open()->find_volume()->get_ldnumber()

get_idnumber() function returns 0 so f_open() function return FR_DISK_ERR.

what can be the reason and how to solve this problem?

km-74
  • 3
  • 4

0 Answers0