<?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>LPC Microcontrollers中的主题 Re: SysTick just stops for no apparent reason</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540091#M12000</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Pacman on Fri Oct 03 04:08:55 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry for the noise and confusion. &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-But if you call your systick from task-time and an interrupt occurs while it's being called, then you'd have a race-condition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ticks++;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above might miss a tick now and then.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The correct way of incrementing a counter, which is updated both by interrupts and task-time, is to use atomic access.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-It gets even worse if you're doing other things in your SysTick interrupt, such as ... unlinking elements from a linked list. &lt;SPAN class="lia-unicode-emoji" title=":winking_face:"&gt;&lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 18:23:39 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T18:23:39Z</dc:date>
    <item>
      <title>SysTick just stops for no apparent reason</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540087#M11996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sdt99 on Thu Sep 25 08:08:02 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC1857 on Keil demo board with IAR, using 1ms SysTick as the primary clock source.&amp;nbsp; I have one variable updated by Systick and used by the main code so I wanted to suspend SysTick interrupts when the variable is accessed by the main code.&amp;nbsp; Here is SysTick initialization (works fine):(CoreClock=180MHz, so the countdown value is within range :&amp;nbsp; I checked)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#define TICKRATE_HZ1 (1000)/* 1000 ticks per second */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SysTick_Config(SystemCoreClock / TICKRATE_HZ1);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are functions I created to disable and re-enable SysTick, checking for a missed tick.&amp;nbsp; The intent was to disable the tick, access the variable (memcpy) and reenable the tick.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void DisableSysTick(void){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SysTick-&amp;gt;CTRL &amp;amp;= ~SysTick_CTRL_TICKINT_Msk; // disable Systick interupt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void EnableSysTick(void){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Check if an interrupt was missed&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(SysTick-&amp;gt;CTRL &amp;amp; SysTick_CTRL_COUNTFLAG_Msk){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SysTick_Handler();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SysTick-&amp;gt;CTRL |= SysTick_CTRL_TICKINT_Msk; // Enable Systick interupt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I call these functions then SysTick seems to randomly stop ticking.&amp;nbsp; When I dump memory from xe000e000 to xe000f000 to look for any register changes that might explain the stop I see no changes (other than the downcounter value, of course).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I comment out these functions then SysTick continues to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't see why this code would cause a problem from either NXP or ARM documentation, but I am pretty new to NXP ARM CPUs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Would be grateful if anyone can point out any obvious errors.&amp;nbsp;&amp;nbsp; I could restructure my code to avoid masking systick, but I am bothered by the fact that I don't understand why the tick stops.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:23:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540087#M11996</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: SysTick just stops for no apparent reason</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540088#M11997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sdt99 on Thu Sep 25 10:32:15 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like I might have found the problem: that the SysTick_Handler() is called from a normal function, not by an interrupt.&amp;nbsp; I guess this is illegal&amp;nbsp; (?).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code was ported from another ARM processor at a slower clock speed, where the EnableSysTick() function did not directly call the SysTick_Handler() ISR, but called a normal function.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:23:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540088#M11997</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: SysTick just stops for no apparent reason</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540089#M11998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Pacman on Sat Sep 27 19:19:02 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;if(SysTick-&amp;gt;CTRL &amp;amp; SysTick_CTRL_COUNTFLAG_Msk){
SysTick_Handler();
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't have a LPC18xx, but as far as I understand, the above code should not be necessary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Try disabling it and see if it works then.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason I think it would work, is that the interrupt pending bit is set, and when this is set, all you have to do, is to enable the interrupt; then the NVIC sees that there's a pending interrupt and executes the SysTick_Handler.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-I might be wrong, though. If so, just ignore this. &lt;SPAN class="lia-unicode-emoji" title=":winking_face:"&gt;&lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:23:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540089#M11998</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: SysTick just stops for no apparent reason</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540090#M11999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sdt99 on Sun Sep 28 05:47:54 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanks for the suggestion, but it's my understanding that the SysTick interrupt cannot be disabled in the NVIC: it can only be disabled in the Systick control register.&amp;nbsp; The NVIC controls peripheral interrupts, but not Cortex interrupts (shown as negative at this link &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Finfocenter.arm.com%2Fhelp%2Findex.jsp%3Ftopic%3D%2Fcom.arm.doc.dui0552a%2FBABHGEAJ.html" rel="nofollow" target="_blank"&gt;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/BABHGEAJ.html&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway the solution it seems is to not call the Systick_Handler directly from the non-ISR code: since I made that change I have not has any further problems with SysTick.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:23:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540090#M11999</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: SysTick just stops for no apparent reason</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540091#M12000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Pacman on Fri Oct 03 04:08:55 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry for the noise and confusion. &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-But if you call your systick from task-time and an interrupt occurs while it's being called, then you'd have a race-condition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ticks++;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above might miss a tick now and then.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The correct way of incrementing a counter, which is updated both by interrupts and task-time, is to use atomic access.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-It gets even worse if you're doing other things in your SysTick interrupt, such as ... unlinking elements from a linked list. &lt;SPAN class="lia-unicode-emoji" title=":winking_face:"&gt;&lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:23:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/SysTick-just-stops-for-no-apparent-reason/m-p/540091#M12000</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:23:39Z</dc:date>
    </item>
  </channel>
</rss>

