Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ERROR 4 [NRF_ERROR_ON_MRN]

Dear Nordic engineers

        I encountered a problem while debugging NRF5_SDK 17.0.2.

        I added BAS and IBS services to the “ble_app_uart” program, and everything went smoothly.But when I tried to port the function of bms, there was a problem.

        The ”service_init()“ initialization failed. I printed the process of each service initialization via RTT. It was found that the BMS service failed to initialize. The return code of err_code printed by RTT is "4". I checked related information, ERROR 4 means [NRF_ERROR_NO_MEM]. So I modified the value of NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE and changed it from the default 1408 to 4000. However, this modification does not seem to take effect, and the BMS initialization process will still return an ERROR 4 code. Please help me analyze, why is this?

       Below is my service_init() code

        

static void services_init(void)
{
uint32_t err_code;
ble_dis_init_t dis_init;
nrf_ble_bms_init_t bms_init;
ble_nus_init_t nus_init;
ble_lbs_init_t lbs_init;
ble_bas_init_t bas_init;
nrf_ble_qwr_init_t qwr_init = {0};

// Initialize Queued Write Module.
qwr_init.error_handler = nrf_qwr_error_handler;

err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
if(err_code != NRF_SUCCESS)
{
NRF_LOG_INFO("QWR service loading err_code %x",err_code);
APP_ERROR_CHECK(err_code);
}


// Initialize Bond Management Service
memset(&bms_init, 0, sizeof(bms_init));

m_bms_bonds_to_delete = ble_conn_state_user_flag_acquire();
bms_init.evt_handler = bms_evt_handler;
//bms_init.error_handler = service_error_handler;
#if USE_AUTHORIZATION_CODE
bms_init.feature.delete_requesting_auth = true;
bms_init.feature.delete_all_auth = true;
bms_init.feature.delete_all_but_requesting_auth = true;
#else
bms_init.feature.delete_requesting = true;
bms_init.feature.delete_all = true;
bms_init.feature.delete_all_but_requesting = true;
#endif
bms_init.bms_feature_sec_req = SEC_JUST_WORKS;
bms_init.bms_ctrlpt_sec_req = SEC_JUST_WORKS;

bms_init.p_qwr = &m_qwr;
bms_init.bond_callbacks.delete_requesting = delete_requesting_bond;
bms_init.bond_callbacks.delete_all = delete_all_bonds;
bms_init.bond_callbacks.delete_all_except_requesting = delete_all_except_requesting_bond;

err_code = nrf_ble_bms_init(&m_bms, &bms_init);
if(err_code != NRF_SUCCESS)
{
NRF_LOG_INFO("BMS service Initialization fail err_code:%x",err_code);
APP_ERROR_CHECK(err_code);
}

// Initialize Battery Service.
memset(&bas_init, 0, sizeof(bas_init));

bas_init.evt_handler = NULL;
bas_init.support_notification = true;
bas_init.p_report_ref = NULL;
bas_init.initial_batt_level = 100;

// Here the sec level for the Battery Service can be changed/increased.
bas_init.bl_rd_sec = SEC_OPEN;
bas_init.bl_cccd_wr_sec = SEC_OPEN;
bas_init.bl_report_rd_sec = SEC_OPEN;

err_code = ble_bas_init(&m_bas, &bas_init);
if(err_code != NRF_SUCCESS)
{
NRF_LOG_INFO("BAS service Initialization fail err_code:%x",err_code);
APP_ERROR_CHECK(err_code);
}

// Initialize LBS.
memset(&m_lbs, 0, sizeof(m_lbs));

lbs_init.led_write_handler = led_write_handler;

err_code = ble_lbs_init(&m_lbs, &lbs_init);
if(err_code != NRF_SUCCESS)
{
NRF_LOG_INFO("LBS service Initialization fail err_code:%x",err_code);
APP_ERROR_CHECK(err_code);
}

// Initialize NUS.
memset(&nus_init, 0, sizeof(nus_init));

nus_init.data_handler = nus_data_handler;

err_code = ble_nus_init(&m_nus, &nus_init);
if(err_code != NRF_SUCCESS)
{
NRF_LOG_INFO("NUS service Initialization fail err_code:%x",err_code);
APP_ERROR_CHECK(err_code);
}


// Initialize Device Information Service.
memset(&dis_init, 0, sizeof(dis_init));

ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);

dis_init.dis_char_rd_sec = SEC_OPEN;

err_code = ble_dis_init(&dis_init);
if(err_code != NRF_SUCCESS)
{
NRF_LOG_INFO("DIS service Initialization fail err_code:%x",err_code);
APP_ERROR_CHECK(err_code);
}
}

Parents
  • Hello,

    Which function specifically returned the NRF_ERROR_NO_MEM?

    If you make sure to have DEBUG defined in your preprocessor defines like shown in the included image, the logger will output a detailed error message whenever a non-NRF_SUCCESS error is passed to an APP_ERROR_CHECK.


    Please do this and let me know what function returned the error, so we may look into the API to see why it failed.

    Best regards,
    Karl

  • Hi Karl

         As shown below, the program returns ERROR when executing “nrf_ble_bms_init()”. I turned on RTT here, and the print here is "BMS service Initialization fail err_code: 4"

    err_code = nrf_ble_bms_init(&m_bms, &bms_init);
    if(err_code != NRF_SUCCESS)
    {
    NRF_LOG_INFO("BMS service Initialization fail err_code:%x",err_code);
    APP_ERROR_CHECK(err_code);
    }

  • Hello,

    Hannibalhz said:
    the program returns ERROR when executing “nrf_ble_bms_init()”. I turned on RTT here, and the print here is "BMS service Initialization fail err_code: 4"

    Thank you for elaborating.

    If you have DEBUG defined, you will get the error and function that returned the error in plain text in the logger.
    The nrf_ble_bms_init function will return the error code from nrf_ble_qwr_attr_register if the nrf_ble_bms_init_t parameter's p_qwr field is non-NULL. This function may return NRF_ERROR_NO_MEM if it lacks the memory to register the new attribute.

    I see that you are only providing your qwr module with a error handler upon initialization. You will need to provide it with a callback and memory buffer as well. Please see the Queued writes example application for a demonstration on how to initialize and use the qwr module.
    Please do this, and see if it resolves your issue.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

Reply Children
No Data
Related