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.
CC26x2
Note: The following instructions have been written for SDK 3_40_00_02 but can be adapted to quite any SDK version (that is why I provided the sources but also the diff files). In addition, the code was written for CC2642R but can be adapted to all the devices of the family (CC2652R, CC2652P, CC1352R, CC1352P)
At the end of this instruction, your project won’t be able anymore to pair. The goal is to save space in FLASH and RAM memory.
This modification is slightly more advanced but it's worth the money!
How to do this?
3. Do the following in simple_peripheral.c
Here are the diff file and the file you are supposed to get if you also removed the display, the secondary advertisement, the auto PHY functionalities and the connection parameters update functionalities:
--- C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\simple_peripheral_without_update_param.c Wed Feb 12 15:35:38 2020 +++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\simple_peripheral_SIMPLE.c Wed Feb 12 16:27:29 2020 @@ -139,28 +139,6 @@ void *pData; // pointer to message } spEvt_t; -// Container to store passcode data when passing from gapbondmgr callback -// to app event. See the pfnPairStateCB_t documentation from the gapbondmgr.h -// header file for more information on each parameter. -typedef struct -{ - uint8_t state; - uint16_t connHandle; - uint8_t status; -} spPairStateData_t; - -// Container to store passcode data when passing from gapbondmgr callback -// to app event. See the pfnPasscodeCB_t documentation from the gapbondmgr.h -// header file for more information on each parameter. -typedef struct -{ - uint8_t deviceAddr[B_ADDR_LEN]; - uint16_t connHandle; - uint8_t uiInputs; - uint8_t uiOutputs; - uint32_t numComparison; -} spPasscodeData_t; - // Container to store advertising event data when passing from advertising // callback to app event. See the respective event in GapAdvScan_Event_IDs // in gap_advertiser.h for the type that pBuf should be cast to. @@ -255,13 +233,6 @@ static void SimplePeripheral_performPeriodicTask(void); static void SimplePeripheral_updateRPA(void); static void SimplePeripheral_clockHandler(UArg arg); -static void SimplePeripheral_passcodeCb(uint8_t *pDeviceAddr, uint16_t connHandle, - uint8_t uiInputs, uint8_t uiOutputs, - uint32_t numComparison); -static void SimplePeripheral_pairStateCb(uint16_t connHandle, uint8_t state, - uint8_t status); -static void SimplePeripheral_processPairState(spPairStateData_t *pPairState); -static void SimplePeripheral_processPasscode(spPasscodeData_t *pPasscodeData); static void SimplePeripheral_charValueChangeCB(uint8_t paramId); static status_t SimplePeripheral_enqueueMsg(uint8_t event, void *pData); static uint8_t SimplePeripheral_addConn(uint16_t connHandle); @@ -281,13 +252,6 @@ /********************************************************************* * PROFILE CALLBACKS */ - -// GAP Bond Manager Callbacks -static gapBondCBs_t SimplePeripheral_BondMgrCBs = -{ - SimplePeripheral_passcodeCb, // Passcode callback - SimplePeripheral_pairStateCb // Pairing/Bonding state Callback -}; // Simple GATT Profile Callbacks static simpleProfileCBs_t SimplePeripheral_simpleProfileCBs = @@ -468,7 +432,7 @@ SimpleProfile_RegisterAppCBs(&SimplePeripheral_simpleProfileCBs); // Start Bond Manager and register callback - VOID GAPBondMgr_Register(&SimplePeripheral_BondMgrCBs); + VOID GAPBondMgr_Register(NULL); // Register with GAP for HCI/Host messages. This is needed to receive HCI // events. For more information, see the HCI section in the User's Guide: @@ -717,14 +681,6 @@ case SP_ADV_EVT: SimplePeripheral_processAdvEvent((spGapAdvEventData_t*)(pMsg->pData)); - break; - - case SP_PAIR_STATE_EVT: - SimplePeripheral_processPairState((spPairStateData_t*)(pMsg->pData)); - break; - - case SP_PASSCODE_EVT: - SimplePeripheral_processPasscode((spPasscodeData_t*)(pMsg->pData)); break; case SP_PERIODIC_EVT: @@ -1116,110 +1072,6 @@ } } - -/********************************************************************* - * @fn SimplePeripheral_pairStateCb - * - * @brief Pairing state callback. - * - * @return none - */ -static void SimplePeripheral_pairStateCb(uint16_t connHandle, uint8_t state, - uint8_t status) -{ - spPairStateData_t *pData = ICall_malloc(sizeof(spPairStateData_t)); - - // Allocate space for the event data. - if (pData) - { - pData->state = state; - pData->connHandle = connHandle; - pData->status = status; - - // Queue the event. - if(SimplePeripheral_enqueueMsg(SP_PAIR_STATE_EVT, pData) != SUCCESS) - { - ICall_free(pData); - } - } -} - -/********************************************************************* - * @fn SimplePeripheral_passcodeCb - * - * @brief Passcode callback. - * - * @return none - */ -static void SimplePeripheral_passcodeCb(uint8_t *pDeviceAddr, - uint16_t connHandle, - uint8_t uiInputs, - uint8_t uiOutputs, - uint32_t numComparison) -{ - spPasscodeData_t *pData = ICall_malloc(sizeof(spPasscodeData_t)); - - // Allocate space for the passcode event. - if (pData ) - { - pData->connHandle = connHandle; - memcpy(pData->deviceAddr, pDeviceAddr, B_ADDR_LEN); - pData->uiInputs = uiInputs; - pData->uiOutputs = uiOutputs; - pData->numComparison = numComparison; - - // Enqueue the event. - if(SimplePeripheral_enqueueMsg(SP_PASSCODE_EVT, pData) != SUCCESS) - { - ICall_free(pData); - } - } -} - -/********************************************************************* - * @fn SimplePeripheral_processPairState - * - * @brief Process the new paring state. - * - * @return none - */ -static void SimplePeripheral_processPairState(spPairStateData_t *pPairData) -{ - uint8_t state = pPairData->state; - - switch (state) - { - case GAPBOND_PAIRING_STATE_STARTED: - break; - - case GAPBOND_PAIRING_STATE_COMPLETE: - break; - - case GAPBOND_PAIRING_STATE_ENCRYPTED: - break; - - case GAPBOND_PAIRING_STATE_BOND_SAVED: - break; - - default: - break; - } -} - -/********************************************************************* - * @fn SimplePeripheral_processPasscode - * - * @brief Process the Passcode request. - * - * @return none - */ -static void SimplePeripheral_processPasscode(spPasscodeData_t *pPasscodeData) -{ - // Send passcode response - GAPBondMgr_PasscodeRsp(pPasscodeData->connHandle , SUCCESS, - B_APP_DEFAULT_PASSCODE); -} - /********************************************************************* * @fn SimplePeripheral_enqueueMsg *
Build and test your program. Except the eventual warning raised by SysConfig due to modification we did earlier, everything should build and work smoothly.
Could we do better? Yes but this modification is quite advanced!
In summary, here we have a software that does not use anymore the bonding/pairing possibilities provided by the BLE stack. However a non-negligible amount of FLASH is consumed by some calls to the bond manager functions (you can find these calls inside osal_icall_ble.c and icall_hci_tl.c)… this is useless and we are going to find a way to avoid this. You will see the code in these two files contains a few #ifdef used to do some conditional compilation.
The file ti_build_config.opt (in the folder Debug/syscfg of your project) contains the symbols used for the conditional compilation of your project (* Note: as you will understand latter, this file is generated by SysConfig and you might be required to launch a first build if the file has not been yet generated).
As you have seen in osal_icall_ble.c and icall_hci_tl.c when the symbol GAP_BOND_MGR is defined, some extra portions of code are compiled. To avoid this, we need to *not* declare the symbol GAP_BOND_MGR.
However, we cannot modify the content of ti_build_config.opt because all the modifications will be erased at each new compilation. Then we have two solutions:
OR
Here is the diff and the content of the build_config.opt.xdt file:
--- C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\build_config.opt.xdt Wed Feb 12 18:24:28 2020 +++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\build_config.opt_SIMPLE.xdt Wed Feb 12 17:54:18 2020 @@ -24,7 +24,7 @@ % if(ble.bondManager) { /* Include GAP Bond Manager */ --DGAP_BOND_MGR +/*-DGAP_BOND_MGR*/ %} % % if(ble.L2CAPCOC) {
/!\ Be careful, by modifying the file build_config.opt.xdt, you modify the way SysConfig is generating ALL the projects based on this SDK!
Here is the content of the file ti_build_config.opt the toolchain should use (no matter which option you chose):
--- C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\ti_build_config.opt Wed Feb 12 18:26:55 2020 +++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\ti_build_config_SIMPLE.opt Wed Feb 12 17:54:47 2020 @@ -9,7 +9,7 @@ -DHOST_CONFIG=PERIPHERAL_CFG /* Include GAP Bond Manager */ --DGAP_BOND_MGR +/*-DGAP_BOND_MGR*/ /* Include Transport Layer (Full or PTM) */ -DHCI_TL_NONE
Build and test your program. Except the eventual warning raised by SysConfig due to modification we did earlier, everything should build and work smoothly.
Here are the links to the different threads I wrote regarding simple_peripheral FLASH size optimization:
Remove display CC26x2 / CC13x2: e2e.ti.com/.../879276
Remove display CC2640R2: e2e.ti.com/.../3252666
Remove #2 advertisement CC26x2 / CC13x2: e2e.ti.com/.../3255504
Remove #2 advertisement CC2640R2: e2e.ti.com/.../880139
Remove RSSI monitoring and auto PHY update CC26x2 / CC13x2: e2e.ti.com/.../880155
Remove RSSI monitoring and auto PHY update CC2640R2: e2e.ti.com/.../880151
Remove connection params updates CC26x2 / CC13x2: e2e.ti.com/.../880171
Remove connection params updates CC2640R2: e2e.ti.com/.../880163
Remove pairing CC26x2 / CC13x2: e2e.ti.com/.../880181
Remove pairing CC2640R2: e2e.ti.com/.../880177