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.

[参考译文] CC2340R5:如何在运行时添加闪存写保护并取消保护?

Guru**** 2587345 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1412374/cc2340r5-how-to-add-flash-write-protection-and-remove-protection-during-runtime

器件型号:CC2340R5

工具与软件:

尊敬的团队:

如标题所述、我仅使用以下代码 、通过设置 VIMS 寄存器来添加写保护、并发送软件复位来消除保护。

void mine_nvs_read_and_write()
{
    NVS_Attrs regionAttrs;

    NVS_getAttrs(nvsHandle, &regionAttrs);

    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);
}

是否推荐采用此方法?  

谢谢!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Connor:

    我在 F3 SDK 中找不到修改 VIMS WEPRX 寄存器的任何其他 API、因此、直接硬件寄存器写入是完成这一点的唯一方法。  我想问您为什么需要在运行时修改闪存 MAIN 区域写入/擦除保护值?

    此致、
    Ryan

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢。

    因为我的客户希望遵循以下流程:应用程序更新-->添加保护-->运行直到下一次更新-->删除保护-->擦除并写入最新版本的应用程序

    这是在 OAD 期间建议的或合理的方法吗? 我还想知道、在你看来、这项保护措施是否必要?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    这通常不是一个用例。  客户试图防范什么?  如果写入/擦除保护值不变、它们会产生什么影响?

    此致、
    Ryan