<?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: Cortex M0+ delay routine without timers in S32K</title>
    <link>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1447871#M15079</link>
    <description>&lt;P&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/182339"&gt;@riglesias2021&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;It does not depend just on the core.&lt;/P&gt;
&lt;P&gt;Although the S32K11x series is not that complicated, we can get different results when&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the delay code is placed in SRAM:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_0-1650633876998.png" style="width: 735px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177744i5EDEE0EF3E1AB251/image-dimensions/735x294?v=v2" width="735" height="294" role="button" title="danielmartynek_0-1650633876998.png" alt="danielmartynek_0-1650633876998.png" /&gt;&lt;/span&gt; &lt;/P&gt;
&lt;P&gt;PTE8 Toggles every 0.9177ms instead of 1ms&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_1-1650633929528.png" style="width: 829px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177745i41CF57983DA4335F/image-dimensions/829x114?v=v2" width="829" height="114" role="button" title="danielmartynek_1-1650633929528.png" alt="danielmartynek_1-1650633929528.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In Flash with Prefetch buffer enabled: 1.085ms&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_2-1650634071884.png" style="width: 850px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177747i55EE9FD83FD11763/image-dimensions/850x326?v=v2" width="850" height="326" role="button" title="danielmartynek_2-1650634071884.png" alt="danielmartynek_2-1650634071884.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_3-1650634102250.png" style="width: 880px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177748iC9D590F136E9BD24/image-dimensions/880x168?v=v2" width="880" height="168" role="button" title="danielmartynek_3-1650634102250.png" alt="danielmartynek_3-1650634102250.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In Flash&amp;nbsp;with Prefetch buffer disabled: 1.585ms&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="c"&gt;MSCM-&amp;gt;OCMDR[0] |= (1&amp;lt;&amp;lt;4) | (1&amp;lt;&amp;lt;5);&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_4-1650634155919.png" style="width: 887px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177749i662E51F6504FE43E/image-dimensions/887x136?v=v2" width="887" height="136" role="button" title="danielmartynek_4-1650634155919.png" alt="danielmartynek_4-1650634155919.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer to the RM, Section 35.5.2 Speculative reads for more information about the buffer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regadrs,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2022 13:35:08 GMT</pubDate>
    <dc:creator>danielmartynek</dc:creator>
    <dc:date>2022-04-22T13:35:08Z</dc:date>
    <item>
      <title>Cortex M0+ delay routine without timers</title>
      <link>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1447046#M15059</link>
      <description>&lt;P&gt;Hello, I´m trying to implement a small assembly routine in a cortex M0+ in order to introduce a software controlled delay in microseconds. For performing this, i wrote this small while() routine:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;while&lt;/SPAN&gt;&lt;SPAN&gt; (CyclesToDelay &amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;__no_operation&lt;/SPAN&gt;&lt;SPAN&gt;();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CyclesToDelay--;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;So, knowing exactly what assembly instructions are executing, the clk clock frequency, and the number of clk cycles per instruction, I can calculate the CyclesToDelay value for a desired delay to introduce.&lt;BR /&gt;&lt;BR /&gt;Assembly:&lt;/P&gt;&lt;P&gt;__no_operation();&lt;BR /&gt;0002 73F8 NOP&lt;BR /&gt;&lt;SPAN&gt;CyclesToDelay&lt;/SPAN&gt;--;&lt;BR /&gt;0002 73FA LDR R1, [R0]&lt;BR /&gt;0002 73FC SUBS R1, R1, #1&lt;BR /&gt;0002 73FE STR R1, [R0]&lt;BR /&gt;while (&lt;SPAN&gt;CyclesToDelay&lt;/SPAN&gt; &amp;gt; 0)&lt;BR /&gt;0002 7400 LDR R1, [R0]&lt;BR /&gt;0002 7402 CMP R1, #0&lt;BR /&gt;0002 7404 BNE 0x000273F8&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Instruction clk cycles according&amp;nbsp;&lt;A href="https://developer.arm.com/documentation/ddi0432/c/programmers-model/instruction-set-summary" target="_blank" rel="noopener"&gt;https://developer.arm.com/documentation/ddi0432/c/programmers-model/instruction-set-summary&lt;/A&gt;&amp;nbsp;are:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;NOP 1 clk cycles&lt;/P&gt;&lt;P&gt;LDR 2 clk cycles&lt;/P&gt;&lt;P&gt;SUBS 1 clk cycles&lt;/P&gt;&lt;P&gt;STR&amp;nbsp; 2 clk cycles&lt;/P&gt;&lt;P&gt;LDR 2 clk cycles&lt;/P&gt;&lt;P&gt;CMP 1 clk cycles&lt;/P&gt;&lt;P&gt;BNE 3 clk cycles&lt;/P&gt;&lt;P&gt;Total clk cycles in this routine = 12 clk cycles,&lt;BR /&gt;&lt;BR /&gt;CORE_CLK = 48mhz&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then,&lt;BR /&gt;&lt;BR /&gt;1)&amp;nbsp;1 CORE_CLK cycle = 1 / 48 us&lt;BR /&gt;&lt;BR /&gt;2) 12 CORE_CLK cycles = 12/48 us ( The number of microseconds one loop of this routine should delay)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Finally:&lt;BR /&gt;&lt;BR /&gt;3)&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;CyclesToDelay *&amp;nbsp; (12/48) = delay_we_want_to_introduce(us)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;or&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;CyclesToDelay = delay_we_want_to_inject(us) * 48 / 12&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However, measuring the delays obtained with this method does not seem to be very accurate. I dont know if this is going to be deterministic or if this is totally possible in this Cortex M0+. Feedback would be appreciated. Many thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 08:49:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1447046#M15059</guid>
      <dc:creator>riglesias2021</dc:creator>
      <dc:date>2022-04-21T08:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Cortex M0+ delay routine without timers</title>
      <link>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1447871#M15079</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/182339"&gt;@riglesias2021&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;It does not depend just on the core.&lt;/P&gt;
&lt;P&gt;Although the S32K11x series is not that complicated, we can get different results when&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the delay code is placed in SRAM:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_0-1650633876998.png" style="width: 735px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177744i5EDEE0EF3E1AB251/image-dimensions/735x294?v=v2" width="735" height="294" role="button" title="danielmartynek_0-1650633876998.png" alt="danielmartynek_0-1650633876998.png" /&gt;&lt;/span&gt; &lt;/P&gt;
&lt;P&gt;PTE8 Toggles every 0.9177ms instead of 1ms&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_1-1650633929528.png" style="width: 829px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177745i41CF57983DA4335F/image-dimensions/829x114?v=v2" width="829" height="114" role="button" title="danielmartynek_1-1650633929528.png" alt="danielmartynek_1-1650633929528.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In Flash with Prefetch buffer enabled: 1.085ms&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_2-1650634071884.png" style="width: 850px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177747i55EE9FD83FD11763/image-dimensions/850x326?v=v2" width="850" height="326" role="button" title="danielmartynek_2-1650634071884.png" alt="danielmartynek_2-1650634071884.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_3-1650634102250.png" style="width: 880px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177748iC9D590F136E9BD24/image-dimensions/880x168?v=v2" width="880" height="168" role="button" title="danielmartynek_3-1650634102250.png" alt="danielmartynek_3-1650634102250.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In Flash&amp;nbsp;with Prefetch buffer disabled: 1.585ms&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="c"&gt;MSCM-&amp;gt;OCMDR[0] |= (1&amp;lt;&amp;lt;4) | (1&amp;lt;&amp;lt;5);&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_4-1650634155919.png" style="width: 887px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177749i662E51F6504FE43E/image-dimensions/887x136?v=v2" width="887" height="136" role="button" title="danielmartynek_4-1650634155919.png" alt="danielmartynek_4-1650634155919.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer to the RM, Section 35.5.2 Speculative reads for more information about the buffer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regadrs,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 13:35:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1447871#M15079</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2022-04-22T13:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Cortex M0+ delay routine without timers</title>
      <link>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1448409#M15102</link>
      <description>&lt;P&gt;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/160001"&gt;@danielmartynek&lt;/a&gt;&amp;nbsp; Thanks for the reply, It seems that i dont have the&amp;nbsp;&lt;SPAN&gt;Prefetch buffer enabled,&lt;/SPAN&gt; Its is possible to determine with exactitude the delay of this routine with a specific MSCM config?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 09:07:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1448409#M15102</guid>
      <dc:creator>riglesias2021</dc:creator>
      <dc:date>2022-04-25T09:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Cortex M0+ delay routine without timers</title>
      <link>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1448575#M15113</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/182339"&gt;@riglesias2021&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;The prefetch buffer is enabled by default.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_1-1650891540337.png" style="width: 716px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177879i8E2BC7895AE85C54/image-dimensions/716x161?v=v2" width="716" height="161" role="button" title="danielmartynek_1-1650891540337.png" alt="danielmartynek_1-1650891540337.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_3-1650891597947.png" style="width: 715px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177881i9C4A2C74E74284D0/image-dimensions/715x138?v=v2" width="715" height="138" role="button" title="danielmartynek_3-1650891597947.png" alt="danielmartynek_3-1650891597947.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_5-1650891969237.png" style="width: 713px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177887i86F18EA18B0FE995/image-dimensions/713x579?v=v2" width="713" height="579" role="button" title="danielmartynek_5-1650891969237.png" alt="danielmartynek_5-1650891969237.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But anyway, I don't think we can determine the accuracy of the timing.&lt;/P&gt;
&lt;P&gt;Even with the prefetch buffer disabled, it depends on the location of the code in the flash.&lt;/P&gt;
&lt;P&gt;Also, the core accesses the Flash via the Crossbar switch.&lt;/P&gt;
&lt;P&gt;The eDMA could add other wait states because of the arbitration on the switch,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="danielmartynek_6-1650892565573.png" style="width: 677px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/177892iDDB0FBF7374E35E7/image-dimensions/677x531?v=v2" width="677" height="531" role="button" title="danielmartynek_6-1650892565573.png" alt="danielmartynek_6-1650892565573.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend using HW timers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 13:19:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/Cortex-M0-delay-routine-without-timers/m-p/1448575#M15113</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2022-04-25T13:19:25Z</dc:date>
    </item>
  </channel>
</rss>

