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.

How to erase single bonding?

Other Parts Discussed in Thread: CC2640, CC2541

Hi

I try to erase bondings in simpleBLECentral project with cc2640.my code is as below:

 idx = GAPBondMgr_ResolveAddr(testAddrType, testAddr, NULL );  //find bond mgr index
 LCD_WRITE_STRING_VALUE("del idx", idx, 10, LCD_PAGE6); 
 LCD_WRITE_STRING_VALUE("del bondCount", bondCount, 10, LCD_PAGE7); 
 if (idx < bondCount) //if address found in bond manager
 {
             int8_t tmp[B_ADDR_LEN + 1];
             tmp[0] = testAddrType;
            // memcpy(&tmp[1], testAddr, B_ADDR_LEN);
            // Reverse bytes
            // VOID osal_revmemcpy( &tmp[1], testAddr, B_ADDR_LEN );
             tmp[1] = testAddr[0];
             tmp[2] = testAddr[1];
             tmp[3] = testAddr[2];
             tmp[4] = testAddr[3];
             tmp[5] = testAddr[4];
             tmp[6] = testAddr[5];
             GAPBondMgr_SetParameter(GAPBOND_ERASE_ALLBONDS, NULL, NULL);
             //GAPBondMgr_SetParameter(GAPBOND_ERASE_SINGLEBOND, B_ADDR_LEN + 1, tmp);
             for (cnt = 0; cnt < 10; cnt++)
                 Task_sleep(SLEEP_TICKS);
    }

when I used GAPBOND_ERASE_ALLBONDS,I erased the bonding successfully.but when I use GAPBOND_ERASE_SINGLEBOND,I am failed to erase.

  • You are correct to use GAPBOND_ERASE_SINGLEBOND.  Assuming you are passing an address into the GAPBondMgr_SetParameter() function that is actually in the bond table, this should work.  

    Note that the bond will only be erased when there is an opportunity to do so in a way that doesn't break the BLE connection.  This means that the active connection must first be terminated.

    I would recommend stepping through the following code in GAPBondMgr_SetParameter():

       case GAPBOND_ERASE_SINGLEBOND:
          if ( len == (1 + B_ADDR_LEN) )
          {
            uint8 idx;
            uint8 devAddr[B_ADDR_LEN];
    
            // Reverse bytes
            VOID osal_revmemcpy( devAddr, (uint8 *)pValue+1, B_ADDR_LEN );
            
            // Resolve address and find index
            idx = GAPBondMgr_ResolveAddr( *((uint8 *)pValue), devAddr, NULL );
            if ( idx < GAP_BONDINGS_MAX )
            {
              // Make sure there's no active connection
              if ( GAP_NumActiveConnections() == 0 )
              {
                // Erase bond
                VOID gapBondMgrEraseBonding( idx );
                
                // See if NV needs a compaction
                VOID osal_snv_compact( NV_COMPACT_THRESHOLD );
                
                // Make sure Bond RAM Shadow is up-to-date
                gapBondMgrReadBonds();
              }
              else
              {
                // Mark entry to be deleted when disconnected
                bondsToDelete[idx] = TRUE;
              }
            }
            else
            {
              ret = INVALIDPARAMETER;
            }
          }
          else
          {
            // Parameter is not the correct length
            ret = bleInvalidRange;
          }
          break;

  • Hi Tim
    Thank you for your reply. After I reversed the testAddr's order,it was OK.
    BTW,I have another question,How can I protect the codes which have been flashed into cc2640?I don't want the codes can be read out from flash.
    and I must make sure that the chip can be re-flashed new codes again.
  • Hi Dan,

    If you want to disable flash read access through JTAG this is done by disabling JTAG access to the various JTAG DAP / TAPs. After this is done you can only re-flash the device by doing a mass erase of the whole flash before re-flashing again. See the technical reference manual (SWCU117- "Device Configuration") and CCFG (appBLE_ccfg.c) in our example BLE projects.

    Regards,
    Svend
  • Hi Svend,I modified the settings in ccfg.c as below:
    //#####################################// Debug access settings
    //#####################################
    #defineSET_CCFG_CCFG_TI_OPTIONS_TI_FA_ENABLE 0x00 // Disable unlocking of TI FA option.
    // #define SET_CCFG_CCFG_TI_OPTIONS_TI_FA_ENABLE 0xC5 // Enable unlocking of TI FA option with the unlock code
    #defineSET_CCFG_CCFG_TAP_DAP_0_CPU_DAP_ENABLE 0x00 // Access disabled
    // #define SET_CCFG_CCFG_TAP_DAP_0_CPU_DAP_ENABLE 0xC5 // Access enabled if also enabled in FCFG
    #define SET_CCFG_CCFG_TAP_DAP_0_PRCM_TAP_ENABLE 0x00 // Access disabled
    // #define SET_CCFG_CCFG_TAP_DAP_0_PRCM_TAP_ENABLE 0xC5 // Access enabled if also enabled in FCFG
    #define SET_CCFG_CCFG_TAP_DAP_0_TEST_TAP_ENABLE 0x00 // Access disabled
    // #define SET_CCFG_CCFG_TAP_DAP_0_TEST_TAP_ENABLE 0xC5 // Access enabled if also enabled in FCFG
    #define SET_CCFG_CCFG_TAP_DAP_1_PBIST2_TAP_ENABLE 0x00 // Access disabled
    // #define SET_CCFG_CCFG_TAP_DAP_1_PBIST2_TAP_ENABLE 0xC5 // Access enabled if also enabled in FCFG
    #define SET_CCFG_CCFG_TAP_DAP_1_PBIST1_TAP_ENABLE 0x00 // Access disabled
    // #define SET_CCFG_CCFG_TAP_DAP_1_PBIST1_TAP_ENABLE 0xC5 // Access enabled if also enabled in FCFG
    #define SET_CCFG_CCFG_TAP_DAP_1_WUC_TAP_ENABLE 0x00 // Access disabled
    // #define SET_CCFG_CCFG_TAP_DAP_1_WUC_TAP_ENABLE 0xC5 // Access enabled if also enabled in FCFG
    After I flashed the code into cc2640 with smartRF flash programmer 2, I could not read out the code,but when I wanted to re-flash the chip,I could not do that.
    smartRF flash programmer 2 promted ">Start flash erase ...
    >Unable to halt target CPURegards,Dan
  • Hi Dan,

    You have locked the device from JTAG access so that is expected. To recover it you need to do a forced mass erase, found under the "wrench" in the upper right corner of SRF Programmer 2.

    .:Svend

  • Hi Tim

    my project is SimpleBLEPeripheral with CC2541

     When I try to erase the oldest bonding information with   case GAPBOND_ERASE_SINGLEBOND,How to fill the parameter about "len" and "*pValue"in bStatus_t GAPBondMgr_SetParameter( uint16 param, uint8 len, void *pValue ),Is the pValue means adress of the information ? and where can I get the address of the information?

    Thank you !

    best regards for you!