<?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>Get call stack problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55497/get-call-stack-problem</link><description>Hi,master: 
 platform:nrf52840 
 IDE:keil compiler version 5 
 tool chain: armcc 
 There are multiple calls to a function in the product. I suspect that there is a problem with this function in some cases. When a condition is met in this function, I add</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 13 Dec 2019 17:36:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55497/get-call-stack-problem" /><item><title>RE: Get call stack problem</title><link>https://devzone.nordicsemi.com/thread/225459?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 17:36:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59f817c2-4257-4e86-b2b6-f5d384125171</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;You&amp;#39;re welcome. As a follow up for SES users (don&amp;#39;t have Keil)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; // GET_SP() in compiler_abstraction.h; __get_MSP() in cmsis_gcc.h
 NRF_LOG_INFO(&amp;quot;nRF52832 SP 0x%08X, MSP 0x%08X, &amp;quot;, GET_SP(), __get_MSP());
and   
 NRF_LOG_INFO(&amp;quot;nRF52832 SP 0x%08X, LR 0x%08X, PC 0x%08X, &amp;quot;, get_sp(), get_lr(), __get_PSP());

assuming:
static inline uint32_t get_sp(void)
{
    register uint32_t spRegister __ASM(&amp;quot;sp&amp;quot;);
    return spRegister;
}

static inline uint32_t get_lr(void)
{
    register uint32_t lrRegister __ASM(&amp;quot;lr&amp;quot;);
    return lrRegister;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Produces from main.c:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;lt;info&amp;gt; app: nRF52832 SP 0x2000FFE0, MSP 0x2000FFE0,&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;and from a called function in the latter case:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;lt;info&amp;gt; app: nRF52832 SP 0x2000FFA8, LR 0x00031631, PC 0x00000000, &lt;br /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get call stack problem</title><link>https://devzone.nordicsemi.com/thread/225338?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 11:45:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74105849-7dd3-4ee2-ba4c-53de3a20b278</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;You can try looking up where the function is located with arm-none-eabi-addr2line, and with the LR value and .axf file as input (.axf is generated when you compile the Keil project)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arm-none-eabi-addr2line -e nrf52832_xxaa.axf 0x00001A61&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You will then get the name of the .c file and line-number.&lt;/p&gt;
&lt;p&gt;e.g.&amp;nbsp;..\..\..\..\..\..\components\libraries\queue\/nrf_queue.c:451&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get call stack problem</title><link>https://devzone.nordicsemi.com/thread/225270?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 02:49:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3b28b3b-6573-4154-9194-97f90b52a507</guid><dc:creator>outspace</dc:creator><description>&lt;p&gt;Hi,&lt;span class="user-name"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/hmolesworth"&gt;hmolesworth&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;Thank you for your answer,Others gave me the answer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get call stack problem</title><link>https://devzone.nordicsemi.com/thread/225269?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 02:47:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d93da764-53d0-468b-8781-9162c3bccbc8</guid><dc:creator>outspace</dc:creator><description>&lt;p&gt;Hi,&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/sigurdon"&gt;Sigurd&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thank you very much for sharing. This is the answer I want. In addition, I would like to ask, is there any way to know the calling method of a function through code implementation in software? Similar to keil&amp;#39;s call stack.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/_5563B783_.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get call stack problem</title><link>https://devzone.nordicsemi.com/thread/225238?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 17:38:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05b67f2e-e974-4e08-b2ff-64d34970583e</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Not sure if it helps, but you can use cmsis_gcc.h to get info&amp;nbsp;&amp;nbsp;&lt;em&gt;__get_PSP()&lt;/em&gt; and&amp;nbsp;&lt;em&gt;__get_MSP()&lt;/em&gt; for process and main stack pointers, plus other stuff.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get call stack problem</title><link>https://devzone.nordicsemi.com/thread/225224?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 16:19:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b1210c0-d0f7-4ca3-b9f1-1cbc3e2746dd</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;With Keil you can do something like this to get the LR,PC and SP:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	unsigned int spReg, lrReg, pcReg;
    __asm
    {
        MOV spReg, __current_sp()
        MOV pcReg, __current_pc()
        MOV lrReg, __return_address()
    }
    NRF_LOG_INFO(&amp;quot;SP = 0x%X\n&amp;quot;,spReg);
    NRF_LOG_INFO(&amp;quot;PC = 0x%X\n&amp;quot;,pcReg);
    NRF_LOG_INFO(&amp;quot;LR = 0x%X\n&amp;quot;,lrReg);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Another approach, is to add a extra&amp;nbsp;context variable in the function call.&lt;/p&gt;
&lt;p&gt;Pseudo code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#DEFINE FOO_FUCNTION 0x4242

func(var_1,var2,context)
{
    NRF_LOG_INFO(func caller: %d,context)
}


foo
{
     func(1,2,FOO_FUCNTION)

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>