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

NRF_ERROR_NO_MEM error while adding a Service to Nordic_BLE_Template example in nrf52840

#define BLE_UUID_OUR_SERVICE 0xABCD // Just a random, but recognizable value

typedef struct { uint16_t service_handle; /**< Handle of Our Service (as provided by the BLE stack). */ }ble_os_t;

ble_os_t ourService;

static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}}; /**< Universally unique service identifiers. */

static void advertising_init(void) { ret_code_t err_code; ble_advdata_t advdata; ble_adv_modes_config_t options;

memset(&advdata, 0, sizeof(advdata));

advdata.name_type               = BLE_ADVDATA_NO_NAME;
advdata.include_appearance      = false;
advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
advdata.uuids_complete.p_uuids  = m_adv_uuids;

memset(&options, 0, sizeof(options));
options.ble_adv_fast_enabled  = true;
options.ble_adv_fast_interval = APP_ADV_INTERVAL;
options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);

}

static void services_init(void) {

memset(&ourService, 0, sizeof(ourService));

ble_uuid_t        service_uuid;
ble_uuid128_t     base_uuid = BLE_UUID_OUR_BASE_UUID;
service_uuid.uuid = BLE_UUID_OUR_SERVICE;
service_uuid.type = BLE_UUID_TYPE_BLE;


err_code = sd_ble_gatts_service_add\			//The program is stuck inside a while loop in app_error_save_and_stop() function with errorID=4(NRF_ERROR_NO_MEM)
	(BLE_GATTS_SRVC_TYPE_PRIMARY,\
		&service_uuid,\
		&(ourService.service_handle));
APP_ERROR_CHECK(err_code);

}

Related