NV Read/Write in APPLICATION_INIT()

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

In system init we have a init code like below:

APPLICATION_INIT()

{

    bleapp_set_cfg((UINT8 *)hello_sensor_gatt_database,

                   sizeof(hello_sensor_gatt_database),

                   (void *)&hello_sensor_cfg,

                   (void *)&hello_sensor_puart_cfg,

                   (void *)&hello_sensor_gpio_cfg,

                   hello_sensor_create);

}

Is there any side effect if we want to read/write NV item in APPLICATION_INIT() ?

Pseudo code like below:

APPLICATION_INIT()

{

  UINT8 databyte;

  databyte = bleprofile_ReadNVRAM(NVRAM_ID_HOST_LIST, sizeof(hello_sensor_hostinfo), (UINT8 *)&hello_sensor_hostinfo);

  if (databyte == 0) {

  //Write initial 0 to the NVs and use another data base

...............

  databyte = bleprofile_WriteNVRAM(NVRAM_ID_HOST_LIST, sizeof(hello_sensor_hostinfo), (UINT8 *)&hello_sensor_hostinfo);

  bleapp_set_cfg((UINT8 *)hello_sensor_gatt_database2,

    sizeof(hello_sensor_gatt_database2),

    (void *)&hello_sensor_cfg2,

    (void *)&hello_sensor_puart_cfg,

    (void *)&hello_sensor_gpio_cfg,

    hello_sensor_create);

  }

  else {

  bleapp_set_cfg((UINT8 *)hello_sensor_gatt_database,

    sizeof(hello_sensor_gatt_database),

    (void *)&hello_sensor_cfg,

    (void *)&hello_sensor_puart_cfg,

    (void *)&hello_sensor_gpio_cfg,

    hello_sensor_create);

    }

}

Please kindly give a suggestion, thanks.

0 Likes
1 Solution
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

The following forum post has a piece of code attached which may be capable of what you want to do:

How to change the GATT database after init (bleapp_set_cfg) ?

I have never personally tried or it or know anyone who has, but it remains your best option to attempt a runtime GATT change.

The approach you were previously taken seems impossible unless you have two different physical boot sources and hardware to switch between the two.

Jacob

View solution in original post

0 Likes
6 Replies
BoonT_56
Employee
Employee
500 likes received 250 likes received 100 likes received

I haven't see this before. Can you access the nvram in the subsequent functions below?

0 Likes
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

This likely won't work since the i2c hardware shouldn't yet be initialized. No harm done in giving it a try though.

"Write initial 0 to the NVs and use another data base " Do you wish to change your boot source? That would require a hardware solution.

Jacob

0 Likes
Anonymous
Not applicable

Hi all,

The main idea is want to use different GATT DB during the boot time, if we found there is a flag set in NV items. We will use the GATT DB2, if not, we will use DB1.

For example, originally we provide the standard battery service for client access, but if we set the flag, we will hide the battery service after next time booting.

0 Likes

Is this still an issue?

henryubnt

0 Likes
Anonymous
Not applicable

Hi Boont,

Roughly test the dynamic change GATT method. Seems work, thank you.

0 Likes
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

The following forum post has a piece of code attached which may be capable of what you want to do:

How to change the GATT database after init (bleapp_set_cfg) ?

I have never personally tried or it or know anyone who has, but it remains your best option to attempt a runtime GATT change.

The approach you were previously taken seems impossible unless you have two different physical boot sources and hardware to switch between the two.

Jacob

0 Likes