2024-03-15 06:06 AM - edited 2024-03-15 06:15 AM
Hi,
For our embedded Zigbee wireless application, we want to use the ST Zigbee stack.
Per design, we want to avoid the use of dynamic memory allication. Per default, the ST Zigbee stack internally seems to use malloc for memory allocation.
The ST application note AN5500 describes a way to let the application provide its own preallocated memory using the function ZbMemConfig(). However, this functions seems not to exist.
- Has anyone managed to use the Zigbee stack with pre-allocated memory and prevent the stack from using malloc?
- Is there an example provided by ST?
Thanks in advance!
Lukas
2024-03-25 06:55 AM
Hi Lukas,
Thanks to have pointed us that AN5500 contains a reference to non existing ZbMemConfig(). It does not exist (anymore?) indeed.
- Has anyone managed to use the Zigbee stack with pre-allocated memory and prevent the stack from using malloc?
I don't think so. Malloc used by the zigbee stack is taking a subset of the Heap memory, that might be increased with a parameter tblsizes defined in ZbInit().
For particular "big network applications", the size of the Heap taken by the M0 can be increased (using ZbInit). And the size of the Heap itself can be increased.
With those mechanisms in place, the target is to let customers a clear vision of the memory that they can use and never to worried about the internal M0 alloc.
Cdlt, Pascal
2024-03-25 10:13 AM
Bonjour Pascal,
Many thanks for your reply.
I don't think so. Malloc used by the zigbee stack is taking a subset of the Heap memory, that might be increased with a parameter tblsizes defined in ZbInit().
I am not sure if I understand; From the code documentation of ZbInit() and ZbInitTblSizesT, it seems possible to pass a pointer to a memory region which could be statically allocated by the user application. With this, the stack would not need to allocate memory on the heap. In the mean time we have tested this in our application. We see that the stack doesn't perform any mallocs during ZbInit() if a pointer to pre-allocated memory is passed.
Unfortunately it seems that there is no possibility to completely prevent the stack from using malloc. Functions like ZbStartup(), ZbZclClusterAlloc() internally use it. As a consequence, a malloc-free implementation which is best practice for embedded applications seems not possible.
For particular "big network applications", the size of the Heap taken by the M0 can be increased (using ZbInit). And the size of the Heap itself can be increased.
Yes, I assume you are referring to the struct fields nwkNeighborTblSz, nwkRouteTblSz, etc.. Increasing those, will require more heap.
With those mechanisms in place, the target is to let customers a clear vision of the memory that they can use and never to worried about the internal M0 alloc.
Customers need to worry about alloc, as they must make sure that there is enough heap available. How can developers determine, which heap size is required for their application?
Thanks for your support.
BR
Lukas
2024-03-25 11:19 AM
Hi Lucas,
Perfectly agree with this:
>Unfortunately it seems that there is no possibility to completely prevent the stack from using malloc. Functions like ZbStartup(), ZbZclClusterAlloc() internally use it. As a consequence, a malloc-free implementation which is best practice for embedded applications seems not possible
And about this:
>Customers need to worry about alloc, as they must make sure that there is enough heap available. How can developers determine, which heap size is required for their application?
I will check if we have a formula but I don't think all parameters are taken into account. Saying differently, the formula will take some average assumptions, and depending on the application, it might need more margin.
(What is the size of your network? How many router? how many Sleepy End Device? What topology is it supposed to be? )
Cdlt, Pascal
NOTE: Are you asking this because of some observed failures? If you are getting some failures, in which conditions are you getting failures? Or is it only a sanity check question?
2024-03-26 09:49 AM
Hi Pascal,
Thanks for following up.
I will check if we have a formula but I don't think all parameters are taken into account. Saying differently, the formula will take some average assumptions, and depending on the application, it might need more margin.
(What is the size of your network? How many router? how many Sleepy End Device? What topology is it supposed to be? )
A formula is a good starting point for sure. In addition it would be helpful if the stack provides a high watermark of heap used at runtime. The usage could then be assessed in stress tests.
Is such a feature available?
We expect a rather simple network topology with probably just one router and few end devices.
NOTE: Are you asking this because of some observed failures? If you are getting some failures, in which conditions are you getting failures? Or is it only a sanity check question?
No, we didn't experience any issues so far. Though the project is in early development phase.
BR
Lukas