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

Data length extension causes NRF_ERROR_NO_MEM on services init

Using SDK 14.0.0 with an nRF52832, I'm trying to use the data length extension, following some sample code found in this post:

https://devzone.nordicsemi.com/f/nordic-q-a/24840/using-dle-and-nrf_ble_gatt_max_mtu_size-23

Here's how I init the BLE stack.

static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings. Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

    // Overwrite some of the default configurations for the BLE stack.
    ble_cfg_t ble_cfg;
    memset(&ble_cfg, 0, sizeof(ble_cfg));

	// Vendor-specific UUIDs. Count these in services_init() below.
    ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = 3;

    // Maximum transmission unit. 
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_SDH_BLE_GATT_MAX_MTU_SIZE;

    // Data length extension.
    ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;

    uint8_t data_length = NRF_SDH_BLE_GATT_MAX_MTU_SIZE + L2CAP_HDR_LEN;
    err_code = nrf_ble_gatt_data_length_set(&m_gatt, BLE_CONN_HANDLE_INVALID, data_length);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_cfg_set(BLE_COMMON_CFG_VS_UUID, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

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

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);

    // Connection event length extension. Must be done *after* BLE is enabled.
    ble_opt_t opt;
    memset(&opt, 0x00, sizeof(opt));
    opt.common_opt.conn_evt_ext.enable = 1;
    err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
    APP_ERROR_CHECK(err_code);
}

This causes NRF_ERROR_NO_MEM at the point where I init the third of four services (three of which are vendor specific) in my application. My linker script looks like this.

MEMORY
{
  FLASH (rx) : ORIGIN = 0x23000, LENGTH = 0x2F000

  RAM (rwx) :  ORIGIN = 0x20002760, LENGTH = 0xB4A0

  NOINIT (rwx) :  ORIGIN = 0x2000DC00, LENGTH = 0x2400
}

I'm using the exact RAM start and size that the warnings I get at runtime ask for.

Removing the data length extension stuff fixes the NRF_ERROR_NO_MEM error (and produces new warnings about RAM size).

Parents Reply Children
Related