USB host msc stm32f107 stop writing to usb memory stick after 30-40 times. f_open() return FR_DISK_ERR
Hi. I'm tring to save data to usb memory stick. this is main fuction :
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;
}
}This is UsbTest_Write(); function
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, "asdfsdfsafdfadf\tasdfsdfsafdfadf\tasdfsdfsafdfadf\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
}When ı connect usb stick it starts to write. After write 30-40 times it stop to writing. If i disconnect usb stick and connect again. It is write again 30-40 times. I looked in debug and put break point after
UsbTest_Write()
function this time it write just 1 time and
UsbTest_Write()
function always return 0 in this line
if(f_open(&myFile, "a.csv", FA_WRITE | FA_OPEN_ALWAYS ) != FR_OK)
{
return 0;
}
Why can be this happen and how can i solve?
