How to update advScanStruct after initialization?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to update advScanStruct after initialization?

1,741 Views
pradeepv
Contributor I

Hi,
I am using FRDM-KW41Z and MCUXpresso SDK-2.2 ,i want to change my advstruct after initialization or while advertising.
I am using wireless uart demo application from bluetooth application .

i have an advstruct of this type

static const gapAdStructure_t advScanStruct[] = {
{
.length = NumberOfElements(adData0) + 1,
.adType = gAdFlags_c,
.aData = (uint8_t *)adData0
},
{
.length = NumberOfElements(uuid_service_wireless_uart) + 1,
.adType = gAdComplete128bitServiceList_c,
.aData = (uint8_t *)uuid_service_wireless_uart
},
{
.length = 7,
.adType = gAdShortenedLocalName_c,
.aData = (uint8_t*)"NXP_WU"
}
};

i am trying to update this structure in my wireless uart application

void Update_AdvStruct(void)
{
   for(int i = 0;i<gAppAdvertisingData.cNumAdStructures;i++)
   {
      if(gAppAdvertisingData.aAdStructures[i].adType == gAdShortenedLocalName_c)
         {
            FLib_MemCpy(&gAppAdvertisingData.aAdStructures[i].aData,"NEW_WU",7);
         }
     }
}

i changed the advstruct from static const to static struct also and tried.
Always fails in memcpy.
How can i update this name in runtime?
whether i have to change adType for updating ? 

2 Replies

1,331 Views
gerardo_rodriguez
NXP Employee
NXP Employee

Hello v,

The reason that your application is crashing is because you are trying to write to a location in flash, which is read-only. The FLib_MemCpy() function will copy each byte from the source address to the destination address. In your case you are trying to write to the address pointed by aData which is the string "NXP_WU" located in flash.

To be able to write to the address pointed by aData, it needs to be pointing to an allocated memory in RAM. You could statically allocate some memory by declaring a global array as:

uint8_t gAData[6] = {0};

And then point aData to this new array:

gAppAdvertisingData.aAdStructures[i].aData = gAData;

Now you will be able to use FLib_MemCpy() as follows. Please note that the "&" is not needed as aData is a pointer and already holds the destination address.

FLib_MemCpy(gAppAdvertisingData.aAdStructures[i].aData,"NEW_WU",7);

Once gAppAdvertisingData contains the desired data, you need to call Gap_SetAdvertisingData() to set the advertising data:

Gap_SetAdvertisingData(&gAppAdvertisingData, &gAppScanRspData);

You can verify that your advertising data was setup successfully by adding the gAdvertisingDataSetupComplete_c case to the BleApp_GenericCallback().

Let me know if this works for you and if you have any question.

Best regards,

Gerardo

0 Kudos
Reply

1,331 Views
pradeepv
Contributor I

I tried in this way: 
Declared a global array like and pointed it to 

uint8_t gAData[6] = {0};

the advscanstruct as follows

static const gapAdStructure_t advScanStruct[3] = {
{
.length = NumberOfElements(adData0) + 1,
.adType = gAdFlags_c,
.aData = (uint8_t *)adData0
}, 
{
.length = NumberOfElements(uuid_service_wireless_uart) + 1,
.adType = gAdComplete128bitServiceList_c,
.aData = (uint8_t *)uuid_service_wireless_uart
}, 
{
.length = 7,
.adType = gAdShortenedLocalName_c,
.aData = (uint8_t*)&gAData
} 
};

It works.
Before BLE initialization , i set the gAData everytime.