Hello TI Experts,
I am currently migrating software built for the CC2640 to our new boards which have the CC2642R1. I am encountering some unexpected behavior with file operations implemented through the FATFS middleware from simplelink_cc26x2_sdk_2_30_00_34. The first issue that I am encountering involves the creation of multiple files. Code from the CC2640 device that creates two separate files is now only creating one file when used on the CC2642R1, despite both operations returning fr = 0. We have created a workaround for this issue by writing a dummy string into the second file being opened using f_puts(). For some reason this allows the file to be created and written to the microSD card properly.
Additionally, in the original CC2640 code we were able to leave the second created file open and have the device write to it continuously with periodic f_sync() operations. However, when implementing this same process on the CC2642R1, we get an fr = 9 error when trying to write block data to the continuously opened file. In order to solve this issue, I had to adjust the code to open and close the file every time block data is written to it. This solution is not ideal due to the time penalty incurred by the f_close() and f_open() calls.
I have the following questions:
-
Why do I have to write a dummy string to get the second file to be created?
-
Why am I not able to leave a file open for continuous writing like I was able to do in previous builds on the CC2640?
Shown below is a portion of code that was used on our CC2640 device:
fresult = f_open(&src, "FileNum", FA_READ); if(fresult == FR_NO_FILE) { fileCounter = 1; #if SERIAL_DEBUG send_debug_cmd("No file found! \a"); #endif } else { f_gets(fileName, 16, &src); f_close(&src); fileCounter = atoi(fileName); } fileCounter++; f_open(&src, "FileNum", FA_CREATE_ALWAYS | FA_WRITE); f_printf(&src, "%d", fileCounter); f_close(&src); f_close(&src); fresult = f_open(&src, fileName, FA_WRITE|FA_CREATE_ALWAYS); System_printf("fresult after f_open %d\n", fresult); System_flush(); f_sync(&src); } void inline write_blockdata_to_sd(uint32_t *blockdata, size_t blocksize, uint32_t timestamp){ fresult += f_write(&src, blockdata, blocksize * sizeof(uint32_t), &bytesWritten); if(timeToSync) { fresult += f_sync(&src); timeToSync = false; }
Shown below is a portion of the CC2642R1 code that has the workarounds to address the previously mentioned issues:
TCHAR var[260]; strcpy(var, "STEPHEN IS THE BEST"); fr = f_open(&src, "FileNum", FA_READ); System_printf("fr after f_open %d\n", fr); System_flush(); if(fr == FR_NO_FILE) fileCounter = 1; else { f_gets(fileName, 16, &src); f_close(&src); fileCounter = atoi(fileName); System_printf("file counter ATOIen %d\n", fileCounter); System_flush(); } sprintf(str, "%d", fileCounter); fileCounter++; f_open(&src, "FileNum", FA_CREATE_ALWAYS | FA_WRITE); f_printf(&src, "%d", fileCounter); f_close(&src); System_printf("fileName %s\n", str); System_flush(); fr =f_open(&src, str, FA_WRITE|FA_CREATE_ALWAYS); System_printf("fr after f_open %d\n", fr); System_flush(); /* Open the source file */ f_close(&src); } void inline write_blockdata_to_sd(uint32_t *blockdata, size_t blocksize, uint32_t timestamp){ fr = f_open(&src, str, FA_WRITE|FA_OPEN_APPEND); System_printf("fr after opening this file: %d\n", fr); System_flush(); fr += f_write(&src, blockdata, blocksize * sizeof(uint32_t), &bytesWritten); System_printf("fr after f_write %d\n", fr); System_flush(); if(timeToSync) { fr += f_sync(&src); timeToSync = false; } f_close(&src); System_printf("Done writing.\nLeaving write_blockdata_to_sd()\n"); System_flush(); return;