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

SD: Characteristics Per Service Limit

Is there a limit to the number of characteristics per (custom) service?

After some testing, it looks like 20 is the maximum (21 causes the device to stop functioning) - is this corrrect and is it documented somewhere?

Thanks :)

  • The way this works is that there is a static 1.5 kB of memory allocated for the GATT table internally in the softdevice. These can be used for any combination of services, characteristics and descriptors, so there isn't a specific limit as such. Each attribute that is in the attribute table consumes of this memory block, both with its size and some overhead per attribute.

    There is currently no way to increase these 1.5 kB. The only thing you can do is to change characteristics from VLOC_STACK to VLOC_USER. This will move the actual characteristic value out of these 1.5 kB and into the application's RAM space, and hence allow you to add more characteristics. Please note that the effect of doing such move is biggest for characteristics with large values.

    If you try to add more that what there is room for, you will get an error code back, which will normally make your application end up in app_error_handler on top of main.c. This will by default do a reset, but if you uncomment the debug assert handler, it will instead hang in a loop allowing you to inspect where things failed and with what error code.

    Edit: Changed size to the correct 1.5 kB, and changed some parts for clarity.

  • Actually, in terms of my attributes, 72 bytes out of a total of 94 bytes is actually being stored in flash memory using the VLOC_USER option. So really, only 22 bytes of attributes is being stored on the SD stack.

    This led me to me believe that the limit is based on the number of characteristics and not the amount of stack data they consume...

    Combining nine 2-byte characteristics into a single characteristic of 18-bytes stopped the crashing which further supports this assumption.

    However, I also understand that there is overhead in addition to the attribute data for each characteristic (in reference to your final sentence).

    So, how large is the overhead (in bytes) for each characteristic (i.e. stack required not including attribute data)?

    Thanks.

  • I've checked this again, and I found out that I was wrong about the exact size of this table, but correct apart from that. There isn't any particular limit of the number of characteristics.

    When you combine characteristics, there will be fewer attributes in the table, giving less overhead, which is perfectly reasonable considering the way things work. I unfortunately don't have an exact number for the overhead per attribute.

    I've edited my answer below slightly for clarity.

  • I guess there is still no option to increase the size of the GATT table? This limit is causing some inconveniences for our project at the moment. Would be a awesome if you could include that in your next update or at least increase the size to let's say 3KB.

  • What soft device is this for? Is this information current? Is that same limitation on the S130 SD 2.0.0?

Related