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.

  • The peripheral example has several missing dependencies so it does not build, unfortunately. 

  • It should be built.Which dependencies were missing.Can I provide them to you?

  • Sorry, I just assumed you were using SES. I'll try again with Keil

  • The Keil projects built ok so I was able to do some debugging. What I noticed was that the Connection handle in m_private became overwritten by the 'm_conn_handle_peripheral_c' handle if I established a connection with the peripheral last. This is because ble_private.c::on_connect() updates the connection handle on all BLE_GAP_EVT_CONNECTED events regardless of the GAP role.

    Fix to prevent the connection handle from being updated on central connection:

    static void on_connect(ble_private_t * p_private, ble_evt_t const * p_ble_evt)
    {
        uint8_t  role        = p_ble_evt->evt.gap_evt.params.connected.role;
        if (role != BLE_GAP_ROLE_PERIPH)
        {
            return;
        }
        
        p_private->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    }

  • I'm sorry for my late reply.I had tried it as your suggestion. It works fine for now.I will continue to test it.It  confused me.  The "if (role == BLE_GAP_ROLE_PERIPH || ble_evt_is_advertising_timeout(p_ble_evt)) " of ble_evt_handler should work. ble_private.c::on_connect() would be called not only in on_ble_peripheral_evt?

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint16_t conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        uint16_t role        = ble_conn_state_role(conn_handle);
    
        // Based on the role this device plays in the connection, dispatch to the right handler.
        if (role == BLE_GAP_ROLE_PERIPH || ble_evt_is_advertising_timeout(p_ble_evt))
        {
    			  NRF_LOG_INFO( "BLE_GAP_ROLE_PERIPH" );
    				ble_private_on_ble_evt( p_ble_evt, &m_private );
            on_ble_peripheral_evt(p_ble_evt);
        }
        else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT))
        {
    			  NRF_LOG_INFO( "BLE_GAP_ROLE_CENTRAL" );
            ble_private_c_on_ble_evt(p_ble_evt, &m_private_c);
            on_ble_central_evt(p_ble_evt);
        }
    }

Related