Extended Advertising Start Issue with PAwR Scanner Role

Hi.

Environment : nrf52833, ncs v3.1.1

I am developing device that has PAwR Scanner Role and Extended Advertising for connecting Mobile Phone(nRF Connect APP).

PAwR is Fine. However when connect/disconnect several Times, bt_le_ext_adv_start return -12.

under code is prj.conf

## USER Config
CONFIG_DTM_INCLUDE=y
CONFIG_USER_LOG_ENABLE=n


# LOG
CONFIG_LOG=y
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_DEFAULT_LEVEL=0
CONFIG_UART_CONSOLE=n
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_LOG_MODE_IMMEDIATE=y

CONFIG_LOG_TIMESTAMP_64BIT=y

## DEBUG
CONFIG_ASSERT=y
CONFIG_RESET_ON_FATAL_ERROR=n

CONFIG_DEBUG_THREAD_INFO=y
CONFIG_DEBUG_OPTIMIZATIONS=y



## WATCH DOG
CONFIG_WATCHDOG=y

CONFIG_REBOOT=y

## Power Management
CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y


##FLASH
CONFIG_FLASH=y
CONFIG_SOC_FLASH_NRF_UICR=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y


## UART
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_USE_RUNTIME_CONFIGURE=y
CONFIG_UART_CONSOLE=n

## AES
CONFIG_NRF_SECURITY=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y
CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE=32
CONFIG_PSA_WANT_GENERATE_RANDOM=y
CONFIG_PSA_WANT_KEY_TYPE_AES=y
CONFIG_PSA_WANT_ALG_CBC_PKCS7=y
CONFIG_PSA_WANT_ALG_CCM=y


## BLE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_BUF_ACL_RX_SIZE=519
CONFIG_BT_BUF_ACL_TX_SIZE=519
CONFIG_BT_L2CAP_TX_MTU=512

CONFIG_BT_HCI_ERR_TO_STR=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_RX_STACK_SIZE=4096

CONFIG_BT_ID_MAX=3
CONFIG_BT_MAX_CONN=7
CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT=7


CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y

## PAWR
CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=5
CONFIG_BT_PER_ADV_SYNC=y

CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER=y
CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER=y

CONFIG_BT_PER_ADV_SYNC_RSP=y
CONFIG_BT_PER_ADV_SYNC_BUF_SIZE=255
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=255




# #### BLE DTM START
# #Configure assertions
CONFIG_ASSERT=y
CONFIG_ASSERT_NO_COND_INFO=y
CONFIG_ASSERT_NO_MSG_INFO=y
CONFIG_HW_STACK_PROTECTION=y

# # Use necessary peripherals
CONFIG_NRFX_TIMER0=y
CONFIG_NRFX_TIMER1=y
CONFIG_NRFX_TIMER2=y
CONFIG_CLOCK_CONTROL=y

CONFIG_FEM_AL_LIB=y

when increase  CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT and Max_Conn, can more connect. but is is not solution.

I use create one ext adv. and reuse it.
I try restart extended advertising on recycled callback. and it execute that delayed after 3 seconds. delay execute function use k_work_schedule.
I checked Log about conn Ref Count. Count is normally increase and reduce when connected and disconnected
could you advice any solution?
* Add: after PAwR is Timeout, adv start is fine. but after resynced from Advertiser, restart advertisement return -12 error.
* Add: Adv Start is Fine when PAwR is Not Synced. Only Occur When PAwR Synced. After the advertisement is failed, the recycled callback arrives, and the adv fails with -12.
 This repeats continuously.
*Add (26.06.16): 
when Disconnected
00> [00:00:34.632,781] <dbg> bt_adv: bt_le_adv_resume: No valid legacy adv 

when return -12 err
Detail Log is Under.
00> [00:01:45.228,790] <dbg> bt_hci_core: tx_processor: TX process start
00> [00:01:45.228,820] <dbg> bt_hci_core: hci_core_send_cmd: fetch cmd
00> [00:01:45.228,851] <dbg> bt_hci_core: hci_core_send_cmd: Sending command 0x2083 (buf 0x20016524) to driver
00> [00:01:45.228,851] <dbg> bt_hci_core: bt_send: buf 0x20016524 len 54 type 1
00> [00:01:45.229,003] <dbg> bt_hci_core: bt_tx_irq_raise: kick TX
00> [00:01:45.229,095] <dbg> bt_hci_core: tx_processor: TX process start
00> [00:01:45.506,530] <dbg> bt_hci_core: bt_recv_unsafe: buf 0x20016304 len 9
00> [00:01:45.506,561] <dbg> bt_hci_core: hci_cmd_complete: opcode 0x2083
00> [00:01:45.506,652] <dbg> bt_hci_core: hci_cmd_done: opcode 0x2083 status 0x00 BT_HCI_ERR_SUCCESS buf 0x20016304
00> [00:01:45.506,683] <dbg> bt_hci_core: hci_cmd_done: sync cmd released
00> [00:01:45.506,713] <dbg> bt_hci_core: bt_tx_irq_raise: kick TX
00> [00:01:45.506,835] <dbg> bt_hci_core: bt_hci_cmd_send_sync: rsp 0x20016524 opcode 0x2083 len 3
00> [00:01:45.506,927] <dbg> bt_hci_core: tx_processor: TX process start
00> [00:01:47.033,996] <dbg> bt_hci_core: bt_hci_cmd_send_sync: process cmd 0x20016524 want 0x20016524
00> --- 33 messages dropped ---
00> [00:01:47.034,027] <dbg> bt_hci_core: hci_core_send_cmd: fetch cmd
00> [00:01:47.034,057] <dbg> bt_hci_core: hci_core_send_cmd: Sending command 0x2036 (buf 0x20016524) to driver
00> [00:01:47.034,088] <dbg> bt_hci_core: bt_send: buf 0x20016524 len 29 type 1
00> [00:01:47.034,240] <dbg> bt_hci_core: bt_recv_unsafe: buf 0x20016304 len 8
00> [00:01:47.034,271] <dbg> bt_hci_core: hci_cmd_complete: opcode 0x2036
00> [00:01:47.034,393] <dbg> bt_hci_core: hci_cmd_done: opcode 0x2036 status 0x00 BT_HCI_ERR_SUCCESS buf 0x20016304
00> [00:01:47.034,423] <dbg> bt_hci_core: hci_cmd_done: sync cmd released
00> [00:01:47.034,484] <dbg> bt_hci_core: bt_tx_irq_raise: kick TX
00> [00:01:47.034,576] <dbg> bt_hci_core: bt_hci_cmd_send_sync: rsp 0x20016524 opcode 0x2036 len 2
00> [00:01:47.034,698] <dbg> bt_hci_core: bt_hci_cmd_alloc: buf 0x20016524
00> [00:01:47.034,729] <dbg> bt_hci_core: bt_hci_cmd_send_sync: buf 0x20016524 opcode 0x2039 len 6
00> [00:01:47.034,759] <dbg> bt_hci_core: bt_hci_cmd_send: opcode 0x2039 param_len 6
00> [00:01:47.034,820] <dbg> bt_hci_core: bt_tx_irq_raise: kick TX
00> [00:01:47.034,851] <dbg> bt_hci_core: bt_hci_cmd_send_sync: process cmd 0x20016524 want 0x20016524
00> [00:01:47.034,881] <dbg> bt_hci_core: hci_core_send_cmd: fetch cmd
00> [00:01:47.034,942] <dbg> bt_hci_core: hci_core_send_cmd: Sending command 0x2039 (buf 0x20016524) to driver
00> [00:01:47.034,973] <dbg> bt_hci_core: bt_send: buf 0x20016524 len 10 type 1
00> [00:01:47.035,095] <dbg> bt_hci_core: bt_recv_unsafe: buf 0x20016304 len 7
00> [00:01:47.035,125] <dbg> bt_hci_core: hci_cmd_complete: opcode 0x2039
00> [00:01:47.035,247] <dbg> bt_hci_core: hci_cmd_done: opcode 0x2039 status 0x0d BT_HCI_ERR_INSUFFICIENT_RESOURCES buf 0x20016304
00> [00:01:47.035,278] <dbg> bt_hci_core: hci_cmd_done: sync cmd released
00> [00:01:47.035,339] <dbg> bt_hci_core: bt_tx_irq_raise: kick TX
00> [00:01:47.035,491] <wrn> bt_hci_core: opcode 0x2039 status 0x0d BT_HCI_ERR_INSUFFICIENT_RESOURCES
00> [00:01:47.035,552] <err> bt_adv: Failed to start advertiser
00> [00:01:47.035,583] <inf> ble: bt_le_ext_adv_start Fail -12
start code is below
static void advStartRaw()
{
    if (deviceInfo.advState)
        return;

    advParam.interval_min = deviceInfo.advInterval;
    advParam.interval_max = deviceInfo.advInterval + 32; // + 20ms

    int err = bt_le_ext_adv_set_data(extAdv, advData, ARRAY_SIZE(advData),
                                     NULL, 0);
    if (err)
    {
        LOG_INF("bt_le_ext_adv_set_data Fail %d", err);
        return;
    }

    err = bt_le_ext_adv_update_param(extAdv, &advParam);
    if (err)
    {
        LOG_INF("bt_le_ext_adv_update_param Fail %d", err);
        return;
    }

    err = bt_le_ext_adv_start(extAdv, &extraStartAdvParam);
    if (err)
    {
        LOG_INF("bt_le_ext_adv_start Fail %d", err);
        return;
    }

    deviceInfo.advState = true;
    LOG_INF("ADV Start");    
}
stop is below
static int advStopRaw()
{
    if (!deviceInfo.advState)
        return -1;

    int err = bt_le_ext_adv_stop(extAdv);
    if (err)
    {
        LOG_INF("BT ADV Stop Fail Code %d", err);
        return err;
    }

    deviceInfo.advState = false;
    LOG_INF("ADV Stop");
    return 0;
}
onConnected is Below
static void onConnected(struct bt_conn *conn, uint8_t err)
{
    if (err)
    {
        LOG_INF("Connection Error %d", err);
        return;
    }

    advStopRaw();
    connHandle = bt_conn_ref(conn);
    connectedState = true;
    deviceInfo.advState = false;
    mtuSize = (int)bt_gatt_get_mtu(conn);
    LOG_INF("Connected. Set MTU Size : %d", mtuSize);
	bt_conn_le_param_update(conn, &updateConnParam); 
}
onDisconnected
static void onDisconnected(struct bt_conn *conn, uint8_t reason)
{  
    bt_conn_unref(conn);
    connectedState = false;
    connHandle = NULL;
    //LOG_INF("Disconnected. Reason 0x%02X", reason);     
    // 0x19 Remote Term Conn
    // 0x22 Local Term Conn
    LOG_INF("Disconnected. Reason 0x%02x %s\n",reason, bt_hci_err_to_str(reason));
}
Parents
  • Hi,

    Please note that there is functionality in PAwR for connecting with a normal BLE connection between the advertiser and any scanner. Because of that, you may need an additional free connection slot. What confuses me is for this you should need a connection slot as central, not peripheral, but please check anyway if things are working if you increase both CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT and CONFIG_BT_MAX_CONN by one. You wrote that things were working when increasing those. If increasing them by 1 solves the issue, then I will suggest that as the solution.

    If the above did not help, then I would need some more info for looking further into the issue. For clarification, please answer the following questions.

    I checked Log about conn Ref Count. Count is normally increase and reduce when connected and disconnected

    Does the reference counter increase and decrease the normal way, also when you see the issue?

    after PAwR is Timeout, adv start is fine. but after resynced from Advertiser, restart advertisement return -12 error.

    Is starting the connectable advertiser always failing with -12 NOMEM when synchronized?

    Is starting the connectable advertiser always succeeding when not synchronized?

    Regarding the following line:

    err = bt_le_ext_adv_update_param(extAdv, &advParam);

    What is the full advParam used there?

    Regards,
    Terje

  • -> So, I solved the problem by increasing the count to 10 and rebooting when the -12 error occurred, but this method is still only a temporary fix.

    Does the reference counter increase and decrease the normal way, also when you see the issue?

    -> Yes. when issue occurred, still reference counter is normally increase and decrease.

    Is starting the connectable advertiser always failing with -12 NOMEM when synchronized?

    -> Yes. It depends on the count value, but typically, a -12 error occurs at around count -3. For example, if the count is 10, and you connect after syncing and restart an ad about 7 times, a -12 error will occur thereafter.

    Is starting the connectable advertiser always succeeding when not synchronized?

    -> When only PAwR is enabled and the device is restarted multiple times without syncing, the -12 error does not occur. Additionally, even if you disconnect the device after syncing and then reconnect multiple times to restart the advertisement, no error occurs.

    err = bt_le_ext_adv_update_param(extAdv, &advParam);

    What is the full advParam used there?

    -> advParam is below.

    static struct bt_le_adv_param advParam = {
        .id = BT_ID_DEFAULT,
        .sid = 1,
        .secondary_max_skip = 0,
        .options = BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV,
        .interval_min = ADV_MIN_INTERVAL,
        .interval_max = ADV_MAX_INTERVAL,
        .peer = NULL,
    };

    The SID value was initially 0, and I thought changing it to 1 might solve the problem, but it didn't work.

Reply
  • -> So, I solved the problem by increasing the count to 10 and rebooting when the -12 error occurred, but this method is still only a temporary fix.

    Does the reference counter increase and decrease the normal way, also when you see the issue?

    -> Yes. when issue occurred, still reference counter is normally increase and decrease.

    Is starting the connectable advertiser always failing with -12 NOMEM when synchronized?

    -> Yes. It depends on the count value, but typically, a -12 error occurs at around count -3. For example, if the count is 10, and you connect after syncing and restart an ad about 7 times, a -12 error will occur thereafter.

    Is starting the connectable advertiser always succeeding when not synchronized?

    -> When only PAwR is enabled and the device is restarted multiple times without syncing, the -12 error does not occur. Additionally, even if you disconnect the device after syncing and then reconnect multiple times to restart the advertisement, no error occurs.

    err = bt_le_ext_adv_update_param(extAdv, &advParam);

    What is the full advParam used there?

    -> advParam is below.

    static struct bt_le_adv_param advParam = {
        .id = BT_ID_DEFAULT,
        .sid = 1,
        .secondary_max_skip = 0,
        .options = BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV,
        .interval_min = ADV_MIN_INTERVAL,
        .interval_max = ADV_MAX_INTERVAL,
        .peer = NULL,
    };

    The SID value was initially 0, and I thought changing it to 1 might solve the problem, but it didn't work.

Children
No Data
Related