<?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>MQX Software SolutionsのトピックRe: MQX not restoring the stack on K70 Tower?</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400204#M13414</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Carlos,&lt;/P&gt;&lt;P&gt;I have the same issue.&lt;/P&gt;&lt;P&gt;I use KDS2.0 MQX4.1.1 on micro MK60FN1M0VLQ12.&lt;/P&gt;&lt;P&gt;I tried to define &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;MQX_SAVE_FP_ALWAYS&lt;/SPAN&gt; as 1 but the problem is not solved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you any suggest?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Mirko&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 Mar 2017 11:02:10 GMT</pubDate>
    <dc:creator>kappa74</dc:creator>
    <dc:date>2017-03-24T11:02:10Z</dc:date>
    <item>
      <title>MQX not restoring the stack on K70 Tower?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400201#M13411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Customer created a very small test program to recreate the issue on the tower using &lt;SPAN style="font-size: 12.0pt; font-family: 'Calibri',sans-serif;"&gt;MK70FN1M0VMJ12 mask 4N96B&lt;/SPAN&gt;. Running this test program recreates the issue very quickly and very often.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; What seems to be happening is that when a task is performing work using the floating point registers and it is interrupted by another task of higher priority that also uses the same floating point registers, then the lower priority task ends up with corrupted data in those floating point registers. For example, this code returns true very often:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test = 0.5f;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(test &amp;lt; 0.4f || test &amp;gt; 0.6f)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt; retVal++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt; retVal++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you look at the screen shots, you can see that the floating point register S0 is being used by the lower priority task. Then after a context switch, the higher priority task uses the same register. Then when the lower priority task resumes, the register S0 has the wrong value. If I make the tasks the same priority or I do this:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: red;"&gt;_int_disable();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test = 0.5f;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(test &amp;lt; 0.4f || test &amp;gt; 0.6f)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt; retVal++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt; retVal++;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: red;"&gt;_int_enable();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then everything works fine. It’s like the RTOS is not restoring the stack properly. Can you please help us with this issue?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-338818"&gt;BugTest-(2).zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Aug 2015 17:47:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400201#M13411</guid>
      <dc:creator>Larry5335</dc:creator>
      <dc:date>2015-08-26T17:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: MQX not restoring the stack on K70 Tower?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400202#M13412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Larry,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I investigated about this issue. I dont know why in the dispatcher the register store function is skipping FPU registers (you can refer to image at the bottom).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can force this code to be executed by setting MQX_SAVE_FP_ALWAYS macro in mqx_cnfg.h and rebuilding PSP and BSP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/54683i652732BE4B1EBDC9/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Carlos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Sep 2015 19:47:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400202#M13412</guid>
      <dc:creator>Carlos_Musich</dc:creator>
      <dc:date>2015-09-03T19:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: MQX not restoring the stack on K70 Tower?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400203#M13413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Carlos,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm facing the same issue. I have a few tasks doing floating point calculations. After context switching I'm getting junk values. If i do the calculations in critical section, I'm getting the expected results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the solution suggested by you (setting&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;MQX_SAVE_FP_ALWAYS). But after that my code resets continuously.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;On debugging, I find that after a reset, code branches to __boot() from the below part causing an infinite loop&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;#if MQX_SAVE_FP_ALWAYS &amp;amp;&amp;amp; PSP_HAS_FPU&lt;BR /&gt; ldr r3, =_psp_push_fp_context&lt;BR /&gt; blx r3&lt;BR /&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Could you please help me on this issue??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Sandeep&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jan 2017 14:21:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400203#M13413</guid>
      <dc:creator>sandeepgeorgema</dc:creator>
      <dc:date>2017-01-13T14:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: MQX not restoring the stack on K70 Tower?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400204#M13414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Carlos,&lt;/P&gt;&lt;P&gt;I have the same issue.&lt;/P&gt;&lt;P&gt;I use KDS2.0 MQX4.1.1 on micro MK60FN1M0VLQ12.&lt;/P&gt;&lt;P&gt;I tried to define &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;MQX_SAVE_FP_ALWAYS&lt;/SPAN&gt; as 1 but the problem is not solved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you any suggest?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Mirko&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Mar 2017 11:02:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400204#M13414</guid>
      <dc:creator>kappa74</dc:creator>
      <dc:date>2017-03-24T11:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: MQX not restoring the stack on K70 Tower?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400205#M13415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;recently I meet same issue, but I have solved it, so post some conclusion here for reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, as carlos mentioned, MQX don't save FPU register before enter isr, if&amp;nbsp;&lt;SPAN&gt;MQX_SAVE_FP_ALWAYS == 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;seem it's gap, but reference manual never suggest how to use FPU in ISR.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Normally there are three ways to implement fpu register save/restore as I understand.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.#define MQX_SAVE_FP_ALWAYS 1&lt;/P&gt;&lt;P&gt;in dispatch.s, you could see, whatever task switch or interrupt isr always save fpu registers, and restore them when back;&lt;/P&gt;&lt;P&gt;but seem the engineer also told me the MQX crash, I guess too much or frequent save/restore maybe damage MQX, even in isr, they save fpu registers in SP, at least we must keep stack large enough.&lt;/P&gt;&lt;P&gt;2.define related floating point task with&amp;nbsp;&lt;SPAN style="color: #1f497d;"&gt;MQX_FLOATING_POINT_TASK&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;which could save/restore fpu register when task switch, same code in dispatch.s, in&amp;nbsp;_pend_svc().&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;but as carlos's snapshot, if isr have floating operation, and &lt;SPAN style="color: #3d3d3d;"&gt;MQX_SAVE_FP_ALWAYS=0,&lt;/SPAN&gt;&amp;nbsp;the FPU register will be changed in isr.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;3.use below function in task to protect floating operation in task,&amp;nbsp;&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #1f497d;"&gt;bool _task_enable_fp(void);&lt;BR /&gt; /* Do your FPU calculation Here */&lt;BR /&gt; void _task_disable_fp(void);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;actually, this solution is same as (2), this is for&amp;nbsp;temporary FPU operation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;so from above description, I have some suggestion how to use FPU in MQX:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;1.never use&amp;nbsp;&lt;SPAN style="color: #3d3d3d;"&gt;MQX_SAVE_FP_ALWAYS== 1, for there are some potential issue to crash MQX, we have no root cause now; and this solution always save/restore fpu registers, which take more time and memory resource;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d;"&gt;2.don't use above (3) solution, which seem same as (2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d;"&gt;3.indentify which task use floating point operation, and define these tasks as&amp;nbsp;MQX_FLOATING_POINT_TASK.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d;"&gt;&amp;nbsp; &amp;nbsp;if only task have floating point operation, which is enough.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d;"&gt;if isr have fpu operation also, indentify which isr, and add&amp;nbsp;_psp_push_fp_context() and&amp;nbsp;_psp_pop_fp_context() call to include fpu operation, which wil save fpu content into C stack.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Dec 2017 14:42:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-not-restoring-the-stack-on-K70-Tower/m-p/400205#M13415</guid>
      <dc:creator>daweiyou</dc:creator>
      <dc:date>2017-12-14T14:42:18Z</dc:date>
    </item>
  </channel>
</rss>

