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

Setting a custom 128 bit UUID. err_code = 4

I am using the experimental_app_hrs_nfc_pairing_pca10040_s132 nrf52 example.

I want to set my custom uuid and I have followed the instructions given in the devzone.nordicsemi.com/.../ tutorial.

github.com/.../nrf51-ble-tutorial-service

But I am getting an err_code 4 from the service _init function that adds the 128-bit service uuid.

I realized that it was because no memory was being allocated to the Custom uuid in the ble_stack_init given below.

static void ble_stack_init(void)
{
    ret_code_t err_code;
  
    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;

    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);

    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = softdevice_app_ram_start_get(&ram_start);
    APP_ERROR_CHECK(err_code);

    // Overwrite some of the default configurations for the BLE stack.
    ble_cfg_t ble_cfg;

    // Configure the number of custom UUIDS.
    memset(&ble_cfg, 0, sizeof(ble_cfg));
    ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = 0;
 
    err_code = sd_ble_cfg_set(BLE_COMMON_CFG_VS_UUID, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

    // Configure the maximum number of connections.
    memset(&ble_cfg, 0, sizeof(ble_cfg));
    ble_cfg.gap_cfg.role_count_cfg.periph_role_count  = BLE_GAP_ROLE_COUNT_PERIPH_DEFAULT;
    ble_cfg.gap_cfg.role_count_cfg.central_role_count = 0;
    ble_cfg.gap_cfg.role_count_cfg.central_sec_count  = 0;
    err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = softdevice_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    
    
}

So in the code below, I changed the lines

ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = 1;

But i am getting an err_code 4 here

   err_code = softdevice_enable(&ram_start);
   APP_ERROR_CHECK(err_code);

My RAM memory address is 0x20001fc0 to 0x2000ffff.

Is there any way to resolve this issue ??

  • Hello Ramkumar

    When you increase the UUID count you need to adjust your ram settings. Error 4 returned by softdevice_enable corresponds to the NRF_ERROR_NO_MEM error. This error is generated by the sd_ble_enable function which is called within softdevice_enable.

    The easiest way of finding the correct RAM settings is by using a terminal such as putty to read the logs supplied by the chip. First make the changes you need to your code (setting the UUID count to what you need), build and load. If the RAM settings are different from the optimal settings the logs displayed in putty will tell you what the RAM start and size should be set to. Then simply change the RAM settings in the target options.

    Best regards

    Jørn Frøysa

Related