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.

为何用CC3220S launchpad 在flash中创建文件失败?

Other Parts Discussed in Thread: CC3220S

char* DeviceFileName = "test.txt";
uint32_t MaxSize = 60*1024; //60K is max file size
int32_t DeviceFileHandle = -1;
int32_t RetVal; //negative retval is an error
uint32_t Offset = 0;
unsigned char InputBuffer[100];
unsigned long MasterToken = 0;

// Create a file and write data. The file in this example is secured, without signature and with a fail safe commit
//create a secure file if not exists and open it for write.
DeviceFileHandle = sl_FsOpen((unsigned char *)DeviceFileName,
SL_FS_CREATE|SL_FS_OVERWRITE | SL_FS_CREATE_SECURE | SL_FS_CREATE_NOSIGNATURE | SL_FS_CREATE_MAX_SIZE( MaxSize ),
&MasterToken);

if( DeviceFileHandle < 0 )
{
printf("create file %s failed!\n", DeviceFileName);
}

运行到这里,返回值-2018,错误! 什么原因呢?

  • 错误的完整log能否提供?
  • 只是在先前运行正常的一个DEMO 工程的main_tirtos.c 中,添加了flash 文件操作测试:
    插入在主线程创建之前。
    报错Log非常简单,就是上面源码中的出错打印信息。
    create file Wlist.txt failed!

    请问有没有example project 涉及到对cc3220S launchpad 串行flash创建读写文件?或者是有什么文档能参考?

    /*
    * ======== main ========
    */
    int main(void)
    {
    pthread_t thread;
    pthread_attr_t pAttrs;
    struct sched_param priParam;
    int retc;
    int detachState;

    /* Call board init functions */
    Board_initGeneral();

    /* Set priority and stack size attributes */
    pthread_attr_init(&pAttrs);
    priParam.sched_priority = 1;

    detachState = PTHREAD_CREATE_DETACHED;
    retc = pthread_attr_setdetachstate(&pAttrs, detachState);
    if(retc != 0)
    {
    /* pthread_attr_setdetachstate() failed */
    while(1)
    {
    ;
    }
    }

    pthread_attr_setschedparam(&pAttrs, &priParam);

    retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);
    if(retc != 0)
    {
    /* pthread_attr_setstacksize() failed */
    while(1)
    {
    ;
    }
    }

    //test flash file system
    FsTest();

    retc = pthread_create(&thread, &pAttrs, mainThread, NULL);
    if(retc != 0)
    {
    /* pthread_create() failed */
    while(1)
    {
    ;
    }
    }

    BIOS_start();

    return (0);
    }
  • 看下这个文件: file:///C:/ti/simplelink_cc32xx_sdk_2_20_00_10/docs/wifi_host_driver_api/html/group___file_system.html
    需安装SDK
  • 你要在sl_Start()调用之后才可以读写文件的。
  • 的确如您所说:调用sl_Start()后即可读写文件了。谢谢!
    This function must be called before any other SimpleLink API is used, or after sl_Stop is called for reinit the device。

    但还有疑问:
    1,lRetVal = sl_Start(0, 0, 0); 和lRetVal = sl_Start(NULL, NULL, NULL); 这两个语句有何区别?
    2,假设每个线程都要用到API,那需要分别启用sl_Start()和sl_Stop吗?
  • 1. 没区别

    2. 只要有一个线程调用了就好了。