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

Finding the amount of RAM needed by adding characteristics and services -> Setting NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE does not work

Hello,

At the moment we are at a point to decide, if we want to expose our loads of data in “parallel” over BLE characteristics or if we should better implement a serial BLE service, which allows to transmit the desired data via serial packets. For App development, other departments wished to get the desired data over separate characteristics. Knowing that more RAM overhead will cause more current consumption in standby, I started investigating in this.

To find out how much RAM the system needs as overhead for one characteristic value of 16 bytes, I wanted to implement some characteristics and measure the amount of RAM needed by the application (compiler shows amount of used RAM). As basis project, I use https://github.com/bjornspockeli/custom_ble_service_example

By doing so, I recognized that the Softdevice creates the parameters/metadata and attribute value in the system stack which is shared by application and Softdevice. But in this area, I cannot see how much RAM is used.

So I tried to set the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE to 4, 8, 16, … to get the system messaging me NRF_ERROR_NO_MEM and iterating the TAB_SIZE until the error message disapears to find the amount of used RAM memory. But I do never get any error message and the system works – all services and characteristics are visible. I have a 16-byte attribute value. Also stored in STACK RAM. So 16 bytes as TAB_SIZE shall be too small at all.

 

Q1: Why does it work?

 

Q2: What can I do to set the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE to another value?

Thank you,

Regards
Andre

Parents
  • Hi Andre, 

    It appears that I was wrong regarding the GATT table size. 

    Q1: The SoftDevice requires a minimum GATT attribute table size of 248, so if the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE is set to a value lower than this then the sd_ble_cfg_set function used to set the table size will return the following error message in the log output

    <error> nrf_sdh_ble: sd_ble_cfg_set() returned NRF_ERROR_INVALID_LENGTH when attempting to set BLE_GATTS_CFG_ATTR_TAB_SIZE.

    See the code snippet below from nrf_sdh_ble_default_cfg_set() in nrf_sdh_ble.c, which is called from ble_stack_init() in main.c.

     // Configure the GATTS attribute table.
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    ble_cfg.gatts_cfg.attr_tab_size.attr_tab_size = 4;//NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE;
    
    ret_code = sd_ble_cfg_set(BLE_GATTS_CFG_ATTR_TAB_SIZE, &ble_cfg, *p_ram_start);
    if (ret_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_GATTS_CFG_ATTR_TAB_SIZE.",
                      nrf_strerror_get(ret_code));
    }

    So the error will not cause the application to assert, it simply prints the return code and since the GATT table size is not set it is by default set to 248. The SD will use some of this memory to place the GATT and the GAP service and their characteristics/descriptors, but it will not use all the space. Hence, you will still be able to add additional services, characteristics and descriptors until you reach the end of the 248 bytes. 

    Q2: The minimum value you can set NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE to is 248. Keep adding services, characteristics and descriptors until the functions that add them return the NRF_ERROR_NO_MEM error code. If this occurs you gradually increase the size until you do not get the errors. If you've added all the necessary services, characteristics and descriptors and do not get the NRF_ERROR_NO_MEM error code, then you can leave the size to its minimum value. 

    Best regards

    Bjørn

Reply
  • Hi Andre, 

    It appears that I was wrong regarding the GATT table size. 

    Q1: The SoftDevice requires a minimum GATT attribute table size of 248, so if the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE is set to a value lower than this then the sd_ble_cfg_set function used to set the table size will return the following error message in the log output

    <error> nrf_sdh_ble: sd_ble_cfg_set() returned NRF_ERROR_INVALID_LENGTH when attempting to set BLE_GATTS_CFG_ATTR_TAB_SIZE.

    See the code snippet below from nrf_sdh_ble_default_cfg_set() in nrf_sdh_ble.c, which is called from ble_stack_init() in main.c.

     // Configure the GATTS attribute table.
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    ble_cfg.gatts_cfg.attr_tab_size.attr_tab_size = 4;//NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE;
    
    ret_code = sd_ble_cfg_set(BLE_GATTS_CFG_ATTR_TAB_SIZE, &ble_cfg, *p_ram_start);
    if (ret_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_GATTS_CFG_ATTR_TAB_SIZE.",
                      nrf_strerror_get(ret_code));
    }

    So the error will not cause the application to assert, it simply prints the return code and since the GATT table size is not set it is by default set to 248. The SD will use some of this memory to place the GATT and the GAP service and their characteristics/descriptors, but it will not use all the space. Hence, you will still be able to add additional services, characteristics and descriptors until you reach the end of the 248 bytes. 

    Q2: The minimum value you can set NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE to is 248. Keep adding services, characteristics and descriptors until the functions that add them return the NRF_ERROR_NO_MEM error code. If this occurs you gradually increase the size until you do not get the errors. If you've added all the necessary services, characteristics and descriptors and do not get the NRF_ERROR_NO_MEM error code, then you can leave the size to its minimum value. 

    Best regards

    Bjørn

Children
No Data
Related