2012-08-09 02:28 AM
does anyone have idea how to modify a text file in usb host mode using Fatfs library.
I have a working project of usb host and successfully writing a new file using the code below. but i dont have the idea how to modify or append info in already existing file./* Register work area for logical drives */
f_mount(0, &fatfs); if(f_open(&file, ''0:STM32.TXT'',FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) { /* Write buffer to file */ bytesToWrite = sizeof(writeTextBuff); res= f_write (&file, writeTextBuff, bytesToWrite, (void *)&bytesWritten); if((bytesWritten == 0) || (res != FR_OK)) /*EOF or Error*/ { USART2_SendData_s(''> STM32.TXT CANNOT be writen.\n''); } else { USART2_SendData_s(''> 'STM32.TXT' file created\n''); } /*close file and filesystem*/ f_close(&file); }2012-08-09 05:53 AM
Use FA_OPEN_ALWAYS, and f_lseek()
http://elm-chan.org/fsw/ff/en/open.html
Perhaps :FIL f;
if( f_open( &f, ''log.txt'', FA_WRITE|FA_OPEN_ALWAYS ) == FR_OK ) { u32 wrt=0;f_lseek( &f, f.fsize );
f_write( &f, buffer, strlen(buffer), &wrt ); f_close( &f); }