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.

CC2640R2F: How to remove #2 (long range) advertisement from simple_peripheral project

Part Number: CC2640R2F
Other Parts Discussed in Thread: BT-POWER-CALC

CC2640R2 (BLE5)

Note: The following instructions have been written for SDK 3_40_00_10 but can be adapted to quite any SDK version (that is why I provided the sources but also the diff files)

By removing the secondary advertisement (sometimes called "long range" advertisement) from the simple_peripheral example (usually called ble5_simple_peripheral) you can significantly save power. The power consumption due to the secondary advertisement (generally long range advertisement) can represent up to 80% of the power consumption of the advertisement period. Please consult the BT-POWER-CALC to have more details regarding power consumption.
In addition, this modification can help you to save memory (not really significant, but we still save 0.2kB i.e. increasing by 3% the OOB available FLASH – in addition the stack required is decreased).

How to do this?

  1. Import the project you want (the OOB ble5_simple_peripheral or the project where you have already removed the display function as shown here)

  2. In simple_peripheral.c, remove all the code related to the #2 advertisement and/or to the Long Range advertisement. A good way is to look for the variable advHandleLongRange. Delete also the advHandleLongRange variable.Here is the diff file and the file you are supposed to get if you also removed the display:

    simple_peripheral_remove_long_range_adv.diff
    --- C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_without_display.c	Tue Feb 11 16:12:35 2020
    +++ C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_SIMPLE.c	Tue Feb 11 16:12:11 2020
    @@ -353,7 +353,6 @@
     
     // Advertising handles
     static uint8 advHandleLegacy;
    -static uint8 advHandleLongRange;
     
     // Address mode
     static GAP_Addr_Modes_t addrMode = DEFAULT_ADDRESS_MODE;
    @@ -1022,29 +1021,6 @@
             status = GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
             SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
     
    -        // Use long range params to create long range set #2
    -        GapAdv_params_t advParamLongRange = GAPADV_PARAMS_AE_LONG_RANGE_CONN;
    -
    -        // Create Advertisement set #2 and assign handle
    -        status = GapAdv_create(&SimplePeripheral_advCallback, &advParamLongRange,
    -                               &advHandleLongRange);
    -        SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    -
    -        // Load advertising data for set #2 that is statically allocated by the app
    -        status = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_ADV,
    -                                     sizeof(advertData), advertData);
    -        SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    -
    -        // Set event mask for set #2
    -        status = GapAdv_setEventMask(advHandleLongRange,
    -                                     GAP_ADV_EVT_MASK_START_AFTER_ENABLE |
    -                                     GAP_ADV_EVT_MASK_END_AFTER_DISABLE |
    -                                     GAP_ADV_EVT_MASK_SET_TERMINATED);
    -
    -        // Enable long range advertising for set #2
    -        status = GapAdv_enable(advHandleLongRange, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
    -        SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    -
     #if defined(BLE_V42_FEATURES) && (BLE_V42_FEATURES & PRIVACY_1_2_CFG)
             if (addrMode > ADDRMODE_RANDOM)
             {
    @@ -1080,13 +1056,6 @@
           {
             // Start advertising since there is room for more connections
             GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
    -        GapAdv_enable(advHandleLongRange, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
    -      }
    -      else
    -      {
    -        // Stop advertising since there is no room for more connections
    -        GapAdv_disable(advHandleLongRange);
    -        GapAdv_disable(advHandleLegacy);
           }
     
           break;
    @@ -1110,7 +1079,6 @@
     
           // Start advertising since there is room for more connections
           GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
    -      GapAdv_enable(advHandleLongRange, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
     
           break;
         }
    @@ -2204,7 +2172,6 @@
     
       // Disable Advertising and destroy sets
       GapAdv_destroy(advHandleLegacy,GAP_ADV_FREE_OPTION_ALL_DATA);
    -  GapAdv_destroy(advHandleLongRange,GAP_ADV_FREE_OPTION_ALL_DATA);
     
       // Intercept NPI RX events.
       NPITask_registerIncomingRXEventAppCB(simple_peripheral_handleNPIRxInterceptEvent, INTERCEPT);
    
         simple_peripheral_SIMPLE.C

  3. Compile and test your project… Everything should still work smoothly!