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

CAF BLE state BT connection limit

Hi,

I am currently developing an application around the CAF BLE state and advertising components.

My setup consists of a nRF9160DK that uses the nRF52840 onboard for BLE. 

The components themselves work mostly OK, but I run into a problem with the following assertion found in ble_state.c:367:

BUILD_ASSERT(!IS_ENABLED(CONFIG_BT_PERIPHERAL) ||
		     (ARRAY_SIZE(active_conn) == 1));

My application does the following two things:

- Advertise so that a device can connect

- Be a central so that I can scan for advertising packets from other BLE sensors. I will never connect, I just need to be able to parse the advertisement data.

So in my prj.conf I have the following lines:

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# General config
CONFIG_NEWLIB_LIBC=y
CONFIG_ASSERT=y
CONFIG_REBOOT=y

# Enable Bluetooth stack and libraries
CONFIG_BT=y
#CONFIG_BT_GATT_CLIENT=y
#CONFIG_BT_GATT_DM=y
#CONFIG_BT_LL_SOFTDEVICE=y

# Bluetooth general settings 
CONFIG_BT_DIS=y # device information service
CONFIG_BT_SMP=y
CONFIG_BT_MAX_CONN=2
CONFIG_BT_MAX_PAIRED=4

# Bluetooth appearance
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="nRF Device"
CONFIG_BT_DEVICE_APPEARANCE=1856

# Enable bonding
# CONFIG_BT_SETTINGS=y
# CONFIG_FLASH=y
# CONFIG_FLASH_PAGE_LAYOUT=y
# CONFIG_FLASH_MAP=y
# CONFIG_NVS=y
# CONFIG_SETTINGS=y
# CONFIG_SETTINGS_NVS=y

# Enable the BMS service
CONFIG_BT_BMS=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=65536
CONFIG_MAIN_STACK_SIZE=65536

# Configuration required by Event Manager
CONFIG_EVENT_MANAGER=y
CONFIG_LINKER_ORPHAN_SECTION_PLACE=y
CONFIG_REBOOT=y

## Config related to CAF (common application framework)
CONFIG_CAF=y
CONFIG_CAF_BLE_STATE=y
# CONFIG_CAF_BLE_BOND_SUPPORTED=y

# CAF BLE ADVERTISING
CONFIG_CAF_BLE_ADV=y
CONFIG_CAF_BLE_ADV_DEF_PATH="ble_adv_def.h"
#CONFIG_CAF_BLE_ADV_PM_EVENTS=y
CONFIG_CAF_BLE_ADV_DIRECT_ADV=n
CONFIG_CAF_BLE_ADV_FAST_ADV=y

# CAF debug
CONFIG_CAF_BLE_ADV_LOG_LEVEL_DBG=y
CONFIG_CAF_BLE_STATE_LOG_LEVEL_DBG=y

## Logger configuration
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_LOG_BACKEND_UART=y
CONFIG_LOG_STRDUP_BUF_COUNT=10
CONFIG_BOOT_BANNER=n

## HC-SR04
CONFIG_SENSOR=y
CONFIG_GPIO=y
CONFIG_HC_SR04=y

# ultrasonic service, CONFIG_BT_L2CAP_TX_BUF_COUNT needed?
CONFIG_BT_L2CAP_TX_BUF_COUNT=5 

# Required for Bluetooth HCI to external nRF52840
CONFIG_NRF_SW_LPUART=y
CONFIG_NRF_SW_LPUART_INT_DRIVEN=y

CONFIG_UART_2_ASYNC=y
CONFIG_UART_2_INTERRUPT_DRIVEN=n
CONFIG_UART_2_NRF_HW_ASYNC=y
CONFIG_UART_2_NRF_HW_ASYNC_TIMER=2

CONFIG_BT_H4=y
CONFIG_BT_WAIT_NOP=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y

CONFIG_UART_INTERRUPT_DRIVEN=y

# ultrasonic service, CONFIG_BT_L2CAP_TX_BUF_COUNT needed?
CONFIG_BT_L2CAP_TX_BUF_COUNT=5 

# Enable scanning
CONFIG_BT_SCAN=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_GATT_CLIENT=y

# Allow for bigger packets to include all TPMS in one packet
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_L2CAP_TX_MTU=253
CONFIG_BT_BUF_CMD_TX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=251

Since I have both CONFIG_BT_PERIPHERAL and CONFIG_BT_CENTRAL, zephyr requies CONFIG_BT_MAX_CONN to be at least 2, I guess because it reserves a connection for the internal central as well? Although from the peripheral point of view I only require one 'connection' to an external central at a time. 

Is there a way around this build assert or am I stuck?

I have uncommented the lines from ble_state.c and now the application 'works' but I doubt this is the right way.

Kind regards,

Stef

Related