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: API to use to send user data in advertisement packet in BLE Broadcast role . we want to accomplish this with legacy BLE 4.2

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG,

Hi ,

We are using the simplelink_lowpower_f3_sdk_7_40_00_64 , which provides the basic ble example which is written using  FreeRTOS. 

Question #1:  Sys config tool get crash when we try to change Advertisement parameter values in sysonfig. Why is that happening? What is the fix for it ? 

We want to experiment with the BLE as a broadcaster role. So we selected that in  sysconfig. There is a tool crash when we are trying to update the advertising parameter configuration. in sys config    

See the below image

          

Even though the sys config tool crashed. It is generating some default advertisement configuration parameters. 

Code was able to compile and i am able to see the adv data. 

Question#2: 

In order to  send  our user data in advertisement packet . I was referring 

Scanning and Advertising Basics from TI website , it is giving information. about how to change advertisement packet. I  tried  in similar way for broadcast example. It is crash in 

below code  line . What is that we are doing wrong. Please provide us with some other example or some other material through which shall help us in achieving this function. 

status = GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);

if (status != SUCCESS)
for(;;); // Loop

 /** New Code **/
                BLEAppUtil_AdvEventData_t * pkt = (BLEAppUtil_AdvEventData_t *)pMsgData;
                if (pkt->pBuf->advHandle == broadcasterAdvHandle_1)
                    {
                        bStatus_t status = FAILURE;

                        status = GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);

                        if (status != SUCCESS)
                            for(;;); // Loop

                        uint8_t ADV_DATA2_LEN = 11;
                        uint8_t *advData2 = ICall_malloc(ADV_DATA2_LEN);

                        advData2[0] = 0x02;
                        advData2[1] = GAP_ADTYPE_FLAGS;
                        advData2[2] = GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED | GAP_ADTYPE_FLAGS_GENERAL;

                        advData2[3] = 0x07;
                        advData2[4] = GAP_ADTYPE_MANUFACTURER_SPECIFIC;
                        advData2[5] = data[0];
                        advData2[6] = data[1];
                        advData2[7] = data[2];
                        advData2[8] = data[3];
                        advData2[9] = data[4];
                        advData2[10] = data[5];

                        broadcasterAdvHandler.eventMask = BLEAPPUTIL_ADV_END_AFTER_DISABLE
                                                        | BLEAPPUTIL_ADV_SET_TERMINATED;
                                                        //| BLEAPPUTIL_SCAN_REQ_RECEIVED;

                        data[5] += 0x01;
                        if(data[5] == 0xFF)
                        {
                            data[5] = 0x01;
                        }

                        status = GapAdv_loadByHandle(broadcasterAdvHandle_1,
                                                            GAP_ADV_DATA_TYPE_ADV,
                                                            ADV_DATA2_LEN,
                                                            advData2);

                        if (status != SUCCESS)
                            for(;;);


                        /** End New Code **/
                    }
 

attaching the modified source code for your reference 

/******************************************************************************

 @file  app_broadcaster.c

 @brief This example file demonstrates how to activate the broadcaster role with
 the help of BLEAppUtil APIs.

 BroadcasterAdvHandler structure is used for define advertising event handling
 callback function and eventMask is used to specify the events that
 will be received and handled.
 In addition, fill the BLEAppUtil_AdvInit_t structure with variables generated
 by the Sysconfig.

 In the events handler functions, write what actions are done after each event.
 In this example, A message will be printed after enabling/disabling
 advertising.

 In the Peripheral_start() function at the bottom of the file, registration,
 initialization and activation are done using the BLEAppUtil API functions,
 using the structures defined in the file.

 More details on the functions and structures can be seen next to the usage.

 Group: WCS, BTS
 Target Device: cc23xx

 ******************************************************************************

 Copyright (c) 2022-2023, Texas Instruments Incorporated
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 *  Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

 *  Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.

 *  Neither the name of Texas Instruments Incorporated nor the names of
 its contributors may be used to endorse or promote products derived
 from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 ******************************************************************************


 *****************************************************************************/

#if defined( HOST_CONFIG ) && ( HOST_CONFIG & ( BROADCASTER_CFG ) )

//*****************************************************************************
//! Includes
//*****************************************************************************
#include "ti_ble_config.h"
#include <ti/bleapp/ble_app_util/inc/bleapputil_api.h>
#include <ti/bleapp/menu_module/menu_module.h>
#include <app_main.h>

//*****************************************************************************
//! Prototypes
//*****************************************************************************
void Broadcaster_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData);

//*****************************************************************************
//! Globals
//*****************************************************************************


BLEAppUtil_EventHandler_t broadcasterAdvHandler =
{
    .handlerType    = BLEAPPUTIL_GAP_ADV_TYPE,
    .pEventHandler  = Broadcaster_AdvEventHandler,
    .eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                      BLEAPPUTIL_ADV_END_AFTER_DISABLE
};

//! Store handle needed for each advertise set
uint8 broadcasterAdvHandle_1;

const BLEAppUtil_AdvInit_t broadcasterInitAdvSet1 =
{
    /* Advertise data and length */
    .advDataLen        = sizeof(advData1),
    .advData           = advData1,

    /* Scan respond data and length */
    .scanRespDataLen   = 0,
    .scanRespData      = NULL,

    .advParam        = &advParams1
};

const BLEAppUtil_AdvStart_t broadcasterStartAdvSet1 =
{
  /* Use the maximum possible value. This is the spec-defined maximum for */
  /* directed advertising and infinite advertising for all other types */
  .enableOptions         = GAP_ADV_ENABLE_OPTIONS_USE_MAX,
  .durationOrMaxEvents   = 0
};

//*****************************************************************************
//! Functions
//*****************************************************************************

/*********************************************************************
 * @fn      Broadcaster_AdvEventHandler
 *
 * @brief   The purpose of this function is to handle advertise events
 *          that rise from the GAP and were registered in
 *          @ref BLEAppUtil_RegisterGAPEvent
 *
 * @param   event - message event.
 * @param   pMsgData - pointer to message data.
 *
 * @return  none
 */
void Broadcaster_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
{
#if 1
    static char data[6]= {'h','e','l','l','o','1'};
#endif

    switch(event)
    {
        case BLEAPPUTIL_ADV_START_AFTER_ENABLE:
        {
            MenuModule_printf(APP_MENU_ADV_EVENT, 0, "Adv status: Started - handle: "
                              MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
                              ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
#if 1

            /** New Code **/
                BLEAppUtil_AdvEventData_t * pkt = (BLEAppUtil_AdvEventData_t *)pMsgData;
                if (pkt->pBuf->advHandle == broadcasterAdvHandle_1)
                    {
                        bStatus_t status = FAILURE;

                        status = GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);

                        if (status != SUCCESS)
                            for(;;); // Loop

                        uint8_t ADV_DATA2_LEN = 11;
                        uint8_t *advData2 = ICall_malloc(ADV_DATA2_LEN);

                        advData2[0] = 0x02;
                        advData2[1] = GAP_ADTYPE_FLAGS;
                        advData2[2] = GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED | GAP_ADTYPE_FLAGS_GENERAL;

                        advData2[3] = 0x07;
                        advData2[4] = GAP_ADTYPE_MANUFACTURER_SPECIFIC;
                        advData2[5] = data[0];
                        advData2[6] = data[1];
                        advData2[7] = data[2];
                        advData2[8] = data[3];
                        advData2[9] = data[4];
                        advData2[10] = data[5];

                        broadcasterAdvHandler.eventMask = BLEAPPUTIL_ADV_END_AFTER_DISABLE
                                                        | BLEAPPUTIL_ADV_SET_TERMINATED;
                                                        //| BLEAPPUTIL_SCAN_REQ_RECEIVED;

                        data[5] += 0x01;
                        if(data[5] == 0xFF)
                        {
                            data[5] = 0x01;
                        }

                        status = GapAdv_loadByHandle(broadcasterAdvHandle_1,
                                                            GAP_ADV_DATA_TYPE_ADV,
                                                            ADV_DATA2_LEN,
                                                            advData2);

                        if (status != SUCCESS)
                            for(;;);


                        /** End New Code **/
                    }
#endif
            break;
        }

        case BLEAPPUTIL_ADV_END_AFTER_DISABLE:
        {
            MenuModule_printf(APP_MENU_ADV_EVENT, 0, "Adv status: Ended - handle: "
                              MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
                              ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
            break;
        }

        default:
        {
            break;
        }
    }
}

/*********************************************************************
 * @fn      Broadcaster_start
 *
 * @brief   This function is called after stack initialization,
 *          the purpose of this function is to initialize and
 *          register the specific events handlers of the broadcaster
 *          application module
 *
 * @return  SUCCESS, errorInfo
 */
bStatus_t Broadcaster_start()
{
    bStatus_t status = SUCCESS;

    status = BLEAppUtil_registerEventHandler(&broadcasterAdvHandler);
    if(status != SUCCESS)
    {
        // Return status value
        return(status);
    }

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

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

    // Return status value
    return(status);
}

#endif // ( HOST_CONFIG & ( BROADCASTER_CFG ) )

With Regards

Ilanchezhian T  

  • Hello Ilanchezhian,

    Thanks for reaching out!

    For your first question, this bug was recently reported by another user and passed along to our internal team to resolve in a future release of the SDK. I do not have the specifics on when this will be though. 

    For the second question, we will look through the code you have provided and get back to you shortly. 

    Best regards,

    Luke

  • Let us know whether we have some inputs in sending BLE data via advertising packet while putting the BLE in broadcaster mode 

  • Hello Ilanchezhian,

    Understood. Could you please help me by sharing a bit more details about what you mean by " It is crash in"?

    I can see that the device is advertising with the code you provided. I also modified the Device Role to Broadcaster inside the sysconfig.

    BR,

    David.

  • Hi 

    Could you please help me by sharing a bit more details about what you mean by " It is crash in"?

     May be my observation is wrong here since I could see the advertisement packet even with our code change, please see the attached screenshot. 

    I could confirm that our modification taken place , uart log statement as mentioned in below screenshot. Also got this output. 

      

    I have taken reference from TI, website for my code change, hoping that I will be able to send my user data in advertisement packet with this change, but it has not happened. Below is the screenshot for reference document which I have referred too.

      

    So what the code I have added has no effect.`

    It does not meet my objective which is to send user data for example say hello1 on the advertisement packet. 

    Also we want to send updated data in the advertisement packet all the time, this is the application use case.

    So the Ask here is: 

    Using the sample application Basic BLE as an example, we want to operate in BLE broadcaster mode since we do not want to get connected by BLE central device. But need to periodically update the user data as part of advertisement data.

    Could you please guide us how it can be accomplished this in our application using cc2340R5 simpllink BLE stack. 

    Thanks & Regards

    Ilanchezhian T 

  • Hello Ilanchezhian,

    Thanks for the additional information.

    I have modified the basic_ble project using your code and I was able to validate using a Bluetooth sniffer that the information sent ("hello1") as part of the advertisement report (inside Manufacturer Specific Data) is correct.

    65 68 6c 6c 6F 31 - ehllo1 (first two are not in order as it is the Manufacturer data that is parsed differently).

    You could double check this as well with a bluetooth sniffer (if you have one at hand) or use another cc23xx/cc26 device to read the manufacturer data from the advertisement report.

    BR,

    David.

  • Hi David,

    Sorry , I could not see my BLE device get scanned.

    Also in the same post i have mentioned CCS tool getting crashed, could it be the dependency on that.

    I am using  Windows 11 , CCS version 

    Code Composer Studio
    Version: 12.6.0.00008

    Excerpt from the same post, top you can see details 

    [Question #1:  Sys config tool get crash when we try to change Advertisement parameter values in sysconfig. Why is that happening? What is the fix for it ? 

    We want to experiment with the BLE as a broadcaster role. So we selected that in  sysconfig. There is a tool crash when we are trying to update the advertising parameter configuration in sys config   ] 

    Could you please provide your environment details. 

    With Regards

    Ilanchezhian T 

  • Can you send me your complete project folder such that i shall try and confirm 

  • Hello,

    If I may chime in - The issue described in the first message has also been mentioned (and resolved) here https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1315743/cc2340r5-sysconfig-error-in-basic_ble-broadcaster-role/5001707#5001707 The same will be fixed in SDK 8.10.

    Best regards,