<?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 Re: RT1050 Saving and Restoring C registers in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321513#M178195</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.&lt;BR /&gt;1） Will I also need to clear the stack?&lt;BR /&gt;-- No, I'm afraid not. Regarding the Cortex-M core-based MCU, the compiler can manage the stack during the function context operation via utilizing the registers in the cores (as below shows). When the MCU runs the RTOS which provides the stack management for the created task, in addition to the above stack management.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jeremyzhou_0-1628653484548.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/152543iEAD28324A126A108/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jeremyzhou_0-1628653484548.png" alt="jeremyzhou_0-1628653484548.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;TIC&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
    <pubDate>Wed, 11 Aug 2021 03:45:19 GMT</pubDate>
    <dc:creator>jeremyzhou</dc:creator>
    <dc:date>2021-08-11T03:45:19Z</dc:date>
    <item>
      <title>RT1050 Saving and Restoring C registers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321322#M178164</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help figuring out how to record the current state of the processor registers so they can later be restored at the specific location in code. This will act like a warm reset but starting after initializing all my devices. Below are the functions used on the ARM9 processor. I need to do the same with the Cortext M7 processor. I am using Keilv5 with RTX5 RTOS in my project. Any examples or tips would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will I also need to clear the stack?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Record current state of processor registers. These registers can be restored at any&lt;/P&gt;&lt;P&gt;//time using the popcregs routine and should cause the program to the spot in code that&lt;/P&gt;&lt;P&gt;//the pushcregs was called.&lt;/P&gt;&lt;P&gt;__asm void pushcregs(PROC_STATE *regs)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;STMIA R0!,{R0-R15} //save register values in data structure&lt;/P&gt;&lt;P&gt;STMDB SP!,{R0-R1} //Save R0 &amp;amp; R1 on stack&lt;/P&gt;&lt;P&gt;MRS R1,CPSR //move contents of CPSR to R1&lt;/P&gt;&lt;P&gt;STMIA R0!,{R1} //save PSR in data structure&lt;/P&gt;&lt;P&gt;MRS R1,SPSR //Move contents of saved PSR to R1&lt;/P&gt;&lt;P&gt;STMIA R0!,{R1} //save contents in data structure&lt;/P&gt;&lt;P&gt;LDMIA SP!,{R0-R1} //restore registers R0 &amp;amp; R1&lt;/P&gt;&lt;P&gt;BX LR //return&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;__asm void popcregs(PROC_STATE *regs)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;LDR R1,[R0,#(17*4)] //point to end of data structure&lt;/P&gt;&lt;P&gt;MSR SPSR_c,R1 //restore SPSR&lt;/P&gt;&lt;P&gt;LDR R1,[R0,#(16*4)] //load CPSR into R1&lt;/P&gt;&lt;P&gt;MSR CPSR_c,R1 //restore CPSR&lt;/P&gt;&lt;P&gt;ADD R0,R0,#4 //do not restore PC&lt;/P&gt;&lt;P&gt;LDMIA R0!,{R1-R14} //restore R1 thru R14&lt;/P&gt;&lt;P&gt;BX LR //return to top of program&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 20:39:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321322#M178164</guid>
      <dc:creator>kamal1</dc:creator>
      <dc:date>2021-08-10T20:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: RT1050 Saving and Restoring C registers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321513#M178195</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.&lt;BR /&gt;1） Will I also need to clear the stack?&lt;BR /&gt;-- No, I'm afraid not. Regarding the Cortex-M core-based MCU, the compiler can manage the stack during the function context operation via utilizing the registers in the cores (as below shows). When the MCU runs the RTOS which provides the stack management for the created task, in addition to the above stack management.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jeremyzhou_0-1628653484548.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/152543iEAD28324A126A108/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jeremyzhou_0-1628653484548.png" alt="jeremyzhou_0-1628653484548.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;TIC&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 03:45:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321513#M178195</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2021-08-11T03:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: RT1050 Saving and Restoring C registers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321928#M178260</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/56840"&gt;@jeremyzhou&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for the helpful information. Are there any examples of saving and restoring the stack pointer and all the registers?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 13:25:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1321928#M178260</guid>
      <dc:creator>kamal1</dc:creator>
      <dc:date>2021-08-11T13:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: RT1050 Saving and Restoring C registers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1322256#M178282</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;Thanks for your reply.&lt;BR /&gt;1) Are there any examples of saving and restoring the stack pointer and all the registers?&lt;BR /&gt;-- No, however, you can learn stack management via reviewing the assembly code of the related C language code function.&lt;BR /&gt;Have a great day,&lt;BR /&gt;TIC&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 02:05:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1322256#M178282</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2021-08-12T02:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: RT1050 Saving and Restoring C registers</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1323315#M178428</link>
      <description>&lt;P&gt;Update:&lt;BR /&gt;&lt;BR /&gt;I found these two functions which is what I needed for my project. Using setjmp and longjmp, I can branch back in my code.&lt;BR /&gt;&lt;BR /&gt;#include "setjmp.h"&lt;/P&gt;&lt;P&gt;setjmp(jmp_buf);&lt;/P&gt;&lt;P&gt;longjmp(jmp_buf, return);&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 15:25:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT1050-Saving-and-Restoring-C-registers/m-p/1323315#M178428</guid>
      <dc:creator>kamal1</dc:creator>
      <dc:date>2021-08-13T15:25:28Z</dc:date>
    </item>
  </channel>
</rss>

