TI中文支持网
TI专业的中文技术问题搜集分享网站

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

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,错误! 什么原因呢?

Viki Shi:

错误的完整log能否提供?

convex j:

回复 Viki Shi:

只是在先前运行正常的一个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 systemFsTest();
retc = pthread_create(&thread, &pAttrs, mainThread, NULL);if(retc != 0){/* pthread_create() failed */while(1){;}}
BIOS_start();
return (0);
}

Viki Shi:

回复 convex j:

看下这个文件: file:///C:/ti/simplelink_cc32xx_sdk_2_20_00_10/docs/wifi_host_driver_api/html/group___file_system.html
需安装SDK

convex j:

回复 Yonghua Pan:

的确如您所说:调用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吗?

赞(0)
未经允许不得转载:TI中文支持网 » 为何用CC3220S launchpad 在flash中创建文件失败?
分享到: 更多 (0)