This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE peripheral that supports 2 simultaneous connections with nRF Connect SDK 1.8

When using nRF Connect SDK v1.6.1, a BLE peripheral that supports 2 simultaneous connections could be created by including these lines in prj.conf. These lines set the Link Layer choice to be the Nordic Semiconductor Softdevice that supports multiple simultaneous connections, and configure it to support 2 connections. 

# Support connection of 2 central devices to the BLE peripheral
CONFIG_BT_LL_SOFTDEVICE_DEFAULT=y
CONFIG_BT_MAX_CONN=2
CONFIG_BT_MAX_PAIRED=2

Then, after the first BLE central device had connected, connectable advertising was re-enabled by including this code snippet in the connected callback:

// enable CONNECTABLE advertising when first connection has been established
int adv_err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
printk("Start advertising while connected (adv_err %d)\n", adv_err);

When I build my application using nRF Connect SDK v1.8, this process no longer works. The line CONFIG_BT_LL_SOFTDEVICE_DEFAULT=y results in a build error. I consulted the documentation for SDK v1.8, which states that BT_LL_SOFTDEVICE is now the default Link Layer option, so I figured I could just delete this line and everything would work as before.

However, that is not the case. After removing the line CONFIG_BT_LL_SOFTDEVICE_DEFAULT=y from prj.conf, the call to bt_le_adv_start() when one central device is already connected returns error code -111, which is this definition:

#define ECONNREFUSED 111 /**< Connection refused */

When I step into the SDK code with a debugger, I find that the root cause is failure of the call to bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_ADV_ENABLE, buf, NULL). This HCI command fails and returns status code BT_HCI_ERR_CONN_LIMIT_EXCEEDED. In other words, the Link Layer only supports a single BLE connection.

What is the correct way to configure support for 2 simultaneous BLE connections to a Peripheral, using SDK 1.8?  I do not want to switch to using the Zephyr software BLE Link Layer ULL LLL split implementation (BT_LL_SW_SPLIT) because that choice is marked as "EXPERIMENTAL" - which makes it unsuitable for production use.

  • Just one question before I start investigating, are you using nRF53 or nRF52?

  • I am using nRF5340.  For prototyping I am using the nRF5340-DK development board.

    I have attached a version of the bluetooth sample application peripheral_lbs that I have modified to support 2 simultaneous connections, and which fails in the way I described in my ticket. To use it, just unzip into the SDK's nrf/samples/bluetooth directory where the modified application will be in a folder "peripheral_lbs_2conn".peripheral_lbs_2conn.zip

  • The nRF5340 has two cores, so you need to enable multiple connections in the network core as well.

    Try setting CONFIG_SDC_SLAVE_COUNT=2 in <ncs location>\zephyr\samples\bluetooth\hci_rpmsg\prj.conf (or set it from the application using child_image/hci_rpmsg.conf like done in the Bluetooth throughput sample). The hci_rpmsg sample will automatically be built and programmed to the network core when using the nRF340.

    By the way, I don't think you need to start advertising again yourself, it should start automatically if more connections are enabled.

    Best regards,

    Simon

  • Wait a second, it seems like CONFIG_SDC_SLAVE_COUNT=2 should be added automatically to hci_rpmsg when using the SoftDevice, see https://github.com/nrfconnect/sdk-nrf/blob/v1.6.1/subsys/bluetooth/controller/bt_ll_softdevice_hci_rpmsg.conf#L4.

    It tested this by setting CONFIG_BT_LL_SOFTDEVICE_DEFAULT=y  in <Bluetooth sample>/prj.conf and it worked fine. I was able to stay connected to 2 devices simultaneously.

    I'm not sure why you got an error when enabling CONFIG_BT_LL_SOFTDEVICE_DEFAULT, but you could just test the sample I used:

    peripheral_hr_two_conn.zip

    Best regards,

    Simon

  • Hi Simon,

    Thanks for your quick reply. I have tried to build the sample application "peripheral_hr_two_conn.zip" that you provided. However, the same build error occurs as when I build my own application using SDK1.8:

    prj.conf:12: warning: attempt to assign the value 'y' to the undefined symbol BT_LL_SOFTDEVICE_DEFAULT

    I note that BT_LL_SOFTDEVICE_DEFAULT is not described in in the online documentation for SDK1.8:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.8.0/kconfig/search.html?q=CONFIG_BT_LL_SOFTDEVICE_DEFAULT&check_keywords=yes&area=default

    Whereas it is described in the SDK v1.6.1 documentation:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.6.1/kconfig/CONFIG_BT_LL_SOFTDEVICE_DEFAULT.html?highlight=config_bt_ll_softdevice_default

    Therefore, I believed that support for the symbol  BT_LL_SOFTDEVICE_DEFAULT has been deprecated, and it can no longer be used. Strangely, you seem to be able to build "peripheral_hr_two_conn.zip" even though its prj.conf file contains the line CONFIG_BT_LL_SOFTDEVICE_DEFAULT=y, but I cannot.

    I have attached my full West build log in case that gives any clue. I am building on Ubuntu Linux v18.04 LTS. That results in a CMake warning about an old version of dtc. I do not think that would cause a build fault, but I am a relative newcomer to Zephyr OS, so may be wrong.

    tony@vbox1804:~/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn$ source ../../../../zephyr/zephyr-env.sh
    tony@vbox1804:~/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn$ west build -p -b nrf5340dk_nrf5340_cpuapp
    -- west build: making build dir /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/build pristine
    -- west build: generating a build system
    Including boilerplate (Zephyr base): /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/cmake/app/boilerplate.cmake
    -- Application: /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn
    -- Zephyr version: 2.7.0 (/home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr), build: v2.7.0-ncs1
    -- Found Python3: /usr/bin/python3.6 (found suitable exact version "3.6.9") found components: Interpreter 
    -- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Cache files will be written to: /home/tony/.cache/zephyr
    CMake Warning at /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/cmake/host-tools.cmake:31 (message):
      Could NOT find dtc: Found unsuitable version "1.4.5", but required is at
      least "1.4.6" (found /usr/bin/dtc).  Optional devicetree error checking
      with dtc will not be performed.
    Call Stack (most recent call first):
      /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/cmake/app/boilerplate.cmake:523 (include)
      /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Found toolchain: gnuarmemb (/home/tony/build-tools/gcc-arm-none-eabi-9-2019-q4-major)
    -- Found BOARD.dts: /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Generated zephyr.dts: /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/build/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/build/zephyr/include/generated/device_extern.h
    -- Including generated dts.cmake file: /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/build/zephyr/dts.cmake
    Parsing /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/Kconfig
    Loaded configuration '/home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/prj.conf'
    
    /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/prj.conf:12: warning: attempt to assign the value 'y' to the undefined symbol BT_LL_SOFTDEVICE_DEFAULT
    
    error: Aborting due to Kconfig warnings
    
    CMake Error at /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/cmake/kconfig.cmake:270 (message):
      command failed with return code: 1
    Call Stack (most recent call first):
      /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/cmake/app/boilerplate.cmake:546 (include)
      /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      /home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:5 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /home/tony/.local/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn/build -S/home/tony/projects/lec-nordic-nrf5340/vendor/thirdparty_nordic_sdk/nrf/samples/bluetooth/peripheral_hr_two_conn -GNinja -DBOARD=nrf5340dk_nrf5340_cpuapp
    
    

    I will investigate your other suggestions. Explicitly setting setting CONFIG_SDC_SLAVE_COUNT=2 in the configuration files for the network core application "hci_rpmsg" sounds like a sensible thing to do.

Related