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

Getting memory error when using s130 on sdk 11

I am trying to implement 128 bit uuid service and charachteristic and I am getting error 4(memory error) from 

line 10: sd_ble_uuid_vs_add(&m_midi_service, &midi_init);

static void services_init(void)
{
    uint32_t       err_code;
    ble_nus_init_t nus_init;
	ble_midi_service_init_t midi_init;
	
	memset(&midi_init, 0, sizeof(midi_init));
    midi_init.data_io_write_handler = data_io_write_handler;
    
    err_code = ble_midi_service_init(&m_midi_service, &midi_init);
    APP_ERROR_CHECK(err_code);
    
    memset(&nus_init, 0, sizeof(nus_init));
    nus_init.data_handler = nus_data_handler;
    
    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);
}

this is the midi_service code that i am using:

static uint32_t data_io_char_add(ble_midi_service_t * p_midi_service, const ble_midi_service_init_t * p_midi_service_init)
{
    uint32_t   err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;

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

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    
    memset(&char_md, 0, sizeof(char_md));
    
    char_md.char_props.read          = 1;
    char_md.char_props.write_wo_resp = 1;
    char_md.char_props.notify        = 1;
    char_md.p_char_user_desc         = NULL;
    char_md.p_char_pf                = NULL;
    char_md.p_user_desc_md           = NULL;
    char_md.p_cccd_md                = &cccd_md;
    char_md.p_sccd_md                = NULL;
    
    // Add the MIDI Data I/O Characteristic UUID
    ble_uuid128_t base_uuid = BLE_UUID_MIDI_DATA_IO_CHAR_BASE_UUID;
    err_code = sd_ble_uuid_vs_add(&base_uuid, &p_midi_service->uuid_type);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    ble_uuid.type = p_midi_service->uuid_type;
    ble_uuid.uuid = BLE_UUID_MIDI_DATA_IO_CHAR_UUID;
    
    memset(&attr_md, 0, sizeof(attr_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;
    
    memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = sizeof(uint8_t);
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = sizeof(uint8_t);
    attr_char_value.p_value      = NULL;
    
    return sd_ble_gatts_characteristic_add(p_midi_service->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_midi_service->data_io_char_handles);
}

uint32_t ble_midi_service_init(ble_midi_service_t * p_midi_service, const ble_midi_service_init_t * p_midi_service_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize service structure
    p_midi_service->conn_handle       = BLE_CONN_HANDLE_INVALID;
    p_midi_service->data_io_write_handler = p_midi_service_init->data_io_write_handler;
    
    // Add service
    ble_uuid128_t base_uuid = BLE_UUID_MIDI_SERVICE_BASE_UUID;
    err_code = sd_ble_uuid_vs_add(&base_uuid, &p_midi_service->uuid_type);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    ble_uuid.type = p_midi_service->uuid_type;
    ble_uuid.uuid = BLE_UUID_MIDI_SERVICE_UUID;

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_midi_service->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    err_code = data_io_char_add(p_midi_service, p_midi_service_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    return NRF_SUCCESS;
}

this is the header code:

#define BLE_UUID_MIDI_SERVICE_BASE_UUID  {{0x00, 0xC7, 0xC4, 0x4E, 0xE3, 0x6C, 0x51, 0xA7, 0x33, 0x4B, 0xE8, 0xED, 0x5A, 0x0E, 0xB8, 0x03}}
#define BLE_UUID_MIDI_SERVICE_UUID        0x0E5A
    
#define BLE_UUID_MIDI_DATA_IO_CHAR_BASE_UUID {{0xF3, 0x6B, 0x10, 0x9D, 0x66, 0xF2, 0xA9, 0xA1, 0x12, 0x41, 0x68, 0x38, 0xDB, 0xE5, 0x72, 0x77}}
#define BLE_UUID_MIDI_DATA_IO_CHAR_UUID       0xE5DB
    
// Forward declaration of the custom_service_t type. 
typedef struct ble_midi_service_s ble_midi_service_t;

typedef void (*ble_midi_data_io_write_handler_t) (ble_midi_service_t * p_midi_service, uint8_t new_state);

typedef struct
{
    ble_midi_data_io_write_handler_t data_io_write_handler;  /**< Event handler to be called when MIDI Data I/O characteristic is written. */
} ble_midi_service_init_t;

/**@brief MIDI Service structure. This contains various status information for the service. */
typedef struct ble_midi_service_s
{
    uint16_t                    service_handle;
    ble_gatts_char_handles_t    data_io_char_handles;
    uint8_t                     uuid_type;
    uint16_t                    conn_handle;
    ble_midi_data_io_write_handler_t data_io_write_handler;
} ble_midi_service_t;

(of course i include all neccery headers and declare all neccery functions..)

I was googling out the error and find an answare thats modified sdk_config.h file but I don't have it..

I have a file called softdevice_handler.c but I don't understand how to modify it for my needs..

Related