How to Modify text file in USB host mode
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2012-08-09 2:28 AM
Posted on August 09, 2012 at 11:28
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); }
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2012-08-09 5:53 AM
Posted on August 09, 2012 at 14:53
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); }
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
