请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC2340R5 工具与软件:
尊敬的团队:
如标题所述、我仅使用以下代码 、通过设置 VIMS 寄存器来添加写保护、并发送软件复位来消除保护。
void mine_nvs_read_and_write()
{
NVS_Attrs regionAttrs;
NVS_getAttrs(nvsHandle, ®ionAttrs);
NVS_read(nvsHandle, 0, (void*) buffer, sizeof(signature));
NVS_read(nvsHandle, 0x800, (void*) buffer2, sizeof(signature2));
/*
* Determine if the NVS region contains the signature string.
* Compare the string with the contents copied into buffer.
*/
if (strcmp((char*) buffer, (char*) signature) == 0)
{
/* Write signature directly from the NVS region to the UART console. */
MenuModule_printf(0, 0, "Read Exist! : %s", buffer);
if((strcmp((char*) buffer2, (char*) signature2) == 0))
{
second_write_flag = true;
MenuModule_printf(0, 0, "Read2 Exist! : %s", buffer2);
}
/* Erase the entire flash sector. */
// NVS_erase(nvsHandle, 0, regionAttrs.sectorSize);
}
else
{
int status = NVS_write(nvsHandle, 0, (void*) signature,
sizeof(signature),
NVS_WRITE_ERASE | NVS_WRITE_POST_VERIFY);
// Add write protection
HWREG(VIMS_BASE + VIMS_O_WEPRB) = VIMS_WEPRB_VAL_S;
/* The signature was not found in the NVS region. */
MenuModule_printf(0, 0, "Writing signature to flash... return code: %d",
status);
MenuModule_printf(0, 0, "------ Add Protection --------");
}
if(second_write_flag == false)
{
int status = NVS_write(nvsHandle, 0x800, (void*) signature2,
sizeof(signature2),
NVS_WRITE_ERASE | NVS_WRITE_POST_VERIFY);
MenuModule_printf(0, 0, "--> Other: Writing flash... return code: %d",
status);
if (status < 0)
{
MenuModule_printf(0, 0, "--> Reset the device to remove protection");
NVIC_SystemReset();
}
else
{
NVS_read(nvsHandle, 0x800, (void*) buffer2, sizeof(signature2));
MenuModule_printf(0, 0, "--> After reset: Writing success... read: %s",
buffer2);
}
}
NVS_close(nvsHandle);
}
是否推荐采用此方法?
谢谢!