<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application</link><description>hello Nordic 
 i am working with nre52840 and nrf52832, with ncs v2.8.0 
 i am using ble SMP service for transferring data with a central device and for DFU. 
 currently i am using this config CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE in my prj.conf so i can</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 27 Aug 2025 15:29:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application" /><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/546962?ContentTypeID=1</link><pubDate>Wed, 27 Aug 2025 15:29:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a43417e4-aaf5-4f63-a906-7e09c0fdcd2e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure I understand what approach you took for your solution, especially when you mention having to make changes to the network buffer (are you referring to the actual network buffer implementation)? In any case, if you want to make a contribution, it would better to explain your proposal to the code owners to get their feedback:&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/contribute/guidelines.html#pull-requests-and-issues"&gt;https://docs.zephyrproject.org/latest/contribute/guidelines.html#pull-requests-and-issues&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/546947?ContentTypeID=1</link><pubDate>Wed, 27 Aug 2025 13:40:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:beeb462b-e9fd-435d-93c4-44d7630cb0d6</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;well i did manage to make it work by making some changes in the trasfer/smp.c and in the net buf&amp;nbsp;&lt;/p&gt;
&lt;p&gt;i was thinking of contribution but i think the following is a bit of an issue&amp;nbsp;&lt;/p&gt;
&lt;p&gt;i manage to path a pointer from my own pool to replace the static net buff.. but in that way the user might give wrong buff size (not NETBUF_SIZE*NETBUF_COUNT) .. another option is that the user will give an&amp;nbsp;function pointer (according to zephyr required api, like in a callbacks) and then zephyr pools the correct size and it informs the user of the size (though user can check how much is left on his pool by his own) .. does the second approach looks nicer, is it zephyr valid in your view ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/542957?ContentTypeID=1</link><pubDate>Mon, 21 Jul 2025 07:30:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39c6c129-6c04-4921-9e1a-28295fd5998c</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/542302?ContentTypeID=1</link><pubDate>Sat, 12 Jul 2025 16:18:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afcbd824-1c38-4d25-94c8-07787012b2c4</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;Hi Vidar&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541930"]If you need to make changes to the SDK sources, you can also propose&amp;nbsp;your changes upstream in Zephyr by submitting a pull request. If accepted you would not have to maintain a patch for every new release. You may check&amp;nbsp;Zephyr&amp;#39;s contribution guidelines for more details about this process.[/quote]
&lt;p&gt;contribution is one option but what i think of at first is maybe wrap the smp module with my own implementation (we did something similar with spi ) but i wonder which internal mcumgr module should i wrap as my_smp.c and my_smp.h .. if you have any ideas i would love to read your thoughts&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541930"]If you were referring to a application defined network buffer (created with NET_BUF_POOL_DEFINE), then I think I understand what you meant by allowing the application to provide a buffer pointer.[/quote]
&lt;p&gt;what i meant is&amp;nbsp;a buffer i allocate in the app and then i give the net buf the pointer for this buf . is this possible using&amp;nbsp;NET_BUF_POOL_DEFINE macro&amp;nbsp; to achieve what i need ? .. and do i need to call it 4 times for each of the 4 buffers or give it a pointer for a buff of size = 4_buffer size )??&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541930"]&lt;p&gt;you may try with the following configuration and check if that gives you an acceptable upload speed.&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_L2CAP_TX_MTU=247&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_BUF_ACL_RX_SIZE=251&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=1220&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;on one of my central devices i only have ble 4.0/2 so mtu=251 will not work ..&lt;/p&gt;
&lt;p&gt;if i change my mcumgr net buf from 704 bytes to 2048 bytes i get between 20-40% increase in throughput (using fs_download we transfer 100kbytes-500kbytes , but we only receive small commands and upload rarely)..&amp;nbsp; so if i could set large buffer for tx and use the space on the expense of the rx buffers that could really help.&amp;nbsp;&amp;nbsp;i don&amp;#39;t think i&amp;#39;ll get the same affect even f i could enable the MTU= 251&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;hope to read you soon&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Ziv&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/541930?ContentTypeID=1</link><pubDate>Wed, 09 Jul 2025 11:44:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:139df19d-23be-45be-8a8f-56e8592b6ed5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;If you need to make changes to the SDK sources, you can also propose&amp;nbsp;your changes upstream in Zephyr by submitting a pull request. If accepted you would not have to maintain a patch for every new release. You may check&amp;nbsp;Zephyr&amp;#39;s contribution guidelines for more details about this process.&amp;nbsp;&lt;/p&gt;
[quote userid="90084" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application"]free for other uses of the app (i manage it with my own heap pool).[/quote]
&lt;p&gt;I may have misunderstood what you meant by &amp;quot;heap&amp;quot; here. If you were referring to a application defined network buffer (created with NET_BUF_POOL_DEFINE), then I think I understand what you meant by allowing the application to provide a buffer pointer. However, I believe this solution would be quite specific to your requirements.&lt;/p&gt;
[quote userid="90084" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541799"]&lt;div&gt;&lt;span&gt;and last related question .. i found&amp;nbsp;out there are 4 buffers actually .. and i wonder of all of them have a footprint in memory at the same time (looks like that by ram size indication when i build) so..&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is there a way they can share the memory (cause incoming and out coming are usually not parallel operations i think (might be wrong) )?&lt;/span&gt;&lt;/div&gt;[/quote]
&lt;p&gt;Yes, it&amp;#39;s 4x by default.&amp;nbsp;&lt;/p&gt;
[quote userid="90084" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541799"]why is it better in your view ?, what risks or problem you see in the alternative ?[/quote]
&lt;p&gt;I don&amp;#39;t see any risks, but as with many other modules in Zephyr, mcumgr initialization is handled outside of the application before reaching main(). If you were using other shared memory, such as the system heap, you could keep this separation. Whether that&amp;rsquo;s a good solution I&amp;rsquo;m not sure.&lt;/p&gt;
&lt;p&gt;I would rather try to optimize the buffer configuration. For example, you may try with the following configuration and check if that gives you an acceptable upload speed.&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_L2CAP_TX_MTU=247&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_BUF_ACL_RX_SIZE=251&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=1220&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/541799?ContentTypeID=1</link><pubDate>Tue, 08 Jul 2025 12:33:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc769cd8-736e-405e-958d-63dcf93d9bdb</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;Hey&amp;nbsp;&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541766"]If you want these file(s) to use system heap, etc, you need to modify the implementation to use k_malloc/k_free and provide new configuration symbols to select whether you want to use dynamic or static allocation[/quote]
&lt;p&gt;i don&amp;#39;t want to change ncs internally cause we are trying to stay align with updated versions and this is not a wise practice i think&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;did you see my lat question (i edit it while you where answering):&lt;/p&gt;
&lt;div&gt;&lt;span&gt;and last related question .. i found&amp;nbsp;out there are 4 buffers actually .. and i wonder of all of them have a footprint in memory at the same time (looks like that by ram size indication when i build) so..&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is there a way they can share the memory (cause incoming and out coming are usually not parallel operations i think (might be wrong) )?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;also, since my incoming messages are usually small commands and my out messages are actual data is it possible to give different size for incoming and out coming?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;or maybe there is a way to give larger buffs only in case of fs_download etc. ?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;[quote userid="4240" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541766"]I believe the buffer management should remain decoupled from the application.[/quote]&lt;span&gt;why is it better in your view ?, what risks or problem you see in the alternative ?&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/541766?ContentTypeID=1</link><pubDate>Tue, 08 Jul 2025 09:42:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af7bc235-1ddd-4093-91b3-84c48e32c4b0</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Ziv,&lt;/p&gt;
&lt;p&gt;You can search&amp;nbsp;through the source files in the SDK tree for&amp;nbsp;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE to see where this symbol is used. If you want these file(s) to use system heap, etc, you need to modify the implementation to use k_malloc/k_free and provide new configuration symbols to select whether you want to use dynamic or static allocation.&lt;/span&gt;&lt;/p&gt;
[quote user="ziv123"] attempted to use that&amp;nbsp;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_BT_DYNAMIC_SVC_REGISTRATION=y&lt;/span&gt;[/quote]
&lt;p&gt;As I said in my previous response, this option enables you to&amp;nbsp;add/remove the SMP service from the attribute table at runtime. I don&amp;#39;t see how it is relevant to what you are trying to do.&lt;/p&gt;
[quote user="ziv123"]i am a bit confused by terminology you used here, as i understand the buffers&amp;nbsp;size i give here&amp;nbsp;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE has a footprint in memory through all the application run and are not just allocated when smp is used .. else this ram would probably be free for use when ble is off no ?&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;The buffer allocated at build time and not freed after use, like a regular static variable.&lt;/p&gt;
[quote user="ziv123"]&lt;div&gt;&lt;span&gt;is there a plane to add to the smp service api an option to give the buffers as pointers from the app layer ?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;it seems kind of wastefull to hold that much memory when it may be used only 50% of app runtime&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;hope to read you soon&lt;/span&gt;&lt;/div&gt;[/quote]
&lt;p&gt;I believe the buffer management should remain decoupled from the application.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/541756?ContentTypeID=1</link><pubDate>Tue, 08 Jul 2025 09:15:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dcf88c3-2f1f-413f-9c29-74bfca2c8bd6</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;Hey Vidar&lt;/p&gt;
&lt;p&gt;i attempted to use that&amp;nbsp;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_BT_DYNAMIC_SVC_REGISTRATION=y&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;with that&amp;nbsp;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;NET_BUF_POOL_HEAP_DEFINE&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;smp_pool&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;SMP_BUF_COUNT&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;SMP_BUF_SIZE&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;NULL&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and try register and unregister to smp each time i connect and disconect but it seems that if i set&amp;nbsp;&lt;/span&gt;CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=0&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;then i have a problem with fs_download -&amp;gt; this&amp;nbsp;&lt;/span&gt;&lt;/span&gt;CONFIG_MCUMGR_GRP_FS_DL_CHUNK_SIZE is not defined&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;[quote userid="4240" url="~/f/nordic-q-a/122791/how-to-allocate-the-mcumgr-buffers-dynamically-from-within-the-application/541712"]use statically allocated memory [/quote]&lt;/div&gt;
&lt;div&gt;i am a bit confused by terminology you used here, as i understand the buffers&amp;nbsp;size i give here&amp;nbsp;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE has a footprint in memory through all the application run and are not just allocated when smp is used .. else this ram would probably be free for use when ble is off no ?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is there a plane to add to the smp service api an option to give the buffers as pointers from the app layer ?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;it seems kind of wasteful to hold that much memory when it may be used only 50% of app runtime&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;and last related question .. i found&amp;nbsp;out there are 4 buffers actually .. and i wonder of all of them have a footprint in memory at the same time (looks like that by ram size indication when i build) so.. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is there a way they can share the memory (cause incoming and out coming are usually not parallel operations i think (might be wrong) )?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;also, since my incoming messages are usually small commands and my out messages are actual data is it possible to give different size for incoming and out coming?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;hope to read you soon&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;best regards&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Ziv&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to allocate the MCUmgr buffers dynamically from within the application</title><link>https://devzone.nordicsemi.com/thread/541712?ContentTypeID=1</link><pubDate>Tue, 08 Jul 2025 06:42:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55b59843-8eff-4a02-a42b-d1435e581504</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t want to use statically allocated memory for the mcumgr transport, you would need to modify the implementation itself. There is no configuration option to disable the use of the statically allocated memory pool. The&amp;nbsp;&lt;span&gt;CONFIG_MCUMGR_TRANSPORT_BT_DYNAMIC_SVC_REGISTRATION config symbol is not relevant for this. It can be enabled if you want&amp;nbsp;the ability to dynamically add/remove the SMP service in your attribute table at runtime and will likely increase the memory usage.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vidar&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>