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

Device reset when calling sd_ble_uuid_vs_add second time

I am using nRF5_SDK_11.0.0-2.alpha_bc3f6a0 with PCA10040 and GCC. I am working on the ble hrs with DFU example. I have modify the hrs to my custom service with a 128bit service UUID. I have call sd_ble_uuid_vs_add 2 times, first one is for my custom service init and the second one is in ble_dfu_init. On the second time, it will return NRF_ERROR_NO_MEM and cause the device reset. If I do not include the DFU service or do not include my custom service, it will working fine. Is there any solution for that?

image description

ble_hrs.c

ble_hrs.h

  • After changing the ram setting, I able to set the attr_tab_size to 0x900 and pass the softdevice_enable. When I calling sd_ble_gatts_characteristic_add with BLE_GATTS_VLOC_USER. I got error 7 NRF_ERROR_INVALID_PARAM. Is there some more configuration require?

  • NRF_ERROR_INVALID_PARAM - Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.

    No,you have supplied sd_ble_gatts_characteristic_addwith invalid parameters. Could you share the code where you add the characteristic?

  • service init will call at main...

    static void services_init(void) { uint32_t err_code; ble_nms_init_t nms_init; ble_bas_init_t bas_init; ble_dis_init_t dis_init;

    // Initialize Heart Rate Service.
    memset(&nms_init, 0, sizeof(nms_init));
    nms_init.evt_handler                 = NULL;
    
    // Here the sec level for the Heart Rate Service can be changed/increased.
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&nms_init.nms_charging_attr_md.cccd_write_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&nms_init.nms_charging_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&nms_init.nms_charging_attr_md.write_perm);
    
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&nms_init.nms_motorCtrl_attr_md.cccd_write_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&nms_init.nms_motorCtrl_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&nms_init.nms_motorCtrl_attr_md.write_perm);
    
    err_code = ble_nms_init(&m_nms, &nms_init);
    APP_ERROR_CHECK(err_code);
    

    in ble_nms_init ...

    uint32_t ble_nms_init(ble_nms_t * p_nms, const ble_nms_init_t * p_nms_init) { uint32_t err_code; ble_uuid_t ble_uuid; const ble_uuid128_t base_uuid128 = BLE_UUID_NMS_BASE;

    // Initialize service structure
    p_nms->evt_handler                 = p_nms_init->evt_handler;
    p_nms->conn_handle                 = BLE_CONN_HANDLE_INVALID;
    
    // Add service
    

    // BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_SERVICE); ble_uuid.uuid = BLE_UUID_NMS_SERVICE; sd_ble_uuid_vs_add(&base_uuid128, &(ble_uuid.type));

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                        &ble_uuid,
                                        &p_nms->service_handle);
    
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    p_nms->uuid_type = ble_uuid.type;
    
    // Add heart rate measurement characteristic
    err_code = charging_char_add(p_nms, p_nms_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    

    in charging_char_add...

    static uint32_t charging_char_add(ble_nms_t * p_nms, const ble_nms_init_t * p_nms_init) { 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);
    cccd_md.write_perm = p_nms_init->nms_charging_attr_md.cccd_write_perm;
    cccd_md.vloc = BLE_GATTS_VLOC_USER;
    
    memset(&char_md, 0, sizeof(char_md));
    
    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;
    

    // BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_MEASUREMENT_CHAR); ble_uuid.type = p_nms->uuid_type; ble_uuid.uuid = BLE_UUID_CHARGING_CHAR;

    memset(&attr_md, 0, sizeof(attr_md));
    
    attr_md.read_perm  = p_nms_init->nms_charging_attr_md.read_perm;
    attr_md.write_perm = p_nms_init->nms_charging_attr_md.write_perm;
    attr_md.vloc       = BLE_GATTS_VLOC_USER;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 1;
    
    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   = 0;
    
    return sd_ble_gatts_characteristic_add(p_nms->service_handle,
                                           &char_md,
                                           &attr_char_value,
                                           &p_nms->charging_handles);
    

    }

    if I use BLE_GATTS_VLOC_USER I got error 7 when calling sd_ble_gatts_characteristic_add, no error for BLE_GATTS_VLOC_STACK

  • You can only place the value of the characteristic in user memory. You are trying to place the CCCD in user memory;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    cccd_md.write_perm = p_nms_init->nms_charging_attr_md.cccd_write_perm;
    cccd_md.vloc = BLE_GATTS_VLOC_USER;
    

    which is not allowed. You have to set it tocccd_md.vloc = BLE_GATTS_VLOC_STACK. This is also explained in this thread

  • I have created a new project of ble_app_hrs_with_dfu using the original nRF5_SDK_11.0.0-2.alpha_bc3f6a0 zip file package. I have only modified the hrs UUID to a 128bit UUID and attached the modified file in post above. I have added comment to the part which is modified. It works fine without the enable of the DFU service which can show in the attached picture in above post. When I enable the DFU service, I will cause error and return NRF_ERROR_NO_MEM when calling sd_ble_uuid_vs_add. I hope it can help for analysis the problem.

Related