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: 程序运行时设置设备名,使用的还是旧名字

Part Number: CC2340R5


程序启动时不调用BLEAppUtil_initAdvSet和BLEAppUtil_advStart,而是等串口输入正确格式的名字后截取名字,使用advSetInitParamsSet_2替代advSetInitParamsSet_1。部分代码如下

static bStatus_t Periperal_modifyScanRespData(char *localName, uint16_t nameLen)
{
    bStatus_t status = SUCCESS;
    uint16_t dstRespDataLen;

    dstRespDataLen = scanRespData2Fill(localName, nameLen);

    advSetInitParamsSet_2.advDataLen = advSetInitParamsSet_1.advDataLen;
    advSetInitParamsSet_2.advData = advSetInitParamsSet_1.advData;
    advSetInitParamsSet_2.advParam = advSetInitParamsSet_1.advParam;
    advSetInitParamsSet_2.scanRespDataLen = dstRespDataLen;
    advSetInitParamsSet_2.scanRespData = scanResData2;

    return status;
}
bStatus_t Peripheral_changeDeviceBroadcastName(char *localName, uint16_t nameLen)
{
    bStatus_t status = SUCCESS;

    Periperal_modifyScanRespData(localName, nameLen);

    status = BLEAppUtil_initAdvSet(&peripheralAdvHandle_1, &advSetInitParamsSet_2);
    if(status != SUCCESS)
    {
        // Return status value
        return(status);
    }

    GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (void *)localName);

    status = BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
    if(status != SUCCESS)
    {
        // Return status value
        return(status);
    }
}

在以前的独立程序上运行正常,设置名字A后立马显示广播名A,重启设置名字B显示广播名B。

但是我为了使用OAD,不得不把程序分成了mcuboot、persistent和oad-onchip三部分,我的代码都加在了oad-onchip里。如果设置了名字A之后再重启设置名字B,广播名和连接后显示的设备名都是A,反复进出设备连接界面几次后更新为名字B。这中间没有再次设置设备名。

麻烦帮忙分析一下原因