<?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>Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18746/printing-stack-and-heap-pointers</link><description>Hi everyone, 
 I am facing memory leak issues while using nrf52 iot SDK for MQTT. The application has a high RAM usage and I am running into memory leakage issue where program starts behaving abnormally after running for few times. Could anyone please</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Jan 2017 12:23:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18746/printing-stack-and-heap-pointers" /><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72383?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 12:23:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1c22dbe-e6ce-4e94-b34e-1cca9e5f8002</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Yes, that is Keil specific, so just ignore it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72382?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 12:22:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4f80af2-a328-4e4f-a0e2-5b4b52edb4b1</guid><dc:creator>Jawad</dc:creator><description>&lt;p&gt;Thanks Bjorn,&lt;/p&gt;
&lt;p&gt;Regarding your comment that &amp;quot;Use MircroLib under &amp;quot;Options for Target&amp;quot;. Is it something related to Keil? I am using Eclipse and can&amp;#39;t find it.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72386?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 11:34:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78d44f01-220d-4acc-919e-b1ee71b4975d</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;You could look into the __heapstats function, see &lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0099a/armlib_cihhgjad.htm"&gt;this&lt;/a&gt; link. Just make sure that you include stdlib.h and uncheck Use MircroLib under &amp;quot;Options for Target&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72385?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 10:40:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c77d65-fd4a-4fd9-aa55-8c4aaeb738bc</guid><dc:creator>Jawad</dc:creator><description>&lt;p&gt;Thanks RK,&lt;/p&gt;
&lt;p&gt;I am using nrf52 IoT SDK implementation for MQTT with following malloc&lt;/p&gt;
&lt;p&gt;void * nrf_malloc(uint32_t size){&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t * buffer = NULL;
uint32_t allocated_size = size;

uint32_t retval = nrf_mem_reserve(&amp;amp;buffer, &amp;amp;allocated_size);

if (retval != NRF_SUCCESS)
{
    buffer = NULL;
}

return buffer;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72384?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 10:36:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59b507fd-f723-4ad6-a737-7beec3ef2225</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;There&amp;#39;s a CMSIS defined function __get_PSP() which should get the stack pointer for any supported compiler, it uses the MRS instruction to do it.&lt;/p&gt;
&lt;p&gt;The heap pointer however, that depends entirely on what malloc implementation you&amp;#39;re using.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72381?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 10:15:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9764b67-f12f-4bc2-8162-1bd382aa224e</guid><dc:creator>Jawad</dc:creator><description>&lt;p&gt;Hi Bjorn,&lt;/p&gt;
&lt;p&gt;Thanks for the comment. I was not using heap before but now for the nrf52 implementation for mqtt I need to use the calloc and malloc functions for which I need heap. That&amp;#39;s why I want to print heap pointer.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Printing Stack and Heap pointers</title><link>https://devzone.nordicsemi.com/thread/72380?ContentTypeID=1</link><pubDate>Wed, 04 Jan 2017 10:09:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cf9d406-e86c-43d8-87f2-34708978ef85</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Jawad,&lt;/p&gt;
&lt;p&gt;a quick-and-dirty way of obtaining the value of the stack pointer is to push a variable to the stack and then print the address of said variable, i.e.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void print_stack_pointer() 
{
  uint32_t * ptr = NULL;
  NRF_LOG_INFO(&amp;quot;%p \n&amp;quot;, (uint32_t)&amp;amp;ptr);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am not sure if you can use the same approach to get the current heap pointer , but I thought that you were&amp;#39;nt using the heap since this is related to &lt;a href="https://devzone.nordicsemi.com/question/109071/mqtt-stops-responding-after-fixed-number-of-subscribe-and-publish/"&gt;this&lt;/a&gt; and &lt;a href="https://devzone.nordicsemi.com/question/108030/region-ram-overflowed-with-stack-error-while-using-tls/"&gt;this&lt;/a&gt; question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>