cancel
Showing results for 
Search instead for 
Did you mean: 

Problem about the usbhost+MSC+Fatfs with stm32cubemx

HLiu.2
Associate

Dear everyone,

Here is my problem about the usbhost+MSC+Fatfs function with stm32cubemx in MCU stm32F407 and stm32L475, with a very strange issue:

There is a bug about the f_write or f_f_sync, the operation and result is as followed:

First test:

1.      f_open // make a new file;

2.      f_write// write something, return is FR_OK, and “the number of bytes written�? is right

3.      f_close// close the file, return is FR_OK, and the f_sync is called and return ok.

4.      //remove the disk and plugin PC

result: file created,but nothing written.

Second test:

1.      f_open // make a new file;

2.      f_write// write something, return is FR_OK, and “the number of bytes written�? is right

3.      f_write// write something, return is FR_OK, and “the number of bytes written�? is right

4.      f_close// close the file, return is FR_OK, and the f_sync is called and return ok.

5.      //remove the disk and plugin PC

result: file created,but nothing written.

Third test:

1.      f_open // make a new file;

2.      f_write “AA�?// write something, return is FR_OK, and “the number of bytes written�? is right

3.      f_sync //return good;

4.      f_write “BB�?// write something, return is FR_OK, and “the number of bytes written�? is right

5.      f_sync //return good;

6.      f_close// close the file, return is FR_OK, and the f_sync is called and return ok.

7.      //remove the disk and plugin PC

8.      result: file created, only “AA�? is written

Fourth test:

1.      f_open // make a new file;

2.      f_write “AA�?// write something, return is FR_OK, and “the number of bytes written�? is right

3.      f_sync //return good;

4.      f_write “BB�?// write something, return is FR_OK, and “the number of bytes written�? is right

5.      f_sync //return good;

6.      f_close// close the file, return is FR_OK, and the f_sync is called and return ok.

7.      f_open // only for read;

8.      f_read//read something, return OK

9.      f_close;

10.  //remove the disk and plugin PC

result: file created, “AA�? “BB�? are written, result is good.

The tests show, if you do some write operation, you need perform one more write or read operation after sync the file, only that the content can be really write to the file.

Is there any people meet the same problem and anybody can kindly give me some suggestion?

Thank you and best wishes.

PS the followed is the picture of the cubemx and the code, which is very simple:

0693W000004IJQUQA4.png

2 REPLIES 2
Not applicable

[STM32 USB training - 11.2 USB MSC host labs]

https://www.youtube.com/watch?v=dC0d8CVEPrQ

[[STM32] STM32F4 USB HOST + Pendrive: Writing to text file]

https://www.youtube.com/watch?v=uIOb5sSFyUY

Good luck!

Thank you I will try to visit the youtube...... I need the luck.