Skip to main content
Visitor II
November 6, 2023
Question

USB host f_write fails when writing too many characters

  • November 6, 2023
  • 0 replies
  • 701 views

My project uses H7 MCU

When I use the USB host I try to write to the USB device, this works OK if I do not write more then 13 characters to a line any more and the data is not written to the file but the file is still created. The below code writes 1000 lines to a text file.

 

 

uint8_t wtext[] = "\n hello world!1"; // this works

// uint8_t wtext[] = "\n hello world!12"; // this does not work


fresult = f_mount(&USBHFatFS, (TCHAR const*)USBHPath, 1); // mount usb stick

fresult = f_open(&USBHFile, "1:/USBHost.txt", FA_CREATE_ALWAYS | FA_WRITE); // create file

f_close(&USBHFile); // close to ensure the file is created


for(int i = 0; i<1000; i++)

{

fresult = f_open(&USBHFile, "1:/USBHost.txt", FA_OPEN_APPEND | FA_WRITE); // open the file

fresult = f_write(&USBHFile, wtext, sizeof(wtext), &byteswritten); // write the data

f_close(&USBHFile); // close the file

}

fresult = f_mount(NULL, (TCHAR const*)USBHPath, 1); // unmount usb stick

 

 

 

I have attached the CubeMX file as a txt, the uploader did not like the file format :astonished_face:

Please can you help me unsderstand what I may change to overcome this.

    This topic has been closed for replies.