This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF-LAUNCHXL: CC3220SF file re-write error

Part Number: CC3220SF-LAUNCHXL
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.

 

  • HI rajan,

    The error is SL_ERROR_FS_FILE_IS_PENDING_COMMIT (in errors.h). This means the file is still waiting to be committed, so the operation cannot be performed yet.
    Please read http://www.ti.com/lit/swru455 section 7.10

    -Aaron
  • Problem is solved after adding fallowing code:
    RetVal = sl_FsCtl(SL_FS_CTL_COMMIT, g_tokens[SL_FS_TOKEN_MASTER], TEST_FILENAME,
    (_u8 *)&FsControl, sizeof(SlFsControl_t), NULL, 0,
    &g_tokens[SL_FS_TOKEN_MASTER]);

    Re-write is working fine is single debug session but once stop debugging and start debugging again then I am able to read file again and again but file re-write not working in this case.
    Same in the case of uniflash also, in first time boot-up everything working fine but once restarted module then again file re-write error showing.
    I fallowed this dev.ti.com/.../wifi_secure_file_system.html tutorial for managing token.
    But I'm wondering that if token related issue then how every-time file read happening.

    Is there token related issue or still something wrong?
  • I found the problem, after checking error code in error.h file.
    Actually in "readConfig()" file, I'm opening file but not closing that's why when second time trying open file for reading then it's showing SL_ERROR_FS_FILE_IS_ALREADY_OPENED.

    Thanks