BLE doesn't work.

Bluetooth connection cache processing - Nordic Q&A - Nordic DevZone - Nordic DevZone

Continuing from last time. After some optimization, the program was able to work. However, after verification, the program could only operate normally for a few hours and then failed to run properly. The phenomenon was manifested as: the USB-related connection was directly disconnected and could not be restored by itself.

After verification, I found that the main reason is that this issue is triggered when multiple connections are in progress simultaneously.
Here is my code.

An error indicates insufficient memory, but even though I set a larger memory, this error still occurs.

I modified some code to disable the previous BLE restart function, and at the same time, I turned off the CODED and 2M PHY switching functions.

Here is my log:

[15:41:36.081]收←◆*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
[00:00:00.002,593] <inf> littlefs: LittleFS version 2.9, disk version 2.1
[00:00:00.002,868] <inf> littlefs: FS at w25q64jvs@0:0x0 is 256 0x1000-byte blocks with 512 cycle
[00:00:00.002,868] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[USB]: status: 5.

[15:41:36.293]收←◆[USB]: status: 1.
[USB]: status: 6.
[USB]: status: 1.
[00:00:00.209,228] <inf> fs_nvs: 2 Sectors of 4096 bytes
[00:00:00.209,228] <inf> fs_nvs: alloc wra: 0, fd0
[00:00:00.209,259] <inf> fs_nvs: data wra: 0, 1c
[00:00:00.209,381] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 
                                            2d 79 a1 c8 6a 40 b7 3c  f6 74 f9 0b 22 d3 c4 80 |-y..j@.< .t.."...
                                            74 72 82 ba               
[15:41:36.355]收←◆                       |tr..             
[00:00:00.212,188] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.212,219] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:00.212,249] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 45.41337 Build 3074452168
[00:00:00.212,707] <inf> bt_hci_core: No ID address. App must call settings_load()
[00:00:00.213,287] <inf> bt_hci_core: Identity: EF:E6:40:48:0B:0F (random)
[00:00:00.213,317] <inf> bt_hci_core: HCI: version 6.0 (0x0e) revision 0x106b, manufacturer 0x0059
[00:00:00.213,348] <inf> bt_hci_core: LMP: version 6.0 (0x0e) subver 0x106b
start scan.

[15:41:37.453]收←◆[USB]: status: 5.
[USB]: status: 1.
[USB]: status: 6.
[USB]: status: 1.
[00:00:00.545,562] <inf> usb_cdc_acm: Device configured

[15:41:40.293]收←◆scan stop.
start scan.

[15:41:43.297]收←◆scan stop.
start scan.

[15:41:46.303]收←◆scan stop.
start scan.
scan stop.
connect [6C], rssi: -63 phy: 1.

[15:41:47.555]收←◆connect [6C], ret: 1.
start scan.
scan stop.
connect [8F], rssi: -71 phy: 1.
[00:00:11.121,246] <wrn> bt_hci_core: opcode 0x2043 status 0x0d 
[bt_conn_le_create]: ERROR -12.
connect [95], ret: 0.
start scan.
scan stop.
connect [46], rssi: -54 phy: 1.
[00:00:11.477,233] <wrn> bt_hci_core: opcode 0x2043 status 0x0d 
[bt_conn_le_create]: ERROR -12.
connect [95], ret: 0.
start scan.

[15:41:48.257]收←◆scan stop.
connect [9C], rssi: -59 phy: 1.
[00:00:11.817,626] <wrn> bt_hci_core: opcode 0x2043 status 0x0d 
[bt_conn_le_create]: ERROR -12.
connect [95], ret: 0.
start scan.
scan stop.
connect [3A], rssi: -67 phy: 1.
[00:00:12.179,290] <wrn> bt_hci_core: opcode 0x2043 status 0x0d 
[bt_conn_le_create]: ERROR -12.
connect [95], ret: 0.
start scan.

8203.Downloads.zip

Parents
  • I have found out the reason why the system stopped working. It is because after adding the failed connection device to the timeout, due to the large number of unconnected devices, it may not be possible to add additional devices, so a second attempt to connect will be made. At this time, there will be a task_wdt error.

    if(dev_count_connect == CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT || dev_count_timeout == CONFIG_SERVER_CLIENT_WAITING_COUNT)
        {
            printk("[FULL DEVICES].\n");
            return;
        }

    Therefore, the crux of the matter still lies in:
    1. Why can't multiple connections be made simultaneously? I tried to shut down my main communication process, which doesn't perform any device communication lifecycle management, data communication, or upper computer communication, but still couldn't connect at the same time.
    2. Why does a second attempt to reconnect cause the system to crash?

  • As I explained in this post, the error code -12 returned by bt_conn_le_create typically means "Not enough memory" (-ENOMEM). This indicates that the system does not have enough resources (such as heap memory or connection objects) to establish a new connection. 

    I see bt_conn_unref() is used the conn_callbacks, but it didn't get registered. Please study the Central Multilink sample and review your code. 

  • 1.

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=3072
    CONFIG_HEAP_MEM_POOL_SIZE=8192
    CONFIG_MAIN_STACK_SIZE=8192
    CONFIG_BT_MAX_CONN=5
    CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT=4

    I think my memory is sufficient. And all my threads create memory separately.

    K_THREAD_DEFINE(SMF_THREAD_ID, SMF_THREAD_STACK_SIZE, SMF_THREAD, NULL, NULL, NULL, SMF_THREAD_PRIORITY, 0, 0);
    K_THREAD_DEFINE(MAIN_SMF_THREAD_ID, SMF_THREAD_STACK_SIZE, MAIN_SMF_THREAD, NULL, NULL, NULL, SMF_THREAD_PRIORITY + 2, 0, 0);
    k_work_queue_start(&o->network_workq, o->net_workq_stack, K_THREAD_STACK_SIZEOF(o->net_workq_stack), WORKQUEUE_PRIORITY + 1, NULL);
    k_work_queue_start(&o->uart_workq, o->uart_workq_stack, K_THREAD_STACK_SIZEOF(o->uart_workq_stack), WORKQUEUE_PRIORITY + 3, NULL);
    k_thread_create(&o->uart_thread, o->uart_stack_area, K_THREAD_STACK_SIZEOF(o->uart_stack_area), MAIN_UART_THREAD, o, NULL, NULL, SMF_THREAD_PRIORITY + 4, 0, K_NO_WAIT);
    I have no idea where the memory will be occupied.

    2.

    BT_CONN_CB_DEFINE(conn_callbacks) = {
        .connected = connected,
        .disconnected = disconnected,
        .le_param_updated = le_param_updated,
        .le_phy_updated = le_phy_updated,
    };
    

    I think this sentence is related to bt_conn_cb_register(&conn_callbacks); It has the same function.

Reply
  • 1.

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=3072
    CONFIG_HEAP_MEM_POOL_SIZE=8192
    CONFIG_MAIN_STACK_SIZE=8192
    CONFIG_BT_MAX_CONN=5
    CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT=4

    I think my memory is sufficient. And all my threads create memory separately.

    K_THREAD_DEFINE(SMF_THREAD_ID, SMF_THREAD_STACK_SIZE, SMF_THREAD, NULL, NULL, NULL, SMF_THREAD_PRIORITY, 0, 0);
    K_THREAD_DEFINE(MAIN_SMF_THREAD_ID, SMF_THREAD_STACK_SIZE, MAIN_SMF_THREAD, NULL, NULL, NULL, SMF_THREAD_PRIORITY + 2, 0, 0);
    k_work_queue_start(&o->network_workq, o->net_workq_stack, K_THREAD_STACK_SIZEOF(o->net_workq_stack), WORKQUEUE_PRIORITY + 1, NULL);
    k_work_queue_start(&o->uart_workq, o->uart_workq_stack, K_THREAD_STACK_SIZEOF(o->uart_workq_stack), WORKQUEUE_PRIORITY + 3, NULL);
    k_thread_create(&o->uart_thread, o->uart_stack_area, K_THREAD_STACK_SIZEOF(o->uart_stack_area), MAIN_UART_THREAD, o, NULL, NULL, SMF_THREAD_PRIORITY + 4, 0, K_NO_WAIT);
    I have no idea where the memory will be occupied.

    2.

    BT_CONN_CB_DEFINE(conn_callbacks) = {
        .connected = connected,
        .disconnected = disconnected,
        .le_param_updated = le_param_updated,
        .le_phy_updated = le_phy_updated,
    };
    

    I think this sentence is related to bt_conn_cb_register(&conn_callbacks); It has the same function.

Children
  • The following are the BLE parameters of my peripheral and central. Will they have any impact on the connection?

    peripheral:

    struct bt_le_adv_param param =
            BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
                                     BT_LE_ADV_OPT_EXT_ADV |
                                     BT_LE_ADV_OPT_CODED,
                                 BT_GAP_ADV_FAST_INT_MIN_1,
                                 BT_GAP_ADV_FAST_INT_MAX_1,
                                 NULL);
    bt_le_ext_adv_start(_LIB_NAME_(inst).adv, BT_LE_EXT_ADV_START_DEFAULT);            

    central:

    struct bt_conn_le_create_param *conn_create_params = BT_CONN_LE_CREATE_PARAM(
            BT_CONN_LE_OPT_NONE,
            BT_GAP_SCAN_FAST_INTERVAL,
            BT_GAP_SCAN_FAST_WINDOW);
    bt_conn_le_create(&o->event.device.device_client_info.addr, conn_create_params, BT_LE_CONN_PARAM_DEFAULT, &dev->conn);

  • bt_hci_core: Connection creation timeout triggered.

    Could this error be related to the above parameters?

  • I have changed the relevant parameters:

    struct bt_le_adv_param param =
            BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
                                     BT_LE_ADV_OPT_EXT_ADV |
                                     BT_LE_ADV_OPT_CODED,
                                 BT_GAP_ADV_FAST_INT_MIN_2,
                                 BT_GAP_ADV_FAST_INT_MAX_2,
                                 NULL);

    struct bt_conn_le_create_param *conn_create_params = BT_CONN_LE_CREATE_PARAM(
            BT_CONN_LE_OPT_NONE,
            BT_GAP_SCAN_FAST_INTERVAL,
            BT_GAP_SCAN_FAST_INTERVAL);
    
    struct bt_le_conn_param *conn_params = BT_LE_CONN_PARAM(
            BT_GAP_INIT_CONN_INT_MIN,
            BT_GAP_INIT_CONN_INT_MAX,
            0,
            400);
    if (o->event.device.device_client_info.phy == PHY_CODED)
    {
        conn_create_params->options = BT_CONN_LE_OPT_CODED | BT_CONN_LE_OPT_NO_1M;
    }
    else
    {
        // Dont change param.
    }
    bt_conn_le_create(&o->event.device.device_client_info.addr, conn_create_params, conn_params, &dev->conn);

    These parameters are basically the parameters in the Demo, but
    "bt_hci_core: Connection creation timeout triggered." Error still exists. What's more fatal is that once this error occurs, almost all subsequent device connections will also generate this error, and it will take many incorrect connections to recover.

Related