<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Cortex M0+ PSP/MSP Stack pointer switching implementation in S32K</title>
    <link>https://community.nxp.com/t5/S32K/Cortex-M0-PSP-MSP-Stack-pointer-switching-implementation/m-p/1256753#M10440</link>
    <description>&lt;P&gt;Hi, I am using a NXP S32K118 Cortex M0+ processor&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scheduler function used to call different tasks ( all is time scheduled ) and i need to do the following:&lt;/P&gt;&lt;P&gt;-&amp;gt; Use the main stack pointer (MSP) for this scheduler function&lt;/P&gt;&lt;P&gt;-&amp;gt; Use the process stack pointer (PSP) for the scheduled tasks&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;3 stacks defined in ram ( main stack, secondary stack 1,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;secondary stack&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;2 ). The idea is that the scheduler uses the main stack, and the scheduled tasks use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;secondary stack&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;secondary stack&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;2&lt;/SPAN&gt;, so i need to&amp;nbsp;switch from MSP to PSP when i´m in the scheduer, before calling the corresponding task, and switch back from PSP to MSP once the corresponding task is completed and im back on the scheduler.&lt;/P&gt;&lt;P&gt;I know how to switch these pointers writing to PSP/MSP/CONTROL registers, but the problem I have is i dont know how to do this context switch/ what i need to do in addition of simply changing stack pointers in order to keep all the stacks working properly, so im here just finding for any help/tips if anyone knows how to implement this properly.&lt;/P&gt;&lt;P&gt;Thank you! &lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Apr 2021 17:00:51 GMT</pubDate>
    <dc:creator>riglesias2021</dc:creator>
    <dc:date>2021-04-05T17:00:51Z</dc:date>
    <item>
      <title>Cortex M0+ PSP/MSP Stack pointer switching implementation</title>
      <link>https://community.nxp.com/t5/S32K/Cortex-M0-PSP-MSP-Stack-pointer-switching-implementation/m-p/1256753#M10440</link>
      <description>&lt;P&gt;Hi, I am using a NXP S32K118 Cortex M0+ processor&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scheduler function used to call different tasks ( all is time scheduled ) and i need to do the following:&lt;/P&gt;&lt;P&gt;-&amp;gt; Use the main stack pointer (MSP) for this scheduler function&lt;/P&gt;&lt;P&gt;-&amp;gt; Use the process stack pointer (PSP) for the scheduled tasks&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;3 stacks defined in ram ( main stack, secondary stack 1,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;secondary stack&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;2 ). The idea is that the scheduler uses the main stack, and the scheduled tasks use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;secondary stack&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;secondary stack&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;2&lt;/SPAN&gt;, so i need to&amp;nbsp;switch from MSP to PSP when i´m in the scheduer, before calling the corresponding task, and switch back from PSP to MSP once the corresponding task is completed and im back on the scheduler.&lt;/P&gt;&lt;P&gt;I know how to switch these pointers writing to PSP/MSP/CONTROL registers, but the problem I have is i dont know how to do this context switch/ what i need to do in addition of simply changing stack pointers in order to keep all the stacks working properly, so im here just finding for any help/tips if anyone knows how to implement this properly.&lt;/P&gt;&lt;P&gt;Thank you! &lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 17:00:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/Cortex-M0-PSP-MSP-Stack-pointer-switching-implementation/m-p/1256753#M10440</guid>
      <dc:creator>riglesias2021</dc:creator>
      <dc:date>2021-04-05T17:00:51Z</dc:date>
    </item>
  </channel>
</rss>

