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: How to update adv data without stop / restart existing adv ?

Part Number: CC2340R5

Tool/software:

Hi All,

I know we can use GapAdv_prepareLoadByBuffer , GapAdv_loadByBuffer to update advertising data however it will cause a restart of adv.

If I don't want to change ADV timing, can I change payload buffer directly without calling GapAdv_prepareLoadByBuffer, GapAdv_loadByBuffer ?

(I expect it reflect the change in next adv interval, it worked on CC2640R2 SDK however it seems not working on CC2340R5 SDK)

  • Hi !

    While we recommend to use the Gap functions and therefore cause a restart of advertisement, if not changing advertisement timing is crucial, you could follow the Directly Manipulating a Buffer While Advertising is Enabled section of the CC23XX SDK BLE-stack user guide to be able to change the advertisement data buffer while advertising is still running.
    Be careful that this comes at the risk of possibly resulting in a corrupted advertising packet.

    Kind regards,
    Maxence

  •  Hi,

    I tested this. It worked on CC2640R2 SDK but not working on CC2340R5 SDK.

    (tested on simplelink_lowpower_f3_sdk_8_40_02_01)

    I'm wondering if there is difference in GAP iCall implementation.

  • When you say that it doesn't work, do you mean that the advertisement data doesn't change, or that the advertising restarts ? And how are you checking if the advertising has restarted or not ?

  • I mangle the buffer directly, in CC2640R2 SDK the advertising payload changes however in  simplelink_lowpower_f3_sdk_8_40_02_01 it doesn't.

    I set ADV interval 5 sec and I change payload every 2.5 sec.

    If I use GapAdv_prepareLoadByBuffer , GapAdv_loadByBuffer to update payload I'll see the advertising every 2.5 sec instead of 5 sec since it restart every 2.5 sec.

    What I want is updating the adv data every 2.5 sec and the ADV interval still keep 5 sec.

    I want to avoid frequently call GapAdv_prepareLoadByBuffer , GapAdv_loadByBuffer, it will cost additional power consumption with around 5ms duration peak.

  • Hi !

    I tried modifying the buffer on a new project, and I did not manage to make it work either. I'll have to ask if it's a bug or an intended feature, as modifying the buffer directly is a little bit sketchy and may cause unintended effects.

    In the meanwhile, maybe a solution to your problem could be to update your buffer every 2.5 seconds, and call GapAdv_prepareLoadByBuffer and GapAdv_loadByBuffer with your buffer when the advertisement ends (so every 5 seconds).

    To give a concrete example, in the basic_ble example of the F3 SDK, you can use the BLEAPPUTIL_ADV_END case of the Peripheral_AdvEventHandler function to call GapAdv_prepareLoadByBuffer and GapAdv_loadByBuffer. Don't forget to put BLEAPPUTIL_ADV_END in the event mask of your event handler.

    Here's a sample code :

    void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
            // Advertisement just ended so it should be safe to update buffer here
            // without corrupting an advertisement.
            case BLEAPPUTIL_ADV_END:
            {
                GapAdv_prepareLoadByHandle(peripheralAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);
    
                // Sample buffer modification
                advData2[9] = 0xEF;
                advData2[10] = 0xBE;
                
                GapAdv_loadByHandle(peripheralAdvHandle_1,
                                                GAP_ADV_DATA_TYPE_ADV,
                                                ADV_DATA2_LEN,
                                                advData2);
            }
            default:
            {
                break;
            }
        }
    }


    This is not a perfect solution as the advertising interval will not be exactly 5 seconds, because of the processing time of  GapAdv_prepareLoadByBuffer and GapAdv_loadByBuffer, but it will get you most of the way there.

    Kind regards,
    Maxence

  • I got your point and that's fallback solution however the drawback is somehow critical for power consumption consideration.

    5s period calling GapAdv_prepareLoadByBuffer / GapAdv_loadByBuffer will cause a 5ms peak power consumption for every iCAll so I want to avoid that.

    Is there some feedback from Ti about direct buffer mangling not working issue ?

  • After asking to the people in R&D, we came to the conclusion that modifying the buffer directly without stopping the advertisement is not supported anymore and is not the right way to do it. The example from the BLE user guide I sent is outdated and we need to remove it. Sorry for the inconvenience !

  • Hi Maxence,

    Thanks for your explanation and looking for doc update.

    BTW if you look my use case some asynchronous way to upload advertising data still valuable for power consumption consideration.