Other Parts Discussed in Thread: CC3220SF, , UNIFLASH
Hi there!
I am working on CC3220SF filesystem for storing data in no-volatile memory, such as configurations. This is why I chosen file system.
My first question, Is there also another way for storing data permanently in CC3220SF-LAUNCHXL?
Second related to filesystem file re-write.
I'm fallowing http://dev.ti.com/tirex/content/simplelink_academy_cc32xxsdk_1_13_00_29/modules/wifi_secure_file_system/wifi_secure_file_system.html tutorial for working with filesystem.
I'm able to open, read and write successfully as per tutorial. But when I am integrating this code with my aws_demo code (with free rtos), everything working well but during second time re-write I am getting fallowing error:
sl_FsOpen (re-write) error: -10344
Here is my code:
void dummyCreateReadWriteFile(char *inData) { long RetVal; //const char originalContent[] = "This is the original content!"; char originalContent[100]; strcpy(originalContent, inData); // Creating unsecured, MAX_SIZE file (this is the maximum length allowed) _i32 fd = sl_FsOpen(TEST_FILENAME, (SL_FS_CREATE | SL_FS_CREATE_FAILSAFE | SL_FS_CREATE_MAX_SIZE(MAX_FILE_SIZE)), &g_tokens[SL_FS_TOKEN_MASTER]); if(fd < 0) { UART_PRINT("[OPENING TIME]sl_FsOpen error: %d\n\r", fd); if(replaceFileContent(inData) == 0) { UART_PRINT("File content replaced successfully\r\n"); } else { UART_PRINT("Failed to replace file's content\r\n"); } } else { st_writeFile(fd, strlen(originalContent), originalContent); RetVal = sl_FsClose(fd, 0, 0, 0); if(fd < 0) { UART_PRINT("[WRITING TIME] sl_FsClose error: %d\n\r", RetVal); } else { UART_PRINT("[WRITE] file closed\r\n"); } } // Check that the new file exists (make sure the "0x020 - No File Safe" property is disabled for the new file) // Note that the size is rounded to the nearest block size st_listFiles(40,0); // Read the file content UART_PRINT("Reading file after CREATION:\n\r"); fd = sl_FsOpen(TEST_FILENAME, SL_FS_READ, &g_tokens[SL_FS_TOKEN_MASTER]); if(fd < 0) { UART_PRINT("[READING TIME] sl_FsOpen error: %d\n\r", fd); } else { st_readFile(fd, MAX_FILE_SIZE); RetVal = sl_FsClose(fd, 0, 0, 0); if(fd < 0) { UART_PRINT("sl_FsClose error: %d\n\r", RetVal); } else { UART_PRINT("[READ] file closed\r\n"); } } } int readConfig(char *buff) { int offset = 0; int RetVal = 0; int length = MAX_FILE_SIZE; _i32 fd; // Read the file content UART_PRINT("Reading configuration file\n\r"); fd = sl_FsOpen(TEST_FILENAME, SL_FS_READ, &g_tokens[SL_FS_TOKEN_MASTER]); if(fd < 0) { UART_PRINT("sl_FsOpen error: %d\n\r", fd); return fd; } while(offset < length) { RetVal = sl_FsRead(fd, offset, (_u8*)buff, length); if(RetVal == SL_ERROR_FS_OFFSET_OUT_OF_RANGE) {// EOF break; } if(RetVal < 0) {// Error UART_PRINT("sl_FsRead error: %d\n\r", RetVal); return RetVal; } offset += RetVal; length -= RetVal; } UART_PRINT("Read \"%s\" (%d bytes)....\n\r", buff, offset); return 0; } //Replacing file content int replaceFileContent(char *buf) { int RetVal = 0; _i32 fd; UART_PRINT("\n\r\n\r ** Replacing file content\n\r"); fd = sl_FsOpen(TEST_FILENAME, SL_FS_WRITE | SL_FS_WRITE_MUST_COMMIT, &g_tokens[SL_FS_TOKEN_MASTER]); if(fd < 0) { UART_PRINT("sl_FsOpen (re-write) error: %d\n\r", fd); return fd; } else { st_writeFile(fd, strlen(buf), buf); RetVal = sl_FsClose(fd, 0, 0, 0); if(RetVal < 0) { UART_PRINT("sl_FsClose (re-write) error: %d\n\r", RetVal); return RetVal; } } return 0; }
Also, st_listFiles(40,0); not working
Calling dummyCreateReadWriteFile() function from network_if.c where getting data from uart.
readConfig() function every time working without any problem but file replaceFileContent() function executing once successfully after that giving error every-time.