This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How do I set UUIDs for advertisements, services, and characteristics?

Hello.

I'm using nrf52832 (S132 v7.0.1, SDK v17.0.0) to develop peripheral roles.

Setting UUIDs for advertisements, services, and characteristics. At that time, sd_ble_uuid_vs_add and characteristic_add are used a lot, and RAM will be insufficient.
Will you be able to reduce RAM consumption? Below is the current code and specifications.

UUID specifications
Advertisement, service, and characteristic UUIDs should all be different.
Create 18 characteristics. (3 in the code)

// UUID Setting
#define ADV_UUID_BASE     {0x77, 0x77, 0x66, 0x66, 0x55, 0x55, 0x44, 0x44, 0x33, 0x33, 0x22, 0x22, 0x11, 0x11, 0x00, 0x00}
#define SERVICE_UUID_BASE {0xHH, 0xHH, 0xGG, 0xGG, 0xFF, 0xFF, 0xEE, 0xEE, 0xDD, 0xDD, 0xCC, 0xCC, 0xBB, 0xBB, 0xAA, 0xAA}
#define CHAR1_UUID_BASE   {0xS1, 0xSS, 0xTT, 0xTT, 0xUU, 0xUU, 0xVV, 0xVV, 0xWW, 0xWW, 0xXX, 0xXX, 0xYY, 0xYY, 0xZZ, 0xZZ}
#define CHAR2_UUID_BASE   {0xS2, 0xSS, 0xTT, 0xTT, 0xUU, 0xUU, 0xVV, 0xVV, 0xWW, 0xWW, 0xXX, 0xXX, 0xYY, 0xYY, 0xZZ, 0xZZ}
#define CHAR3_UUID_BASE   {0xS1, 0xSS, 0xTT, 0xTT, 0xUU, 0xUU, 0xVV, 0xVV, 0xWW, 0xWW, 0xXX, 0xXX, 0xYY, 0xYY, 0xZZ, 0xZZ}

#define BLE_UUID_CHAR_MAX 3

// UUID Base
static ble_uuid128_t ble_char_uuid_base[BLE_UUID_CHAR_MAX] = 
{
    CHAR1_UUID_BASE,
    CHAR2_UUID_BASE,
    CHAR3_UUID_BASE,
};

// Characteristic params
static ble_add_char_params_t add_char_params = 
{
    .uuid            = 0xYYYY,
    .uuid_type       = NULL,
    .max_len         = 248,
    .init_len        = 248,
    .is_var_len      = false,
    .char_props.read = 1,
    .read_access     = SEC_OPEN,
};

static uint16_t                 m_service_handle;   /**< Handle of local service (as provided by the BLE stack).*/
static ble_gatts_char_handles_t m_char_handles;     /**< Handles of local characteristic (as provided by the BLE stack).*/

// set the UUID here.
static void uuid_init(void)
{
    ret_code_t    err_code;
    ble_uuid_t    adv_uuid;
    ble_uuid_t    service_uuid;
    ble_uuid_t    char_uuid;
    ble_uuid128_t adv_uuid_base = {ADV_UUID_BASE};
    ble_uuid128_t service_uuid_base = {SERVICE_UUID_BASE};

    // advertise setting
    err_code = sd_ble_uuid_vs_add(&adv_uuid_base, &adv_uuid.type);
    APP_ERROR_CHECK(err_code);

    // service setting
    err_code = sd_ble_uuid_vs_add(&service_uuid_base, &service_uuid.type);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &m_service_handle);
    APP_ERROR_CHECK(err_code);

    // characteristic setting
    for (uint8_t i = 0; i <= BLE_UUID_CHAR_MAX; i++) {
        err_code = sd_ble_uuid_vs_add(&ble_char_uuid_base[i], &char_uuid.type);
        APP_ERROR_CHECK(err_code);

        add_char_params.uuid_type = char_uuid.type;
        err_code = characteristic_add(m_service_handle, &add_char_params, &m_char_handles);
        APP_ERROR_CHECK(err_code);
    }

    return;
}

Happy Holidays!

  • Hi Kei, 

    There is a limited amount of RAM dedicated for the ATT table. Meaning you can't get over a limited number for vendor specific UUIDs. 

    The solution is to avoid creating multiple base UUIDs. If you want to have different UUID for each of your characteristic you can use the same base and only change the 2 bytes UUID when you declare the characteristic (add_char_params.uuid ). Please refer to the UART service that we provided in the SDK. Note how the TX and RX characteristic share the same base and only has 2 bytes different. 

    Another option is to avoid having too many characteristic and group them together and use an Opcode byte to differentiate them. 

  • Hello.

    When I proceeded with the creation with the current code, the following error occurred in the debugger.

    Error[Lp011]: section placement failed  unable to allocate space for sections/blocks with a total estimated minimum size of 0x5bd4 bytes (max align 0x8) in <[0x2000'a648-0x2000'ffff]> (total uncommitted space 0x59b8).
     
    Error[Lp021]: the destination for compressed initializer batch "P2-1" is placed at an address that is dependent on the size of the batch, which is not allowed when using lz77 compression.  
    Consider using "initialize by copy with packing = zeros" (or none) instead. 


    Thank you for the solution.
    Use it to avoid running out of RAM.

    Best Regards.

Related