Skip to content

Commit

Permalink
applications: Added overlays allowing to support more BT conns.
Browse files Browse the repository at this point in the history
The Matter bridge application is able to support only 10 BT
connections on the network core.

Added overlays allowing to increase the number of BT connections
by decreasing the size of stacks and BT buffers. Additionally
updated the readme to describe how to use it.

Signed-off-by: Kamil Kasperczyk <[email protected]>
  • Loading branch information
kkasperczyk-no authored and rlubos committed Oct 5, 2023
1 parent ad9c84a commit 1226be9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
36 changes: 36 additions & 0 deletions applications/matter_bridge/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ The application supports bridging the following Matter device types:
* Temperature Sensor
* Humidity Sensor

All the listed Matter device types are enabled by default.
To disable one of them, set any of the following configuration options:

* :kconfig:option:`CONFIG_BRIDGE_ONOFF_LIGHT_BRIDGED_DEVICE` to ``n`` to disable On/Off Light.
* :kconfig:option:`CONFIG_BRIDGE_TEMPERATURE_SENSOR_BRIDGED_DEVICE` to ``n`` to disable Temperature Sensor.
* :kconfig:option:`CONFIG_BRIDGE_HUMIDITY_SENSOR_BRIDGED_DEVICE` to ``n`` to disable Humidity Sensor.

The application supports over-the-air (OTA) device firmware upgrade (DFU) using either of the two following protocols:

* Matter OTA update protocol.
Expand Down Expand Up @@ -91,6 +98,7 @@ The application supports two bridged device configurations that are mutually exc
The application supports the following Bluetooth LE services:

* Nordic Semiconductor's :ref:`LED Button Service <lbs_readme>` - represented by the Matter On/Off Light device type.
* Zephyr's :ref:`Environmental Sensing Service <peripheral_esp>` - represented by the Matter Temperature Sensor and Humidity Sensor device types.

Depending on the bridged device you want to support in your application, :ref:`enable it using the appropriate Kconfig option <matter_bridge_app_bridged_support_configs>`.
The Matter bridge supports adding and removing bridged devices dynamically at application runtime using `Matter CLI commands`_ from a dedicated Matter bridge shell module.
Expand Down Expand Up @@ -270,6 +278,34 @@ You can enable the :ref:`matter_bridge_app_bridged_support` by using the followi
* :kconfig:option:`CONFIG_BRIDGED_DEVICE_SIMULATED` - For the simulated bridged device.
* :kconfig:option:`CONFIG_BRIDGED_DEVICE_BT` - For the Bluetooth LE bridged device.

Additionally, you can decide how many bridged devices the bridge application will support.
The decision will make an impact on the flash and RAM memory usage, and is verified in the compilation stage.
The application uses dynamic memory allocation and stores bridged device objects on the heap, so it may be necessary to increase the heap size using the :kconfig:option:`CONFIG_CHIP_MALLOC_SYS_HEAP_SIZE` Kconfig option.
Use the following configuration options to customize the number of supported bridged devices:

* :kconfig:option:`CONFIG_BRIDGE_MAX_BRIDGED_DEVICES_NUMBER` - For changing the maximum number of non-Matter bridged devices supported by the bridge application
* :kconfig:option:`CONFIG_BRIDGE_MAX_DYNAMIC_ENDPOINTS_NUMBER` - For changing the maximum number of Matter endpoints used for bridging devices by the bridge application.
This option does not have to be equal to :kconfig:option:`CONFIG_BRIDGE_MAX_BRIDGED_DEVICES_NUMBER`, as it is possible to use non-Matter devices that are represented using more than one Matter endpoint.

Configuring the number of Bluetooth LE bridged devices
------------------------------------------------------

You have to consider several factors to decide how many Bluetooth LE bridged devices to support.
Every Bluetooth LE bridged device uses a separate Bluetooth LE connection, so you need to consider the number of supported Bluetooth LE connections (selected using the :kconfig:option:`CONFIG_BT_MAX_CONN` Kconfig option) when you configure the number of devices.
Since the Matter stack uses one Bluetooth LE connection for commissioning, the maximum number of connections you can use for bridged devices is one less than is configured using the :kconfig:option:`CONFIG_BT_MAX_CONN` Kconfig option.

Increasing the number of Bluetooth LE connections affects the RAM usage on both the application and network cores.
The current maximum number of Bluetooth LE connections that can be selected using the default configuration is ``10``.
You can increase the number of Bluetooth LE connections if you decrease the size of the Bluetooth LE TX/RX buffers used by the Bluetooth controller, but this will decrease the communication throughput.
Build the target using the following command in the project directory to enable a configuration that increases the number of Bluetooth LE connections to ``20`` by decreasing the sizes of Bluetooth LE TX/RX buffers:

.. parsed-literal::
:class: highlight
west build -b nrf7002dk_nrf5340_cpuapp -- -DCONFIG_BRIDGED_DEVICE_BT=y -DOVERLAY_CONFIG="overlay-bt_max_connections_app.conf" -Dhci_rpmsg_OVERLAY_CONFIG="*absoule_path*/overlay-bt_max_connections_net.conf"
Replace *absolute_path* with the absolute path to the Matter bridge application on your local disk.

Building and running
********************

Expand Down
22 changes: 22 additions & 0 deletions applications/matter_bridge/overlay-bt_max_connections_app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Set 20 BLE connections, as it is an upper limit supported by the Soft Device Controller.
CONFIG_BT_MAX_CONN=20

# Set buffer sizes in a consistent way with the ones used by the network core.
CONFIG_BT_BUF_ACL_RX_SIZE=96
CONFIG_BT_BUF_ACL_TX_SIZE=96
CONFIG_BT_CTLR_DATA_LENGTH_MAX=96

# Set MTU size to fit in the single buffer and avoid fragmentation (BUF_SIZE = MTU_SIZE + 4 B of L2CAP header).
CONFIG_BT_L2CAP_TX_MTU=92

# Set max number of bridged BLE devices, which is CONFIG_BT_MAX_CONN-1, as 1 connection is reserved for Matter.
CONFIG_BRIDGE_MAX_BRIDGED_DEVICES_NUMBER=19

# Assume that every bridged device uses only 1 endpoint, however it can be increased if specific use case requires it.
CONFIG_BRIDGE_MAX_DYNAMIC_ENDPOINTS_NUMBER=19
15 changes: 15 additions & 0 deletions applications/matter_bridge/overlay-bt_max_connections_net.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Set 20 BLE connections, as it is an upper limit supported by the Soft Device Controller
CONFIG_BT_MAX_CONN=20

# Decrease stack and buffer sizes to free some RAM and support 20 BLE connections
CONFIG_MAIN_STACK_SIZE=512
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
CONFIG_BT_BUF_ACL_RX_SIZE=96
CONFIG_BT_BUF_ACL_TX_SIZE=96
CONFIG_BT_CTLR_DATA_LENGTH_MAX=96

0 comments on commit 1226be9

Please sign in to comment.