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

Error NRF_ERROR_NO_MEM ble_nus_data_send on ble_app_hrs_rscs_relay

I try to add NUS service in example ble_app_hrs_rscs_relay.

I have fail on send data from "Relay" to smart phone iOS nRF Toolbox.

1. I have modify the MTU size .
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247 

2. I try to echo back the data as below code.

static void nus_data_handler(ble_nus_evt_t * p_evt)
{

    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_DEBUG("Received data from BLE eNUS. Writing data on UART.");
        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);

        for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
        {
            do
            {
                if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
        if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
        {
            while (app_uart_put('\n') == NRF_ERROR_BUSY);
        }

		
		{
			uint16_t index = 0;


		
			index = p_evt->params.rx_data.length;
			
			{
				NRF_LOG_DEBUG("Ready to send data over BLE NUS");
				NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, index);
			
				do
				{
					err_code = ble_nus_c_string_send(&etest_m_nus_c, (uint8_t *)p_evt->params.rx_data.p_data, index);
					if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
					{
						APP_ERROR_CHECK(err_code);
					}
				} while (err_code == NRF_ERROR_BUSY);
			
				index = 0;
			}

		if (ECHOBACK_BLE_UART_DATA)
			{
				// Send data back to smart phone.
				do
				{
					NRF_LOG_DEBUG("send data back smart phone over BLE NUS");
					NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, index);

					err_code = ble_nus_data_send(&etest_m_nus, (uint8_t *)p_evt->params.rx_data.p_data, &index, etest_m_conn_handle_nus_c);		//test echo loop back

					if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
					{
						NRF_LOG_ERROR("Failed sending NUS message to smart phone. Error 0x%x. ", err_code);
						APP_ERROR_CHECK(err_code);
					}
				} while (err_code == NRF_ERROR_BUSY);
		}

    	}
		
    }

}

3. Bellow is debug message.

<info> app: Dbg: BLE_NUS_C_EVT_NUS_TX_EVT.
<debug> app: Receiving data.
<debug> app: FF FF A1 46 00 19 |;..
<error> app: Failed sending NUS message. Error 0x4.
<error> app: ERROR 4 [NRF_ERROR_NO_MEM] at ..\..\..\main.c:496
PC at: 0x00028777
<error> app: End of error report

4. How did I enlarge the RAM size?

Thanks a lot 

  • I did not have any debug message.

    SDH:DEBUG:sd_ble_enable: RAM start a""

  • Hi,

    I suspect the NO_MEM error is coming from link context manager and not related to the RAM base address. Can you check the return code from blcm_link_ctx_get() in ble_nus_data_send() to confirm? In that case you will have to increase the link count in your BLE_NUS_DEF() macro.

  • Hi,

    Yes, I have get the return code from blcm_link_ctx_get(), that is 0x04 error code.

    1. I try to increase the link code form 3 to 6, or from 3 to 4.

    It make an other problem, when I enable BLE stack.

    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Register a handler for BLE events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    }
    

    show below debug message.

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at ..\..\..\main.c:1196
    PC at: 0x00028F43
    <error> app: End of error report

    2. How do I enable the RAM debug message?

    "SDH:DEBUG:sd_ble_enable: RAM start a"

  • Hi,

    Could you  upload your project here so I can try to debug it here? The RAM debug message should be printed out by default. 

  • Hi,

    Thanks for your helping.

     I have solve the problem when ble_nus_data_send() occur NRF_ERROR_NO_MEM, which I have enable the log and print out when stack enable software device.

    Q1. How may link count I should use, current link count is set 6.

    #ifndef NRF_SDH_BLE_TOTAL_LINK_COUNT
    //#define NRF_SDH_BLE_TOTAL_LINK_COUNT 1
    #define NRF_SDH_BLE_TOTAL_LINK_COUNT 6
    //#define NRF_SDH_BLE_TOTAL_LINK_COUNT 3
    #endif

    Q2. Is that depend on my application SPEC, the MAX is 20 ?

Related