This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

issue about Ram setting and NRF_ERROR_RESOURCES:

Hi:

  I'm developing a project with  nRF 58232 in ble_app_hrs_rscs_relay example ( s132  sdk:nRF5SDK160098a08e2 ). The device need to be central and peripheral,My device worked fine as peripheral with smart phone. After that I tried to make the device  connect to the smart phone first, and then connect to other device as central. My device worked fine as  central and peripheral at first. But I got [NRF_ERROR_RESOURCES]  error after a while.

<info> app: Peer Temp.

<debug> ble_private_c: send data to peripheral

<debug> nrf_ble_gq: Adding item to the request queue

<debug> nrf_ble_gq: GATTC Write Request

<debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0.

<debug> nrf_ble_gq: Processing the request queue...

<debug> nrf_ble_gq: Processing the request queue...

<debug> ble_private_c: Received HVX on link 0x16, hrm_handle 0x16

<debug> ble_private_c: Received HVX on link 0x16, hrm_handle 0x16

<info> app: Temp Respond.

<info> app: Peer Temp.

<debug> ble_private_c: send data to peripheral

<debug> nrf_ble_gq: Adding item to the request queue

<debug> nrf_ble_gq: GATTC Write Request

<debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0.

<debug> nrf_ble_gq: Processing the request queue...

<debug> nrf_ble_gq: Processing the request queue...

<debug> ble_private_c: Received HVX on link 0x16, hrm_handle 0x16

<debug> ble_private_c: Received HVX on link 0x16, hrm_handle 0x16

<info> app: Temp Respond.

<error> app: ERROR 19 [NRF_ERROR_RESOURCES] at :0PC at: 0x00000000
<error> app: End of error report
 

I seeked the answer for NRF_ERROR_RESOURCES in DevZone.I found it might be caused by size of BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT or BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT. So I changed the size of both BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT  and BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT to 3. Unfortunately I got an unknown error after my device conneted to peripheral.

<info> app: Peripheral connected

<info> app: Central connected<info> app: Attempt to find Peripheral on conn_handle 0x0

<debug> nrf_ble_gq: Registering connection handle: 0x0000

<debug> ble_db_disc: Starting discovery of service with UUID 0xFF00 on connection handle 0x0.

<debug> nrf_ble_gq: Adding item to the request queue

<debug> nrf_ble_gq: GATTC Primary Services Discovery Request

<debug> nrf_ble_gq: SD GATT procedure (2) succeeded on connection handle: 0.

<info> app: Peer Connect.

<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: Found service UUID 0xFF00.<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.

<error> app: ERROR 13313 [Unknown error code] at :0PC at: 0x00000000
<error> app: End of error report

And I haven't changed the ram setting after BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT  and  BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT were modified.If it needed to modify the ram,how much ram I need to increase in MDK setting If  I increase 1 in BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT or

 BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT  . 

Maybe I get a wrong way to fix NRF_ERROR_RESOURCES. Please tell me what do I miss.

My second problem is about the Ram setting for  __HEAP_SIZE. I had changed NRF_BLE_GQ_GATTS_HVX_MAX_DATA_LEN and NRF_BLE_GQ_GATTC_WRITE_MAX_DATA_LEN to 20.And I found gattc_write_alloc and gatts_hvx_alloc had called nrf_balloc_alloc.But __HEAP_SIZE is zero in ble_app_hrs_rscs_relay example. Did I need to change __HEAP_SIZE. If __HEAP_SIZE need to be changed, I need to change ram setting, right?My ram setting is default in ble_app_hrs_rscs_relay example.

  • Hi,

    The queue module should treat the NRF_ERROR_RESOURCES error the same it treats NRF_ERROR_BUSY in queue_process() request_process() as noted in this other thread: https://devzone.nordicsemi.com/f/nordic-q-a/57919/ble-gatt-queue-library-with-sd_ble_gattc_write-nrf_error_resources. That may explain why you run out of buffers space. Please try to patch the module as shown below and see if you get the same result.

    //From
    if (err_code == NRF_ERROR_BUSY) // Softdevice is processing another GATT request.
    {
        NRF_LOG_DEBUG("SD is currently busy. The GATT request procedure will be attempted \
                              again later.");
    }
    //to
    if (err_code == NRF_ERROR_BUSY) || (err_code == NRF_ERROR_RESOURCES) // Softdevice is processing another GATT request.
    {
        NRF_LOG_DEBUG("SD is currently busy. The GATT request procedure will be attempted \
                    again later.");
    }
            

     

    My second problem is about the Ram setting for  __HEAP_SIZE.

     balloc use statically allocated RAM instead of heap.

  • Thanks for reply. I had done  as you advised. I didn't see NRF_ERROR_RESOURCES any more for now.But I still got Unknown error[ERROR 13313].It only happened when my device connected the peer after the phone connected my device first.If my device connected the peer first, and then phone connected to my device, it worked fine.What may cause that?

    <info> app: Central connected
    
    <info> app: Attempt to find Peripheral on conn_handle 0x0
    
    <debug> nrf_ble_gq: Purging request queue with id: 0
    
    <debug> nrf_ble_gq: Pointer to freed memory block: 0x20003A64.
    
    <debug> nrf_ble_gq: Pointer to freed memory block: 0x20003A7C.
    
    <debug> nrf_ble_gq: Registering connection handle: 0x0000
    
    <debug> ble_db_disc: Starting discovery of service with UUID 0xFF00 on connection handle 0x0.
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Primary Services Discovery Request
    
    <debug> nrf_ble_gq: SD GATT procedure (2) succeeded on connection handle: 0.
    
    <info> app: Peer Connect.
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> ble_db_disc: Found service UUID 0xFF00.
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Characteristic Discovery Request
    
    <debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
    
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Characteristic Discovery Request
    
    <debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
    
    <debug> nrf_ble_gq: Processing t
    he request queue...
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Characteristic Discovery Request
    
    <debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
    
    <debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
    
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> ble_db_disc: Discovery of service with UUID 0xFF00 completed with success on connection handle 0x0.
    
    <debug> ble_private_c: Private Service discovered at peer.
    
    <info> app: peripheral discovered on conn_handle 0x0
    
    <debug> ble_private_c: Configuring CCCD. CCCD Handle = 23, Connection Handle = 0
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Write Request
    
    <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0.
    
    <info> app: DB Discovery instance 0x2000302C available on conn handle: 0
    
    <info> app: Found 1 services on conn_handle: 0
    
    <info> app: Peer Verify.
    
    <debug> ble_private_c: send data to peripheral
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Write Reques
    t
    
    <debug> nrf_ble_gq: SD is currently busy. The GATT request procedure will be attempted                       again later.
    
    <debug> nrf_ble_gq: Pointer to allocated memory block: 0x20003A4C.
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> nrf_ble_gq: GATTC Write Request
    
    <debug> nrf_ble_gq: SD is currently busy. The GATT request procedure will be attempted                           again later.
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> nrf_ble_gq: GATTC Write Request
    
    <debug> nrf_ble_gq: Pointer to freed memory block: 0x20003A4C.
    
    <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0.
    
    <debug> nrf_ble_gq: Processing t
    he request queue...
    
    <debug> nrf_ble_gq: Processing the request queue...
    
    <debug> ble_private_c: Received HVX on link 0x16, hrm_handle 0x16
    
    <debug> ble_private_c: Received HVX on link 0x16, hrm_handle 0x16
    
    <info> app: Peer Verify Success.
    
    <info> app: Peer Temp.
    
    <debug> ble_private_c: send data to peripheral
    
    <debug> nrf_ble_gq: Adding item to the request queue
    
    <debug> nrf_ble_gq: GATTC Write Request
    
    <debug> nrf_ble_gq: SD GATT procedure (1) succeeded on connection handle: 0.
    
    
    <error> app: ERROR 13313 [Unknown error code] at :0
    
    PC at: 0x00000000
    
    <error> app: End of error report

  • 13313=0x3401 means the send function returned the sys attribute missing error:

    BLE_ERROR_GATTS_SYS_ATTR_MISSING

    System attributes missing, use sd_ble_gatts_sys_attr_set to set them to a known value.

    Is the BLE_GATTS_EVT_SYS_ATTR_MISSING event handled in your application or is it handled by the Peer Manager module (used if you support bonding)? 

    MSC for BLE_GATTS_EVT_SYS_ATTR_MISSING event:

    GATTS System Attributes Handling: Unknown Peer

  • My device didn't spupport bongding.

    #define SEC_PARAM_BOND                  0                                       /**< Perform bonding. */
    #define SEC_PARAM_MITM                  0                                       /**< Man In The Middle protection not required. */
    #define SEC_PARAM_LESC                  0                                       /**< LE Secure Connections not enabled. */
    #define SEC_PARAM_KEYPRESS              0                                       /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE                    /**< No I/O capabilities. */
    #define SEC_PARAM_OOB                   0                                       /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE          7                                       /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE          16                                      /**< Maximum encryption key size. */

  • But are you including the Peer manager module in your project? If not, please implement event handling for the BLE_GATTS_EVT_SYS_ATTR_MISSING event like it's implemented in the ble_app_uart example:

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
    
        switch (p_ble_evt->header.evt_id)
        {
    ...
            case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
                // Pairing not supported
                err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_SYS_ATTR_MISSING:
                // No system attributes have been stored.
                err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
                APP_ERROR_CHECK(err_code);
                break;
    
    ...
        }
    }

Related