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

cc2541 osal_snv_write写不进去

求助!!!
场景:2541作丛机,手机APP连接2541后发送数据,然后2541保存并重启,现在发现在使用osal_snv_write()写入数据到flash的时候就出错了,写不进去,我的代码如下:判断手机APP发送的数据正确就会发送MODE_SWITCH_EVT

#define  SNV_ADDR 0x80
static void simpleBLEPeripheral_ProcessOSALMsg( osal_event_hdr_t *pMsg ) {static attHandleValueNoti_t pReport; uint8 ret;switch ( pMsg->event ){case KEY_CHANGE:simpleBLEPeripheral_HandleKeys( ((keyChange_t *)pMsg)->state, ((keyChange_t *)pMsg)->keys );break; case MODE_SWITCH_EVT: sys_config.role = BLE_ROLE_CENTRAL; ret = osal_snv_write(SNV_ADDR, sizeof(SYS_CONFIG), &sys_config);if(SUCCESS == ret) {pReport.len = 2;pReport.handle = 0x0035;pReport.value[0] = 'o';pReport.value[1] = 'k';GATT_Notification( 0, &pReport, FALSE );NPI_WriteTransport("Notify to app and reboot\r\n", osal_strlen("Notify to app and reboot\r\n"));Serial_Delay(200);HAL_SYSTEM_RESET();} else NPI_WriteTransport("Save fail\r\n", osal_strlen("Save fail\r\n")); break;default:// do nothingbreak;} }

我想请问是我写数据的时机不对?还是哪里有问题?

Viki Shi:

写入失败返回什么错误?使用SNV的注意点如下:

There are some important considerations when using this API:
1. These are blocking function calls and an operation may take several hundred milliseconds to complete. This is especially true for NV write operations. In addition, interrupts may be disabled for several milliseconds. It is best to execute these functions at times when they do not conflict with other timing-critical operations. For example, a good time to write NV items would be when the receiver is turned off.
2. Furthermore, the functions must not be called from an interrupt service routine, unless otherwise specified by a separate application note or release note of an implementation.
3. Try to perform NV writes infrequently. It takes time and power; also most flash devices have a limited number of erase cycles.
4. If the structure of one or more NV items changes, especially when upgrading from one version of a TI stack software to another, it is necessary to erase and re-initialize the NV memory. Otherwise, read and write operations on NV items that changed will fail or produce erroneous results.

user5111503:

回复 Viki Shi:

把某段不相关代码 编译进去后就好了。不知道为什么,是不是和编译器优化有关

赞(0)
未经允许不得转载:TI中文支持网 » cc2541 osal_snv_write写不进去
分享到: 更多 (0)