<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bluetooth connection cache processing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/122543/bluetooth-connection-cache-processing</link><description>I attempted to use nRF52840 for multi-connection data interaction, but whenever I was debugging, I always encountered the problem of being unable to establish a connection. The return value of bt_conn_le_create was -12. 
 My communication has the following</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Jun 2025 20:47:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/122543/bluetooth-connection-cache-processing" /><item><title>RE: Bluetooth connection cache processing</title><link>https://devzone.nordicsemi.com/thread/540935?ContentTypeID=1</link><pubDate>Mon, 30 Jun 2025 20:47:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4e45afd-59d4-4732-b501-0e3de7c5d595</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The error code&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;-12&lt;/code&gt;&lt;span&gt;&amp;nbsp;when attempting to create a connection (e.g., with&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;bt_conn_le_create&lt;/code&gt;&lt;span&gt;&amp;nbsp;or similar functions) typically means&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&amp;quot;Not enough memory&amp;quot;&lt;/strong&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;code dir="ltr"&gt;-ENOMEM&lt;/code&gt;&lt;span&gt;). This indicates that the system does not have enough resources (such as heap memory or connection objects) to establish a new connection.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The error code&amp;nbsp;&lt;code dir="ltr"&gt;-128&lt;/code&gt;&amp;nbsp;in the context of&amp;nbsp;&lt;code dir="ltr"&gt;bt_gatt_dm: GATT discover failed, error: -128&lt;/code&gt;&amp;nbsp;indicates that there is&amp;nbsp;&lt;strong&gt;no active BLE connection&lt;/strong&gt;&amp;nbsp;when the GATT discovery is attempted. This is equivalent to the&amp;nbsp;&lt;code dir="ltr"&gt;ENOTCONN&lt;/code&gt;&amp;nbsp;error, which means &amp;quot;Not connected.&amp;quot; You will encounter this error if you try to perform GATT operations, such as service discovery, without having an established BLE connection to the peer device.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can refer to the&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;a title="Scan, connect and establish connection to up to 62 peripherals." href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/bluetooth/central_multilink/README.html#ble_central_multilink"&gt;Central Multilink&lt;/a&gt;&amp;nbsp;sample, which can&amp;nbsp;&lt;/span&gt;&lt;span&gt;scan, connect, and establish multilink connections.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;br /&gt;Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connection cache processing</title><link>https://devzone.nordicsemi.com/thread/540649?ContentTypeID=1</link><pubDate>Fri, 27 Jun 2025 04:26:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:735cf8fb-7c1e-4dbf-93a5-dc641d59567c</guid><dc:creator>carefree</dc:creator><description>&lt;p&gt;Here are my connection parameters:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;peripherals:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;_API_(int)
_LIB_NAME_(init)()
{
    int err;

    err = bt_enable(NULL);
    if (err)
    {
        return err;
    }

#if defined(CONFIG_BT_CTLR_PHY_CODED)

    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);

#elif defined(CONFIG_BT_EXT_ADV)

    struct bt_le_adv_param param =
        BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
                                 BT_LE_ADV_OPT_EXT_ADV,_LIB_NAME_(inst
                             BT_GAP_ADV_FAST_INT_MIN_1,
                             BT_GAP_ADV_FAST_INT_MAX_1,
                             NULL);

#endif

    err = bt_le_ext_adv_create(&amp;amp;param, NULL, &amp;amp;_LIB_NAME_(inst).adv);

    if (err)
    {
        printk(&amp;quot;Failed to create Coded PHY extended advertising set (err %d)\n&amp;quot;, err);
        return err;
    }

    err = bt_le_ext_adv_set_data(_LIB_NAME_(inst).adv, ad, ARRAY_SIZE(ad), NULL, 0);
    if (err)
    {
        printk(&amp;quot;Failed to set extended advertising data (err %d)\n&amp;quot;, err);
        return err;
    }

    err = bt_le_ext_adv_start(_LIB_NAME_(inst).adv, BT_LE_EXT_ADV_START_DEFAULT);
    if (err)
    {
        printk(&amp;quot;Failed to start advertising set (err %d)\n&amp;quot;, err);
        return err;
    }

    return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;At the same time, after the connection, change the PHY to CODED:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void connected(struct bt_conn *conn, uint8_t conn_err)
{
    int err;

    if (conn_err)
    {
        printk(&amp;quot;Connection failed, err 0x%02x \n&amp;quot;, conn_err);
        _LIB_NAME_(inst).conn = NULL;
        return;
    }

#if defined(CONFIG_BT_CTLR_PHY_CODED)

    const struct bt_conn_le_phy_param preferred_phy = {
        .options = BT_CONN_LE_PHY_OPT_CODED_S8,
        .pref_rx_phy = BT_GAP_LE_PHY_CODED,
        .pref_tx_phy = BT_GAP_LE_PHY_CODED,
    };
    err = bt_conn_le_phy_update(conn, &amp;amp;preferred_phy);
    if (err)
    {
        printk(&amp;quot;bt_conn_le_phy_update() returned %d&amp;quot;, err);
    }

#endif

    _LIB_NAME_(inst).conn = conn;
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
    // if (_LIB_NAME_(inst).config != NULL &amp;amp;&amp;amp; _LIB_NAME_(inst).config-&amp;gt;callback.connected != NULL)
    // {
    //     _LIB_NAME_(inst).config-&amp;gt;callback.connected(false);
    // }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;central:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  #define INTERVAL_MIN 10
#define INTERVAL_MAX 10
static struct bt_le_conn_param *conn_param = BT_LE_CONN_PARAM(INTERVAL_MIN, INTERVAL_MAX, 0, 400);
  
  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);

    struct bt_le_conn_param *conn_params = BT_LE_CONN_PARAM(
        BT_GAP_INIT_CONN_INT_MIN,
        BT_GAP_INIT_CONN_INT_MAX,
        0,
        100);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connection cache processing</title><link>https://devzone.nordicsemi.com/thread/540647?ContentTypeID=1</link><pubDate>Fri, 27 Jun 2025 04:10:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef7af241-bf39-425d-b76f-158d90bc3650</guid><dc:creator>carefree</dc:creator><description>&lt;p&gt;After making the modifications, the results were indeed quite satisfactory. However, there are still some other issues that I would like to ask you about. Here is my debugging log:&lt;/p&gt;
&lt;p&gt;connect [E4], rssi: -37 phy: 1.&lt;br /&gt;[connected] Connect success.&lt;br /&gt;connect [E4], ret: 1.&lt;br /&gt;[E4]: Send Hello.&lt;br /&gt;[E4]: Send Check Mode.&lt;br /&gt;[E4]: Config Mode.&lt;br /&gt;connect [8F], rssi: -45 phy: 1.&lt;br /&gt;[00:00:07.392,883] [1;33m&amp;lt;wrn&amp;gt; bt_hci_core: opcode 0x2043 status 0x0d [0m&lt;br /&gt;Create connection err: -12.&lt;br /&gt;connect [95], ret: 0.&lt;br /&gt;error: 3.&lt;br /&gt;connect [10], rssi: -50 phy: 1.&lt;br /&gt;[00:00:08.456,329] [1;33m&amp;lt;wrn&amp;gt; bt_hci_core: opcode 0x2043 status 0x0d [0m&lt;br /&gt;Create connection err: -12.&lt;br /&gt;connect [95], ret: 0.&lt;br /&gt;error: 3.&lt;br /&gt;connect [8F], rssi: -45 phy: 1.&lt;br /&gt;[00:00:09.491,851] [1;33m&amp;lt;wrn&amp;gt; bt_hci_core: opcode 0x2043 status 0x0d [0m&lt;br /&gt;Create connection err: -12.&lt;br /&gt;connect [95], ret: 0.&lt;br /&gt;error: 3.&lt;br /&gt;connect [D3], rssi: -42 phy: 1.&lt;br /&gt;[00:00:10.545,196] [1;33m&amp;lt;wrn&amp;gt; bt_hci_core: opcode 0x2043 status 0x0d [0m&lt;br /&gt;Create connection err: -12.&lt;br /&gt;connect [95], ret: 0.&lt;br /&gt;error: 3.&lt;br /&gt;connect [10], rssi: -51 phy: 1.&lt;br /&gt;[00:00:11.610,595] [1;33m&amp;lt;wrn&amp;gt; bt_hci_core: opcode 0x2043 status 0x0d [0m&lt;br /&gt;Reset BLE......&lt;/p&gt;
&lt;p&gt;1.This situation occurred when several devices were attempting to connect simultaneously. From the log, it can be seen that except for the first connected device, all the other devices seemed to have failed to connect. What could be the reason for this?&lt;/p&gt;
&lt;p&gt;[00:00:19.576,416] [1;33m&amp;lt;wrn&amp;gt; bt_hci_core: Connection creation timeout triggered[0m&lt;br /&gt;[connected] Connect error: 2.&lt;br /&gt;connect [6C], ret: 0.&lt;br /&gt;error: 3.&lt;br /&gt;connect [46], rssi: -45 phy: 1.&lt;br /&gt;[connected] Connect success.&lt;/p&gt;
&lt;p&gt;[00:00:51.086,395] [1;31m&amp;lt;err&amp;gt; bt_gatt_dm: GATT discover failed, error: -128.[0m&lt;br /&gt;error: 5.&lt;/p&gt;
&lt;p&gt;2.Sometimes such situations occur as well. Could this be due to poor communication quality? Can I optimize some configuration parameters to reduce the occurrence of these two types of errors?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connection cache processing</title><link>https://devzone.nordicsemi.com/thread/540618?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2025 16:07:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:021918f9-90ea-4286-880d-ec3e2bf137c5</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user=""]1. Sometimes it is impossible to search for any device. This situation usually occurs during the transition from Coded to 2M phy.[/quote]
&lt;p&gt;It seems resource exhaustion or stack instability due to improper cleanup after disconnects or failed connections.&lt;/p&gt;
[quote user=""]2. Due to some communication abnormalities, the device resources were not properly released, resulting in bt_conn_le_create returning -12.[/quote]
&lt;p&gt;&lt;code dir="ltr"&gt;bt_conn_le_create&lt;/code&gt;&lt;span&gt;&amp;nbsp;returning&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;-12&lt;/code&gt;&lt;span&gt;&amp;nbsp;, which typically maps to&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;-ENOMEM means&lt;/code&gt;&lt;span&gt;&amp;nbsp;out of memory/resources.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In your disconnect callback, I suggest always calling&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;bt_conn_unref()&lt;/code&gt;&lt;span&gt;&amp;nbsp;on the connection object. If you store connection pointers elsewhere, ensure you manage their reference counts correctly. For multilink, you also need to ensure that the&amp;nbsp;CONFIG_BT_MAX_CONN and CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT are the number of concurrent connections you need, and increase&amp;nbsp;&lt;code dir="ltr"&gt;CONFIG_HEAP_MEM_POOL_SIZE&lt;/code&gt;&amp;nbsp;accordingly. See my colleague&amp;#39;s explanation in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/118385/ble-peripheral-with-multiple-connections"&gt;this post&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;br /&gt;Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connection cache processing</title><link>https://devzone.nordicsemi.com/thread/540567?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2025 10:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:733f114a-a1c9-4525-88d6-6cd9cde9236f</guid><dc:creator>carefree</dc:creator><description>&lt;p&gt;In prj.conf, I set CONFIG_BT_MAX_CONN to 1, which can trigger this issue more quickly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>