<?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>No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91797/no-heap-space-for-incoming-notifications</link><description>We have an application running on an nRF9160 development board (shortly to be ported to a production board), which listens on a serial link for sensor data, which is then sent via udp/dtls, via NB-IoT. 
 The development board is connected to a serial</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Sep 2022 17:52:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91797/no-heap-space-for-incoming-notifications" /><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388632?ContentTypeID=1</link><pubDate>Thu, 29 Sep 2022 17:52:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ccc6e14-1b29-4c39-aea6-318349183396</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Running for more than 12 hours now with no warning messages. Clearly the problem is solved.&lt;/p&gt;
&lt;p&gt;Am including code here in case it helps others.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define TRANSMISSION_STACK_SIZE 1024
#define TRANSMISSION_PRIORITY 5

K_THREAD_STACK_DEFINE(transmission_stack_area, TRANSMISSION_STACK_SIZE); // define memory for application workqueue

struct k_work_q transmission_work_q; // application workqueue

static struct k_work server_transmission_work; // A work Q element - infinite loop that receives, parses and acts on message events

...


k_work_queue_init(&amp;amp;transmission_work_q); // intialise workqueue

// start workqueue
k_work_queue_start(&amp;amp;transmission_work_q, transmission_stack_area,
                   K_THREAD_STACK_SIZEOF(transmission_stack_area), TRANSMISSION_PRIORITY,
                   NULL);

k_work_init(&amp;amp;server_transmission_work, server_transmission_work_fn);  // initialise worker task - points to function that does the work

// k_work_submit(&amp;amp;server_transmission_work);  // uses system workqueue
k_work_submit_to_queue(&amp;amp;transmission_work_q, &amp;amp;server_transmission_work); // worker task uses application workqueue
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Initially when the stack size of the workqueue was set to 512 the device panicked. At 1024 it is running perfectly.&lt;/p&gt;
&lt;p&gt;Thanks again. Cheer Ron.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388455?ContentTypeID=1</link><pubDate>Thu, 29 Sep 2022 05:44:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b48b8212-da70-4837-8bb8-a5730a67516f</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;Great news!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388452?ContentTypeID=1</link><pubDate>Thu, 29 Sep 2022 05:10:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f5a1b65-fe80-4444-9199-f1767f8ee1d2</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;In the end, it was as you indicated Achim, ridiculously simple, in about 4 lines of code, to create&amp;nbsp;another workqueue thread and assign the work task to that with no other changes. Since doing that a few hours ago&amp;nbsp;the application has been almost continuously running&amp;nbsp;with no warnings. Will see what happens overnight, then all being well close this question&amp;nbsp; .. again! Cheers Ron.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388006?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 20:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42f984c6-f9b5-4c6d-8e1d-119ee24dcf33</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;That polling causes energy consumption, a wait not.&lt;/p&gt;
&lt;p&gt;But, yes, check a short polling interval and we will see, if that helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388005?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 20:14:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f1de052-0291-40e2-889d-a7f69252ec8b</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Can&amp;#39;t see a downside to polling in this case as nothing else needs to be done in user land and it isn&amp;#39;t possible to miss a message.&amp;nbsp; However, I may try using a different thread at least to accumulate more practical experience with Zephyr. Anyway, thanks, this has been really helpful. Will report back later on results. Cheers Ron.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388003?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 20:02:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e5ddb8a-772c-41d1-8d59-14803fc57331</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;A short timeout in &lt;span&gt;k_msgq_get&lt;/span&gt; will be a polling. Maybe working.&lt;/p&gt;
&lt;p&gt;There is also some more sophisticated function (e.g. Events).&lt;/p&gt;
&lt;p&gt;A thread is not that complicated and changing that job into a thread should not take too long.&lt;/p&gt;
&lt;p&gt;Anyway, it&amp;#39;s you to decide.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388002?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 19:49:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fe76831-152d-4c60-a164-c7ced45cdff9</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Thanks, was aware that the system queue thread isn&amp;#39;t to be blocked for any significant length of time.&amp;nbsp; I&amp;#39;d assumed that a&amp;nbsp;&lt;span&gt;k_msgq_get would implement an automatic yield but maybe this is wrong.&amp;nbsp; Apart from using a different thread, another solution&amp;nbsp;might be to create an &amp;#39;automatic yield&amp;#39; by waiting on the message queue with a k_msqq_get with a short timeout period (rather than waiting forever), then&amp;nbsp;call yield, then loop back to k_msqq_get&amp;nbsp;and so on,&amp;nbsp;only exiting the loop when a message is received. Will perhaps try that simple change anyway, see what happens.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388001?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 19:33:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe770077-46f8-46e3-8bfa-eb45d44749a5</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;I&amp;#39;m mainly a java developer, so I&amp;#39;m not that used to zephyr.&lt;/p&gt;
&lt;p&gt;As far as I understand zephyr and the idea of a job-queue, it&amp;#39;s no good practice to wait in such a job.&lt;/p&gt;
&lt;p&gt;But you may wait in you main-thread, or you may use an own thread, which then is able to wait.&amp;nbsp; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/388000?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 19:25:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:696cc15e-2bec-4072-a735-50ee2f479ba5</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Hi Achim,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;server_transmission_worker_init();  // initialise the udp worker
	baseuart_connect_async(baseuart); // Also creates dma buffer storage
	//## Kick off main transmission worker here
 	k_work_submit(&amp;amp;server_transmission_work);  // uses system workthread&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yes, in main() a system workqueue worker task to transmit/receive data over dtls/NB-IoT is initialised, a uart connection to another mcu is also initialised, then the system workqueue transmission worker task is started. This waits on&amp;nbsp;&lt;span&gt;k_msgq_get for messages that are created on the queue by bytes coming across the uart link by&amp;nbsp;the (simple) uart&amp;nbsp;dma interrupt routine that marshals the bytes into a message pushed onto the message queue. Those messages are then sent via dtls/NB-IoT to a dtls2mqtt gateway with responses being sent back across the uart link.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Am quite open to modifying this design if there is a better approach, or if it is preferable that the work is done in an application workqueue rather than the system one.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/387998?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 18:42:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f5a29af-8f4f-4ac1-9c70-1022976b373e</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;The system work queue is a job queue. A job is added with k_work_submit as in at_monitor.c,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; k_work_submit(&amp;amp;at_monitor_work);&lt;/p&gt;
&lt;p&gt;What is suspicious is the&lt;/p&gt;
&lt;p&gt;static void server_transmission_work_fn(struct k_work *work)&lt;/p&gt;
&lt;p&gt;in your snippet. Because that&amp;#39;s usually a function assigned to such a job. e.g.&lt;/p&gt;
&lt;p&gt;static K_WORK_DEFINE(server_transmission_work, server_transmission_work_fn);&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; k_work_submit(&amp;amp;server_transmission_work);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/387996?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 18:26:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9da454cf-4128-4d84-920d-68b67610b291</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Thanks for the reply, appreciate your picking this up.&lt;/p&gt;
&lt;p&gt;Apart from the work task waiting for messages to arrive in a message queue:&lt;/p&gt;
&lt;p&gt;k_msgq_get(&amp;amp;receive_event_msq, &amp;amp;rxevt, K_FOREVER);&lt;/p&gt;
&lt;p&gt;There are no other tasks that have been started by me to run on the system work queue.&lt;/p&gt;
&lt;p&gt;New to Zephyr, I&amp;#39;ve been assuming that waiting on a k_msqq_get would automatically yield to allow other tasks on the system work queue to run.&amp;nbsp; Is that incorrect?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/387985?ContentTypeID=1</link><pubDate>Mon, 26 Sep 2022 16:06:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:135a9df3-58c5-4e66-bf26-7333fc9a63ac</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;are you using the system workqueue in your application? It&amp;#39;s possible that the system workqueue is running tasks that are blocking the at monitor from running so the at notification fifo won&amp;#39;t clear out. Have you checked this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/386257?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2022 18:51:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc86c63f-a745-4ee3-ae1d-108b65c867ad</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Ok, understood Achim. Thanks for your efforts in trying to track the problem down.&amp;nbsp; Will report back if I do eventually discover a root cause.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/386147?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2022 11:27:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42e086b7-56d4-49bc-9f4a-e38c686c04c1</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;Seems to be complicated and irritating. From my side, I have no idea left.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/386087?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2022 06:36:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:972c5499-d321-4080-986f-ebfc9f4fd259</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Thanks Achim,&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have just made all the printk statements conditional, which should have been done anyway to switch them off for a release version.&lt;/p&gt;
&lt;p&gt;Thought it had resolved the issue but another heap space warning just popped up!&lt;/p&gt;
&lt;p&gt;Print statement also don&amp;#39;t explain the out of heap warning messages generated overnight when there was no input/output character activity, with the worker function blocked waiting for input.&amp;nbsp; Or why increasing the heap significantly did not solve the problem anyway, which tends to indicate that the heap somehow isn&amp;#39;t being entirely garbage collected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The warning is annoying but otherwise appears to be benign,&amp;nbsp;though there could be bad side effects over time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/386029?ContentTypeID=1</link><pubDate>Tue, 13 Sep 2022 14:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7ab7cac-527f-4ba2-9b52-9d0ffdbc06fa</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;Hi Ron,&lt;/p&gt;
&lt;p&gt;my understanding of &amp;quot;at_monitor&amp;quot; is:&lt;/p&gt;
&lt;p&gt;- it reads some notification and queues them for later processing (at_monitor_dispatch)&lt;/p&gt;
&lt;p&gt;- based on the messages in the queue, it calls the registered callbacks (at_monitor_task)&lt;/p&gt;
&lt;p&gt;If these callbacks take too long, then &amp;quot;at_monitor_dispatch&amp;quot; will run out-of-heap.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know, how long your callback takes, I would start to add some time-measurement to see, if there are cases, where it takes longer and then start to analyze them.&lt;/p&gt;
&lt;p&gt;From analyzing the source code (if the snippet is that code in the callback), I see all the &amp;quot;printk&amp;quot; (at least 7-9 I would put in #ifdef and disable them). And there is a second queue. If that is also too full, then that pushs back the waits. The comment above &amp;quot;k_msgq_purge&amp;quot; indicates, that it should not be an issue (and dropping messages is really OK), but maybe calling &amp;quot;k_msgq_purge&amp;quot; takes longer as expected.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385813?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 19:01:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f831b48-72db-43e0-8447-700fa7d22c23</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Hi Achim.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Anyway, after the additional warning messages were received over night, sending characters to the application now generates this slightly different warning:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;W: No heap space for incoming notification: +CEREG: 1,&amp;quot;C920&amp;quot;,&amp;quot;000E9166&amp;quot;,9,,,&amp;quot;00000000&amp;quot;,&amp;quot;00000110&amp;quot;&lt;/p&gt;
&lt;p&gt;then on a couple more character sends:&lt;/p&gt;
&lt;p&gt;W: No heap space for incoming notification: +CSCON: 0&lt;/p&gt;
&lt;p&gt;W: No heap space for incoming notification: +CEREG: 1,&amp;quot;C920&amp;quot;,&amp;quot;000E9166&amp;quot;,9,,,&amp;quot;000&lt;/p&gt;
&lt;p&gt;Terminal disconnected itself.&lt;/p&gt;
&lt;p&gt;Then again after reconnecting the terminal, printing after every incoming uart message and at intervals thereafter&lt;/p&gt;
&lt;p&gt;W: No heap space for incoming notification: +CSCON: 0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385812?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 18:47:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7aa78771-236b-42d0-a05c-16fc1c709890</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Hello again Achim. Pity but I spoke too soon about increasing monitoring heap size being the solution, as this morning there were 3 more of the same warnings waiting. It&amp;#39;s pretty clear that these warnings are happening whilst the worker function is blocked on the message queue read indicated above, where it is waiting for messages to be generated as a result of characters arriving over the uart that is linked to an external mcu.&amp;nbsp; Although increasing the heap size has significantly reduced the frequency of their appearance, it does seem like some sort of memory leak is occurring after all.&lt;/p&gt;
&lt;p&gt;Messages are pushed onto the message queue in the uart callback function as follows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;case UART_RX_RDY:
		printk(&amp;quot;Received data %d bytes\r\n&amp;quot;, evt-&amp;gt;data.rx.len);
		rxevt.length = evt-&amp;gt;data.rx.len;
		//** Copy data from dma rx buffer to message queue buffer
		memcpy(rxevt.data, &amp;amp;evt-&amp;gt;data.rx.buf[evt-&amp;gt;data.rx.offset], evt-&amp;gt;data.rx.len); // copy received bytes to message queue
		
		printk(&amp;quot;rxevt data is: &amp;quot;);
		for (int i = 0; i &amp;lt; rxevt.length; i++) printk(&amp;quot;%02X&amp;quot;,rxevt.data[i]);
		printk(&amp;quot; length: %lu\r\n&amp;quot;,rxevt.length);

		//** push base uart received buffer on message queue
		while (k_msgq_put(&amp;amp;receive_event_msq, &amp;amp;rxevt, K_NO_WAIT) != 0)  {
            //** message queue is full: purge old data &amp;amp; try again 
            k_msgq_purge(&amp;amp;receive_event_msq);
        }

		//** Disabling the uart causes it to be enabled again below
		uart_rx_disable(baseuart);
		
		break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Nothing else is happening other than waiting for this case statement to be invoked as a result of characters arriving.&amp;nbsp; So maybe an under the hood issue after all?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385676?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 10:13:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d558f11d-f2b1-447f-816c-b84a7af389ac</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;You&amp;#39;re welcome.&lt;/p&gt;
&lt;p&gt;(It&amp;#39;s cool, just spend few moments for a hint, and let you do the time intensive tests :-) .)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385675?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 10:11:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d93f7de4-2761-45cd-963f-4efc4f5b4077</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Thanks for the detective work Achim, problem solved.&lt;/p&gt;
&lt;p&gt;After adding CONFIG_AT_MONITOR_HEAP_SIZE=1024 to prj.conf the warning message no longer appears.&amp;nbsp; Much appreciated.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385637?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 07:19:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d112ea2-ea61-4056-8c2c-8f62182154b9</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;I searched for &amp;quot;No heap space for incoming notification&amp;quot; and found it in &amp;quot;nrf/lib/at_monitor/at_monitor.c&amp;quot;. That at_monitor contains a Kconfig and that:&lt;/p&gt;
&lt;p&gt;config AT_MONITOR_HEAP_SIZE&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;int &amp;quot;Heap size for notifications&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;range 64 2048&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;default 256&lt;/p&gt;
&lt;p&gt;Interesting, how many different heaps are used.&lt;/p&gt;
&lt;p&gt;On a first look, at_monitor copies all received data and put that into a fifo, where a monitor tasks takes the data, calls the handler, and frees the data.&lt;/p&gt;
&lt;p&gt;I guess, depending on what you do in the handler callback, that may lead to a shortage in that heap.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385614?ContentTypeID=1</link><pubDate>Sun, 11 Sep 2022 22:09:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1862c815-c1b0-4dcc-8011-74a5379fa806</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;(Of course valgrind isn&amp;#39;t applicable, was still in Linux dev mode!).&lt;/p&gt;
&lt;p&gt;Have tried changing&amp;nbsp;&lt;span&gt;CONFIG_NRF_MODEM_LIB_HEAP_SIZE, so memory allocation in prj.conf is now:&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;# Heap and stacks&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_HEAP_MEM_POOL_SIZE&lt;/span&gt;&lt;span&gt;=16384&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MAIN_STACK_SIZE&lt;/span&gt;&lt;span&gt;=4096&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE&lt;/span&gt;&lt;span&gt;=4096&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_NRF_MODEM_LIB_HEAP_SIZE&lt;/span&gt;&lt;span&gt;=2048&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;No change.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;Have tried setting&amp;nbsp;&lt;/span&gt;&lt;/span&gt;CONFIG_LOG_MODE_DEFERRED to y and n in prj.conf
&lt;div&gt;
&lt;div&gt;&lt;span&gt;No change, apart from the warning being in bold with a timestamp when set to y&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;The application itself is very simple.&amp;nbsp; Just one system workqueue worker function running in a loop that waits for and reads messages from an application mcu from a uart via a short message queue, transmits them via dtls/NB-IoT, then&amp;nbsp;transmits replies via the uart back to the application mcu.&amp;nbsp; There are no mallocs in the application.&amp;nbsp;The message queue is created once in main as is the worker function.&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;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;The warning - W: No heap space for incoming notification: +CSCON: 0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Seems to occur during the wait for incoming uart messages, before any data to send arrives from the application mcu via the uart:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;k_msgq_get&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;receive_event_msq, &lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;rxevt, K_FOREVER);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;That queue is only 4 elements max, with each q element event buffer at 48 bytes.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;The entire worker function is reproduced below in case you can spot anything suspicious:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void server_transmission_work_fn(struct k_work *work)
{
	int err;
	struct receive_event rxevt; //** NB - receive_event struct data buffer is currently size 96 in sockets.h
	int received;
	uint8_t recv_buf[DOWNLINK_RCV_BUF_SIZE];

	for(;;) { // infinite loop

		printk(&amp;quot;\r\n&amp;gt;&amp;gt;&amp;gt; server_transmission_work_fn started &amp;lt;&amp;lt;&amp;lt;\r\n&amp;quot;);

		//** read message to transmit from the message queue
		//** NB - k_forever waits until a message arrives in the queue
		k_msgq_get(&amp;amp;receive_event_msq, &amp;amp;rxevt, K_FOREVER);
		
		printk(&amp;quot;Base board receive buffer to send is: %s\r\n&amp;quot;, rxevt.data);

		printk(&amp;quot;Transmitting UDP/IP payload of %d bytes to the &amp;quot;, rxevt.length + UDP_IP_HEADER_SIZE);
		printk(&amp;quot;IP address %s, port number %d\n&amp;quot;, CONFIG_UDP_SERVER_ADDRESS_STATIC, CONFIG_UDP_SERVER_PORT);
		printk(&amp;quot;Message buffer to send is: &amp;quot;);	
		for (int i = 0; i &amp;lt; rxevt.length; i++) printk(&amp;quot;%02X&amp;quot;,rxevt.data[i]);
		printk(&amp;quot;\r\n&amp;quot;);

		/*******************************************************************/

		//** NB - need to reconnect (create socket) for each transmission, disconnect after receive timeout
		//** or on error
		err = server_connect();
		if (err) {
			printk(&amp;quot;Not able to connect to UDP server\n&amp;quot;);
			goto exitloop;
		}
		else {
			printk(&amp;quot;Connected to UDP Server\r\n&amp;quot;);
		}

		/******************************************************************/

		// if (endndx &amp;gt; 0) { // endndx is the length of data to send - packet found if endndx &amp;gt; 0
		if (rxevt.length &amp;gt; 0) {
			// err = send(client_fd,&amp;amp;rxevt.data[startndx],endndx, 0);
			err = send(client_fd, rxevt.data, rxevt.length, 0);
			if (err &amp;lt; 0) {
				printk(&amp;quot;Failed to transmit UDP packet, %d\n&amp;quot;, errno);
				goto exitloop;
			}
			else {
				printk(&amp;quot;Packet transmitted\r\n&amp;quot;);
			}

			memset(recv_buf,0, sizeof(recv_buf));
			//** Receive udp return message
			received = recv(client_fd, recv_buf, sizeof(recv_buf), MSG_WAITALL); //NB - If MSG_DONTWAIT flag used recv returns err and no message

			if (received &amp;lt;= 0) {
				printk(&amp;quot;No udp reply\r\n&amp;quot;);
				//** Saved outgoing message should be resent up to n times
				//** By injecting into base uart receive message queue  
				if (sendretrycount &amp;lt; MAXSENDRETRIES) {
					//** push base uart received buffer back into message queue
					while (k_msgq_put(&amp;amp;receive_event_msq, &amp;amp;rxevt, K_NO_WAIT) != 0)  {
						//** message queue is full: purge old data &amp;amp; try again 
						k_msgq_purge(&amp;amp;receive_event_msq);
					}
					sendretrycount += 1; // increment retry count
				}
			}
			else {
				sendretrycount = 0;
				printf(&amp;quot;udp reply is: &amp;quot;);
				for (int i = 0; i &amp;lt; received; i++) printk(&amp;quot;%02X&amp;quot;,recv_buf[i]);
				printk(&amp;quot; length: %d\r\n&amp;quot;, received);

				//** Send receive message to base board via dma transmit
				uart_tx(baseuart,recv_buf, received, SYS_FOREVER_MS);	
			}
		}
		else {
			printk(&amp;quot;Failed to find valid packet in receive buffer\r\n&amp;quot;);
		}

	exitloop:
		// ** Disconnect udp socket - closes client_fd
		server_disconnect( );

	}// end infinite for(;;)

}
&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;Thanks again, Ron.&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385608?ContentTypeID=1</link><pubDate>Sun, 11 Sep 2022 09:03:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bac23ec-394e-469e-a1c3-b87ce4d6d5d0</guid><dc:creator>Ron Segal</dc:creator><description>&lt;p&gt;Wow, thanks ever so much for giving this some serious&amp;nbsp;consideration Achim.&amp;nbsp; A memory leak is of course&amp;nbsp;more than&amp;nbsp;likely, despite no obvious candidates&amp;nbsp;having walked through the code&amp;nbsp;many times. Also surprising in that case that is doesn&amp;#39;t eventually lead to a failure.&amp;nbsp; Or maybe it simply hasn&amp;#39;t run enough times yet. Will have a go with Valgrind, see if that throws up anything suspicious. Will check logging. Also, didn&amp;#39;t know about the modem heap size parameter, thanks for that, will try increasing it first opportunity then reply again later.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385603?ContentTypeID=1</link><pubDate>Sun, 11 Sep 2022 07:30:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:380a41eb-ea43-499d-a1d0-a4fc2fe293b4</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;There is also a CONFIG_NRF_MODEM_LIB_HEAP_SIZE, see nrf/lib/nrf_modem_lib/Kconfig.modemlib, read the docu there. Maybe that requires more than the 1k (range 512-4096).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No heap space for incoming notifications</title><link>https://devzone.nordicsemi.com/thread/385602?ContentTypeID=1</link><pubDate>Sun, 11 Sep 2022 06:53:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:216dfb98-6048-4090-b654-bba9ad618a02</guid><dc:creator>Achim Kraus</dc:creator><description>&lt;p&gt;One pitfall may be the logging. There are many modes and details. If the logging backend works deferred (CONFIG_LOG_MODE_DEFERRED), then sometimes parts of the passed parameters (&amp;quot;%s&amp;quot;) must be copied to the heap. if that happens &amp;quot;fast/excessive&amp;quot;, that may cause also some issues. But I&amp;#39;m not sure, if that uses the same heap as malloc or something else.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>