This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using maximum values for Central and Pehripheral link counts.

Question preamble

I am writing a bluetooth application where two nRF5 devices will be in a master / slave configuration. However, I want to be able to flick a physical button, before powering on the device, that controls wether it starts as a master or a slave.

When it is acting in Slave mode it will just be a standard bluetooth peripheral:

#define CENTRAL_LINK_COUNT               0                                          /**< Number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT            1                                          /**< Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/

However, when it is operating in Master mode it will need a central link to connect to the slave and a peripheral link to treat the master / slave pair as a single device:

#define CENTRAL_LINK_COUNT               1                                          /**< Number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT            1                                          /**< Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/

As the comment next to these messages suggests, when you change these values then you should change the RAM Memory section in the .ld file too:

MEMORY
{
  FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000
  RAM (rwx) :  ORIGIN = 0x200025e0, LENGTH = 0x5a20
}

Obviously, if I want to be able to turn the device off, flick a switch, turn it back on again and have it have switched modes then I need to write one program that I can place on both the master and slave nRF5 chips.

I am trying to work out how to make that happen.

The easiest way to make this work, in my mind, is to declare the maximum CENTRAL and PERIPHERAL links that I might need but just don't activate the links if they are not needed. That would allow for only one .ld configuration and a single program.

For that reason, I was thinking that I would use this configuration on the slave and just not use the central capabilities:

#define CENTRAL_LINK_COUNT               1                                          /**< Number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT            1                                          /**< Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/

My question

Now my question is simple, is there a downside to declaring that a Central link is required in the softdevice_enable_get_default_config method but not actually using it? What can go wrong by doing this?

I can see in the above mentioned method that the central count not being zero does have a flow-on effect:

if (p_ble_enable_params->gap_enable_params.central_conn_count != 0)
{
    p_ble_enable_params->gap_enable_params.central_sec_count  = SOFTDEVICE_CENTRAL_SEC_COUNT;
}

But I'm not sure what that changes. If anything.

Also, thinking about it now, if I switch the device configuration then I should clear the bonding data when the device restarts. That way it can be treated as a completely new device. Does that sound right to you?

Thanks in advance for your time!

P.S. I'm using the nRF51822 with SDK 12.3.0.

Related