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. 

  • 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.

  • carefree said:
    "bt_hci_core: Connection creation timeout triggered."

    Did you get on the peripheral side or the central side? Could you update the error log on both sides?

    Could you try to debug and ensure that the bt_conn_unref() is executed when the connection fails in your project?

  • warn.zip

    These are some of the logs that I have captured.
    warn.txt: Log file when "bt_hci_core: opcode 0x2043 status 0x0d" occurs at the Central end.
    warn2.txt: Log file when "Connection creation timeout triggered." occurs at the Central end.
    warn3.txt: Log file of the Peripheral end when "Connection creation timeout triggered." occurs at the Central end.

    The bt_conn_unref() function exists in both the err of the connected() function and the disconnected() function. Therefore, if the connection fails, it will definitely be called (unless there are other situations where it needs to be called additionally. If so, please let me know).

    However, for some devices, such errors usually occur when they establish the connection for the first time. Therefore, I think it might not be caused by the failure of the previous connection. Of course, the log information should be the main reference.

  • When "Connection creation timeout triggered." is triggered due to a failed device connection, all subsequent attempts to connect with that device will be incorrect until another device successfully attempts to connect, at which point the device will be able to connect properly.

Reply Children
No Data
Related