CC2340R5: How to make sure Bond Information is not corrupted?

Part Number: CC2340R5

Tool/software:

Hi Forum,

 I am working on project where i need to know bond info upon wakeup from shutdown or arbitrarily at runtime and also need to implement a mechanism to detect corruption. Could you suggest any API or base code for this?

Also, this gapbondmgr doc has API 'gapBondMgrReadBondRec()' which is used to read bond info but i don't see this API available in SDK 9.11.00.08. Furthermore the description of this API doesn't give clarity which bond record is returned if more than one bond info are present? for example, if there are 3 bond info and i were to read 1st and 3rd or may be all of them, how to do that?

Regards

Vaibhav

  • Hi !

    You are correct, the gapBondMgrReadBondRec has been replaced by the GapBondMgr_readBondFromNV function in the latest SDK. The gapBondNvRecord_t object passed to this function will be filled with the values of the bond. Both functions serve the same purpose. The documentation for this function currently has a bug where it is not displayed, but you can still read it in the C:\ti\simplelink_lowpower_f3_sdk_9_11_00_18\source\ti\ble\host\gapbondmgr\gapbondmgr.h file :

    /**
     * @fn      GapBondMgr_readBondFromNV
     *
     * @brief   Read bond record from NV
     *
     * @param   mode - whether to read by index (GAPBOND_READ_BY_IDX) or by address (GAPBOND_READ_BY_ADDR)
     * @param   pIdentifier - pointer to bond index (0 - GAP_BONDINGS_MAX) or device address (6 bytes BDADDR)
     * @param   addrType - address type, only relevant if mode = GAPBOND_READ_BY_ADDR
     * @output  pBondRecord - pointer to output, must be allocated by the caller
     *
     * @return  SUCCESS if bond was read successfully
     *          bleGAPNotFound if there is no bond record
     *          bleInvalidRange if the bond index is out of range or the mode is invalid
     *          bleGAPBondItemNotFound if an item is not found in NV
     */

    You can therefore select the bond either from index or from the address of the device you are bonded with.

    I don't think we support any functions for detecting corruption in the NVS. Could you expand on what your threat model or use case is for NVS corruption ?

    Kind regards,
    Lea

  • Hi Maxence,

    Use case here is keyfob, from the experience of previous development based on CC26xx, we observed NVS corruption issues and loss of bond info. To reduce the risk of unexpected resets during low-voltage conditions, we have implemented battery voltage monitoring. We are also evaluating strategies to protect NVS integrity and preserve bonding information. Could you suggest additional measures or best practices you’ve seen effective in preventing NVS corruption and bond loss?

    Regards

    Vaibhav

  • Hi !

    NVS corruption when losing power can happen if a NVS write is happening in the middle of a NVS write. But we are not aware of any NVS corruption problem when losing power and not using NVS, or when losing power and doing a NVS read.

    In order to be 100% sure that a NVS write is correct and is not corrupting anything, you can set the NVS_WRITE_POST_VERIFY flag in the parameters of the NVS_write function. This flag adds a NVS read after the NVS write, in order to make sure that the write is correct.

    Your code would look as follows :

    if (NVS_write(nvsHandle, (uint32_t)FLASH_ADDRESS(page, offset), pBuf, len, NVS_WRITE_POST_VERIFY) != NVS_STATUS_SUCCESS) 
    {
        // Handle write failure
        // Log or implement error handling
        NVS_close(nvsHandle);
        return;
    }
    
    // Continue code

    Kind regards,
    Lea