<?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>two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21680/two-seperate-call-stacks-with-msp-and-psp</link><description>Hello, 
 I intended to implement an application without OS. Due to safety concerns I would like to have two call stacks : one for softdevice using MSP and the other for my application using PSP. 
 Is there an example for how to do this ? 
 Regards</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Jun 2017 20:56:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21680/two-seperate-call-stacks-with-msp-and-psp" /><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85161?ContentTypeID=1</link><pubDate>Wed, 07 Jun 2017 20:56:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef5ccd23-6d35-4e8e-848a-23818041932a</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;I am intrigued by your goal of safety.  How is it safer to use two different stacks?  Do you use other memory protection for safety (since your two threads could still corrupt each others static memory)?  Have you considered using a &amp;quot;safer&amp;quot; language such as Rust?  I struggle myself with these issues (using C++, without using the SD).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85163?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 15:38:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93e3689a-1e7e-4f71-94de-4561ee35a9da</guid><dc:creator>telemedcar</dc:creator><description>&lt;p&gt;can you give me an example how to configure the linker for PSP and MSP stacks ? Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85165?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 13:01:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:504b6c20-1664-4c9e-a246-57837c5e431a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The processor is in Thread mode when it is reset (That is executing its reset handler).&lt;/p&gt;
&lt;p&gt;You can do the following&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;__set_CONTROL(__get_CONTROL | CONTROL_nPRIV_Msk );
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;you can initialize  PSP using  MSR command like below
Once you have selected in the Control register that you CONTROL-nPRIV = 1;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;msr   psp, r0\t\n&amp;quot; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The value you put in this psp should not conflict with your linker so make sure you configure your linker correctly.&lt;/p&gt;
&lt;p&gt;That is all you need to do for your application to use PSP when in Thread mode and the rest of the system will use MSP (assuming you are not using any RTOS, otherwise RTOS will redefine this for you).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85160?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 09:30:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01594516-17d3-44e0-96af-470df789480d</guid><dc:creator>telemedcar</dc:creator><description>&lt;p&gt;Thanks, RK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85167?ContentTypeID=1</link><pubDate>Mon, 08 May 2017 09:27:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a9f7dd1-ce89-4cba-9d84-033321e586d5</guid><dc:creator>telemedcar</dc:creator><description>&lt;p&gt;Thanks.
Do I have to define stack sections (one for MSP and the other one for PSP)  in arm_startup_nrf52.s ? How can I initialize the MSP and PSP there ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85166?ContentTypeID=1</link><pubDate>Sun, 07 May 2017 17:53:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77396056-c9f7-472c-8643-1d8465d993d2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Table 2.17 and exception return are in the second link of my reply.  They are  ARM core features,  that are done automatically when exception handlers run.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85164?ContentTypeID=1</link><pubDate>Fri, 05 May 2017 09:22:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bb1013e-6bdc-4c45-9104-db2102d3a4ec</guid><dc:creator>telemedcar</dc:creator><description>&lt;p&gt;What do mean by proper EXEC_RETURN ? Do I have to implement it myself ? where do I find the table 2.17, in SD or product specification ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85159?ContentTypeID=1</link><pubDate>Thu, 04 May 2017 22:01:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a19e4abb-aa52-4056-a67b-259626c89986</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;No the &amp;#39;S&amp;#39; on MOVS means it updates the flags, it says nothing about switching context.&lt;/p&gt;
&lt;p&gt;@telemedcar, I&amp;#39;ve never used it myself but it really should be no more than adding an extra section to the linker file, or whatever you&amp;#39;re using to generate sections, to be your process stack, and then edit the .s startup code to set both stack pointers, main to the main stack, process to the new sections and then set bit 1 in the CONTROL register which will move you to using PSP. I think that&amp;#39;s everything which is needed.&lt;/p&gt;
&lt;p&gt;Should be 5 lines of assembler in the reset handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85162?ContentTypeID=1</link><pubDate>Thu, 04 May 2017 09:01:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25abed64-f1e5-4c9b-af40-24b97c261e74</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi telemedcar, Like butch said, compiler takes care of this stuff and thinking about this is normally done by people implementing an Operating system. That said, it is quite simple to select stack pointer for an application. Exception handlers always use MSP. So if the application is making SVC call or for any application peripheral specific IRQs, only MSP will be used. For thread mode you can control which stack pointer to use by writing to &lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CHDBIBGJ.html"&gt;Control Register&lt;/a&gt;. If you initialize the control register quite early in your application, then when exception occur (softdevice always run in exception handlers) proper &lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/Babefdjc.html"&gt;EXEC_RETURN&lt;/a&gt; will be pushed to the stack to mark that when it returns to thread mode then it should pop stack pointer value to PSP . Look at table 2.17. One you have selected PSP in control register and initialized it proper value at the start of the application, then compilers and ARM core will handle the rest.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85158?ContentTypeID=1</link><pubDate>Thu, 27 Apr 2017 13:55:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d6e4484-634c-4f63-bb61-05f9585c1043</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;Unless you are writing the OS yourself, I don&amp;#39;t think you need to worry about it.  For example, in my projects using C and with only one main thread and interrupt handlers, I don&amp;#39;t worry about it.  The compiler takes care of it without my knowing.  I only know it happens because I can read the assembler code and see for example a MOVS instruction, where the &amp;quot;S&amp;quot; means it also switches context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85157?ContentTypeID=1</link><pubDate>Thu, 27 Apr 2017 13:41:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1edbd269-ea5f-479e-90ef-8142ce8f954f</guid><dc:creator>telemedcar</dc:creator><description>&lt;p&gt;I am not saying that MSP is unused. My intention is to leave MSP to SoftDevice and handlers (ISRs and Exception). My user application would use PSP only. I will look at the link. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: two seperate call stacks with MSP and PSP</title><link>https://devzone.nordicsemi.com/thread/85156?ContentTypeID=1</link><pubDate>Thu, 27 Apr 2017 12:08:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:381d9316-e7bf-4142-94b0-d1c97536a110</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;Respectfully, I think you would get more discussion in a forum of an ARM website.  Your question is about operating systems and this forum is mostly about radios.  Also, see &lt;a href="https://www.adamheinrich.com/blog/2016/07/context-switch-on-the-arm-cortex-m0/"&gt;www.adamheinrich.com/.../&lt;/a&gt;.  That says the NVIC automatically switches contexts (between the two stacks) for interrupts.  It is not like the MSP is unused, available for you to use care free.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>