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);
}
}