I'm developing software for the nRF5340 based on the NCS 3.2.4 "hello world" example.
Adding bt_enable() returns error code -11.
Please tell me how to implement bt_enable() so that it completes correctly.
The source code is as follows:
prj.conf
CONFIG_LOG=y CONFIG_USE_SEGGER_RTT=y CONFIG_BT=y CONFIG_BT_DEVICE_NAME="Thingy91X" CONFIG_BT_CENTRAL=y CONFIG_BT_SCAN=y CONFIG_BT_SCAN_FILTER_ENABLE=y CONFIG_BT_SCAN_UUID_CNT=1
main.c
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <bluetooth/scan.h>
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define TARGET_DEVICE_NAME "nRF54L15"
#define TARGET_DEVICE_NAME_LEN (sizeof(TARGET_DEVICE_NAME) - 1)
static void scan_filter_match(struct bt_scan_device_info *device_info,
struct bt_scan_filter_match *filter_match, bool connectable)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
printk("Filters matched. Address: %s connectable: %d\n", addr, connectable);
}
static void scan_filter_no_match(struct bt_scan_device_info *device_info, bool connectable)
{
#if 0
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
#endif
}
static void scan_connecting_error(struct bt_scan_device_info *device_info)
{
printk("Connecting failed\n");
}
BT_SCAN_CB_INIT(scan_cb, scan_filter_match, scan_filter_no_match, scan_connecting_error, NULL);
static int scan_init(void)
{
int err;
struct bt_le_scan_param scan_param = {
.type = BT_LE_SCAN_TYPE_PASSIVE,
.options = BT_LE_SCAN_OPT_FILTER_DUPLICATE,
.interval = 0x0010,
.window = 0x0010,
};
struct bt_scan_init_param scan_init_param = {
.connect_if_match = true, .scan_param = &scan_param, .conn_param = NULL
};
bt_scan_init(&scan_init);
bt_scan_cb_register(&scan_cb);
err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, TARGET_DEVICE_NAME);
if (err) {
printk("bt_scan_filter_add() = %d\n", err);
return err;
}
err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
if (err) {
printk("bt_scan_filter_enable() = %d\n", err);
return err;
}
return 0;
}
static int scan_start(void)
{
int err;
err = bt_scan_start(BT_SCAN_TYPE_SCAN_PASSIVE);
if (err) {
printk("bt_scan_start() = %d\n", err);
return err;
}
return 0;
}
int main(void)
{
int err;
#if 1
err = bt_enable(NULL);
if (err) {
printk("bt_enable() = %d\n", err);
return 0;
}
err = scan_init();
if (err) {
printk("scan_init() = %d\n", err);
return 0;
}
err = scan_start();
if (err) {
printk("scan_start() = %d\n", err);
return 0;
}
#endif
for(;;) {
static uint32_t c = 0;
printk("Hello World! (%d) %s\n", c, CONFIG_BOARD_TARGET);
c++;
k_msleep(1000);
}
return 0;
}The following message is displayed in J-Link RTT Viewer V8.92:
00> *** Booting nRF Connect SDK v3.2.4-4c3fc0d44534 *** 00> *** Using Zephyr OS v4.2.99-9673eec75908 *** 00> [00:00:02.251,190] <err> bt_hci_driver: Endpoint binding failed with -11 00> [00:00:02.251,190] <err> bt_hci_core: HCI driver open failed (-11) 00> bt_enable() = -11
Disabling Bluetooth processing (changing `#if` on line 88 to 0) allows it to work correctly.
00> *** Booting nRF Connect SDK v3.2.4-4c3fc0d44534 *** 00> *** Using Zephyr OS v4.2.99-9673eec75908 *** 00> Hello World! (0) nrf5340dk/nrf5340/cpuapp 00> Hello World! (1) nrf5340dk/nrf5340/cpuapp 00> Hello World! (2) nrf5340dk/nrf5340/cpuapp 00> Hello World! (3) nrf5340dk/nrf5340/cpuapp
The procedure for writing is as follows:
C:\ncs\applications\hello_world_v3-2-4_rev2\build>nrfutil device recover --core Network v Recovered 960033963 nrfutil device recover v Recovered 960033963 nrfutil device erase --core Network v Erased 960033963 nrfutil device erase v Erased 960033963 nrfutil device program --firmware merged.hex [00:00:01] ###### 100% [3/3 960033963] Programmed nrfutil device reset v Reset was applied to 960033963
Is build/merged.hex an image where Application and Network are combined?

