CC2340R5-Q1: About Advertise Transmission Evne

Part Number: CC2340R5-Q1
Other Parts Discussed in Thread: BLE-STACK

Hi, TI_Team.

Please let me know the timing of events that occur during advertising packet transmission.

I have confirmed the operation of the software with the additions of "BLEAPPUTIL_ADV_END" and "BLEAPPUTIL_ADV_TERMINATED" to the event handler.

I am toggling a port at the timing of event occurrence.

As shown in the diagram below, it can be seen that "BLEAPPUTIL_ADV_END" event occurs both before and after transmission,

while the "BLEAPPUTIL_ADV_TERMINATED" event occurs after transmission.

@SDK 7.40

Q1.Why does "BLEAPPUTIL_ADV_END" occur before transmission?

  -Does the fact that the API: GapAdv_disable() is executed before transmission have any effect?

Q2.Why does "BLEAPPUTIL_ADV_TERMINATED" occur?

  I have made the following settings, but I would like to know if the cause "Sent when an advertisement set is terminated due to a connection establishment" will trigger

  the occurrence of the "BLEAPPUTIL_ADV_TERMINATED" event?"

    -Device Role:Broadcastaer、Legacy Event Properties Options:Non-connectable and Non-scannable undirected

Please feel free to ask your question, and I'll be happy to provide a response.

Regards.

  • Sorry, TI_Team.

    I made a mistake in my previous question. It should be "BLEAPPUTIL_ADV_END_AFTER_DISABLE" instead of "BLEAPPUTIL_ADV_END."

    The comment in the diagram is also incorrect.

    I apologize for the confusion.

  • Hello, 

    Q1. Why does "BLEAPPUTIL_ADV_END" (BLEAPPUTIL_ADV_END_AFTER_DISABLE) occur before transmission?

    The BLEAPPUTIL_ADV_END_AFTER_DISABLE is sent after the last advertisement ends. See more information in the image below: 

    The GapAdv_disable() API uses this event to disable the advertisements. 

    Additionally, GAP_EVT_ADV_END_AFTER_DISABLE maps to the BLEAPPUTIL_ADV_END_AFTER_DISABLE event as shown Gap section of the BLE users guide in the Gap Adv Event Mask code snippet.

    This is found in the API Translation Tables in the Porting BLE-Stack to BLE5-Stack section of the users guide. 

    Q2.Why does "BLEAPPUTIL_ADV_TERMINATED" (BLEAPPUTIL_ADV_SET_TERMINATED) occur?

    The BLEAPPUTIL_ADV_SET_TERMINATED occurs when the time/number of advertisement events are used up. 

    This can be found in the Scanning and Advertising Basics SLA in the Configuring the advertising event mask for BLEAPPUTIL_ADV_SET_TERMINATED

    Let me know if you have any further questions! 

    Thanks, 

    Isaac

  • Hi, Isaac.

    Thanks for your reply.

    Q1 and Q2 were understood with the above answers.

    Let me ask one more question.
    Q3. Please tell me why the event "BLEAPPUTIL_ADV_END" of CH2 in the figure below does not occur.
    ("Sent after each advertisement (for legacy advertising) or at the end of each respective advertisement set (for extended advertising). I understand from the description that it occurs after the advertisement is sent).

    Regards.

  • Hello, 

    Did you include BLEAPPUTIL_ADV_END within the event mask? 

    If not, you can add the event in the event mask. I have linked an example for populating the event mask here (listing 40). 

    Let me know if this helps! 

    Thanks, 

    Isaac

  • Hello,

    Thanks for reply.

    Could you please provide the content of the documentation and the source code that you are referring to?

    Then I can help you evaluate if there are any missing settings or code.

    Prerequisites: As shown in the red box below, the "bleapputil_api.h" and "bleapputil_init.c" files are linked to files in the SDK and have not been modified.

    All GAP_ADV events are masked in the "bleapputil_init.c" file.

    bStatus_t BLEAppUtil_initAdvSet(uint8 *advHandle,
                                    const BLEAppUtil_AdvInit_t *advInitInfo)
    {
        return bleStk_initAdvSet(BLEAppUtil_advCB, advHandle, GAP_ADV_EVT_MASK_ALL,
                                 advInitInfo->advParam, advInitInfo->advDataLen,
                                 advInitInfo->advData, advInitInfo->scanRespDataLen,
                                 advInitInfo->scanRespData);
    }
    

    The "bleapputil_api.h" file is also unchanged.

    /// GAP ADV event mask
    typedef enum BLEAppUtil_GAPAdvEventMaskFlags_e
    {
        BLEAPPUTIL_ADV_START_AFTER_ENABLE    = GAP_EVT_ADV_START_AFTER_ENABLE,  //!< Gets advertising handle using pBuf. Sent on the first advertisement after a @ref BLEAppUtil_advStart.
        BLEAPPUTIL_ADV_END_AFTER_DISABLE     = GAP_EVT_ADV_END_AFTER_DISABLE,   //!< Gets advertising handle using pBuf. Sent after advertising stops due to a @ref BLEAppUtil_advStop.
        BLEAPPUTIL_ADV_START                 = GAP_EVT_ADV_START,               //!< Gets advertising handle using pBuf. Sent at the beginning of each advertisement (for legacy advertising) or at the beginning of each each advertisement set (for extended advertising).
        BLEAPPUTIL_ADV_END                   = GAP_EVT_ADV_END,                 //!< Gets advertising handle using pBuf. Sent after each advertisement (for legacy advertising) or at the end of each each advertisement set (for extended advertising).
        BLEAPPUTIL_ADV_SET_TERMINATED        = GAP_EVT_ADV_SET_TERMINATED,      //!< Gets @ref GapAdv_setTerm_t using pBuf. pBuf should be cast to @ref GapAdv_setTerm_t. Sent when an advertisement set is terminated due to a connection establishment
        BLEAPPUTIL_SCAN_REQ_RECEIVED         = GAP_EVT_SCAN_REQ_RECEIVED,       //!< Gets @ref GapAdv_scanReqReceived_t using pBuf. pBuf should be cast to @ref GapAdv_scanReqReceived_t. Sent when a scan request is received.
        BLEAPPUTIL_ADV_DATA_TRUNCATED        = GAP_EVT_ADV_DATA_TRUNCATED,      //!< Gets @ref GapAdv_truncData_t using pBuf. pBuf should be cast to @ref GapAdv_truncData_t. Sent when the advertising data is truncated due to the limited advertisement data length for connectable advertisements.
        BLEAPPUTIL_ADV_INSUFFICIENT_MEMORY   = GAP_EVT_INSUFFICIENT_MEMORY      //!< A memory failure has occurred.
    } BLEAppUtil_GAPAdvEventMaskFlags_e;
    

    In the "app_broadcaster.c" file, only four events are enabled and the port is toggled for each event.

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

    void Broadcaster_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
            case BLEAPPUTIL_ADV_START_AFTER_ENABLE:
            {
                GPIO_toggle(CONFIG_GPIO_0);
                break;
            }
    
            case BLEAPPUTIL_ADV_END_AFTER_DISABLE:
            {
                GPIO_toggle(CONFIG_GPIO_0);
                break;
            }
            case BLEAPPUTIL_ADV_END:
            {
    			GPIO_toggle(CONFIG_GPIO_1);
                break;
            }
           case BLEAPPUTIL_ADV_SET_TERMINATED:
            {
                GPIO_toggle(CONFIG_GPIO_2);
                break;
            }
            default:
            {
                break;
            }
        }
    }

    When operated under these conditions, the following diagram is shown.

    Regards.

  • Hello, 

    It looks like you have set up everything correctly. 

    Could you send me your implementation for enabling and disabling advertisements? Currently I am able to see BLEAPPUTIL_ADV_END occurring for each advertisement with your initial setup, but I need to know the enabling and disabling advertisements implementation to see further. 

    Let me know!

    Thanks, 

    Isaac

  • Hello.

    Thank you for checking the settings. First, I'm glad that the settings seem to be correct.

    I will provide the implementation code for advertising transmission below.

    Assumption: After the IC is reset, there will be no advertising transmission.

          Then, it will repeat the process of wakeup and advertising transmission every 100 msec.

    Func : App_StackInitDoneHandler()

                 - Setting Adv_set and Setup Timer for wakeup

        status = Broadcaster_start();
        if(status != SUCCESS)
        {
            // TODO: Call Error Handler
        }
        tsPrepareTimer();											/* Set up a timer for Wakeup every 100 msec */

    Func : Broadcaster_start()

                 -I only removed BLEAppUtil_advStart() from the sample source code 'Basic_BLE'.

                   ※This is done to prevent transmission during initialization.

    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);
        }
    #if	0
        status = BLEAppUtil_advStart(broadcasterAdvHandle_1, &broadcasterStartAdvSet1);
        if(status != SUCCESS)
        {
            // Return status value
            return(status);
        }
    #endif
        // Return status value
        return(status);
    }

    After Wakeup, set the data for advertising transmission in the buffer, and then proceed with the next code.

    bStatus_t Broadcaster_updateAdvData(char *advDat)
    {
        bStatus_t status = SUCCESS;
    
        status = GapAdv_disable(broadcasterAdvHandle_1);
        if((status != SUCCESS) && (status != bleAlreadyInRequestedMode))
        {// Return status value
            return(status);
        }
        status = GapAdv_loadByHandle(broadcasterAdvHandle_1, GAP_ADV_DATA_TYPE_ADV, advDat[0], &advDat[1]);
        if(status != SUCCESS)
        {// Return status value
            return(status);
        }
        status = GapAdv_enable(broadcasterAdvHandle_1, GAP_ADV_ENABLE_OPTIONS_USE_MAX_EVENTS , 1);
        if(status != SUCCESS)
        {// Return status value
            return(status);
        }
        return(status);
    }

    If you need anything else, please let me know. Thank you.

  • Hello, 

    Sorry for the inconvenience, I am still attempting to replicate the issue. I will give a response on Friday. 

    Thank you for your patience. 

    Thanks, 

    Isaac

  • Hello, 

    I apologize for the delay, but I am still attempting to replicate the issue. Please expect a response early next week. 

    Again, thank you for your patience. 

    Regards, 

    Isaac

  • Hello, 

    Can you implement the BLEAPPUTIL_ADV_END event within an unmodified Basic_ble project? When done, can you verify that the event is occurring after each advertisement on your end? 

    Additionally, could you clarify the reason you are using this event? 

    I'm currently still attempting to replicate the issue on my end. I apologize for the inconvenience, and I really appreciate your patience. 

    Thanks, 
    Isaac

  • Hi.

    I made minimal changes to the BLE_Basic project and confirmed its operation.

    These changes

     ・Add GPIO port and implementing toggle processing when an event occurs

     ・As well as registering events during Advertise transmission as a peripheral role

     ※please refer to the code below (The part marked with @@@ is the added code)

    BLEAppUtil_EventHandler_t peripheralAdvHandler =
    {
        .handlerType    = BLEAPPUTIL_GAP_ADV_TYPE,
        .pEventHandler  = Peripheral_AdvEventHandler,
        .eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                          BLEAPPUTIL_ADV_END_AFTER_DISABLE |
                          BLEAPPUTIL_ADV_END    /* @@@ */
    };
    

    void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        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);
                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;
            }
    #if 1  /* @@@ */
            case BLEAPPUTIL_ADV_END:
            {
                GPIO_toggle(CONFIG_GPIO_0);
                break;
            }
    #endif  /* @@@ */
            default:
            {
                break;
            }
        }
    }

    As a result, I was able to confirm that an event occurs after each advertisement (please refer to the diagram below).

    Why was it able to operate correctly?

    I will also answer the question, 'Additionally, could you clarify the reason you are using this event?'

    There is currently no specific action taking place within this event.

    I posted it to confirm the timing of the event occurrence, which did not happen.

    What actions are generally recommended to be taken within this event?

    As we are still considering the specifications, please provide any recommended processing if available.

    Regards.

  • Hello, 

    It looks like the event is working fine the unmodified Basic_ble project. The results you have sent look identical to mine. 

    First, I noticed in the previous plots provided, you have BLEAPPUTIL_ADV_SET_TERMINATED labeled as one of the gpios. Are you sure that this is the correct event label?

     

    In the code, it says GPIO 2 is labeled at BLEAPPUTIL_ADV_SET_TERMINATED, but from the code you sent me, the advertisements are never terminated, and the device never forms a connection, so this event should not happen. I will link the event information here 

    The behavior of the waveform looks extremely similar to the behavior of the BLE_ADV_END event. Below I will include two pictures from what I observed.

     

    As you can see, the BLEAPPUTIL_ADV_END and the labeled BLEAPPUTIL_ADV_SET_TERMINATED look similar in behavior. Can you double check the setup to make sure that these events are accurate? 

    Additionally, can you please provide the project so I can look at the differences to understand the issue better? 

    Let me know! 

    Thanks, 
    Isaac

  • Hi, Isaac.

    Thank you very much for your kind assistance.

    I'm wondering why events are occurring in the project I am currently developing, as stated in the description of "BLEAPPUTIL_ADV_SET_TERMINATED" where it says, "Event occurs upon connection establishment," as you mentioned.

    Furthermore, I find it perplexing that the expected event, "BLEAPPUTIL_ADV_END," is not occurring.

    I believe it would be helpful for you to take a look at the project to better understand the situation.

    However, I'm unsure about the method of sharing it. Could you please advise me on how to do so?

    Regards.

    Note: Please be advised that the company will be on vacation until ~5/5, so please wait for the sharing until then.

  • Hello, 

    Were you able to confirm that GPIO2 in the figure above is BLEAPPUTIL_ADV_SET_TERMINATED and not BLEAPPUTIL_ADV_END? The waveforms look identical, so I just want to confirm that. 

    Additionally, please follow the Exporting to Archive section at the link provided. 

    Thanks, 

    Isaac