<?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>Kinetis Microcontrollers中的主题 Re: Handling NMI on bootup</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973184#M55268</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Install an NMI handler in Flash to catch the event out of reset by disabling NMI MUX function on the PIN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg. from uTasker project&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;static void irq_NMI(void)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; // this is executed immediately out of reset if the NMI line is enabled and held low&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; _CONFIG_PORT_INPUT_FAST_LOW(B, PORTB_BIT18, PORT_PS_UP_ENABLE); // set the NMI line to an input to remove the NMI function and allow the processor to continue&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you want to use the NMI during normal operation install a new handler in SRAM and reconfigure the pin MUX.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg. from uTasker project&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Allow the user to enter an NMI handler, ensuring that the NMI pin is configured as NMI function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// - note that the NMI must not have been disabled to allow this to work&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;extern void fnEnterNMI(void (*_NMI_handler)(void))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; VECTOR_TABLE *ptrVect = (VECTOR_TABLE *)(RAM_START_ADDRESS);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; ptrVect-&amp;gt;ptrNMI = _NMI_handler; // enter interrupt handler&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; _CONFIG_PERIPHERAL(B, 18, (PB_18_NMI | PORT_PS_UP_ENABLE)); // set the NMI pin function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Aug 2019 14:19:35 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2019-08-26T14:19:35Z</dc:date>
    <item>
      <title>Handling NMI on bootup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973183#M55267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/XingChang"&gt;XingChang&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For one of the projects, we are using MKW36 chip, In which NMI pin used as wakeup source, so in FOPT we enabled NMI.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On reset, while booting, NMI is triggered and always enters into NMI handler. When looked into call stack it is observed that there is an NMI exception from where NMI handler is invoked.&lt;/P&gt;&lt;P&gt;In this scenario, the reset handler (_thumb_startup) is invoked two times. How to handle this situation? Can you please help us in understanding the code execution flow in this scenario.&lt;/P&gt;&lt;P&gt;As per the Reference manual, when NMI is active low processor executes an Exception entry and reads address of NMI handler from Vector table offset 8, and begins execution at NMI interrupt handler. But the call stack given below looks different and the PC value for NMI Exception shows 0xFFFFFFF9, this call stack is captured from J-Link debugger.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_9.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/89394i7CB32D818F10A81D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_9.png" alt="pastedImage_9.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Naven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Aug 2019 13:25:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973183#M55267</guid>
      <dc:creator>nsuresh2</dc:creator>
      <dc:date>2019-08-26T13:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Handling NMI on bootup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973184#M55268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Install an NMI handler in Flash to catch the event out of reset by disabling NMI MUX function on the PIN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg. from uTasker project&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;static void irq_NMI(void)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; // this is executed immediately out of reset if the NMI line is enabled and held low&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; _CONFIG_PORT_INPUT_FAST_LOW(B, PORTB_BIT18, PORT_PS_UP_ENABLE); // set the NMI line to an input to remove the NMI function and allow the processor to continue&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you want to use the NMI during normal operation install a new handler in SRAM and reconfigure the pin MUX.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg. from uTasker project&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// Allow the user to enter an NMI handler, ensuring that the NMI pin is configured as NMI function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;// - note that the NMI must not have been disabled to allow this to work&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;extern void fnEnterNMI(void (*_NMI_handler)(void))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; VECTOR_TABLE *ptrVect = (VECTOR_TABLE *)(RAM_START_ADDRESS);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; ptrVect-&amp;gt;ptrNMI = _NMI_handler; // enter interrupt handler&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; _CONFIG_PERIPHERAL(B, 18, (PB_18_NMI | PORT_PS_UP_ENABLE)); // set the NMI pin function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:19:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973184#M55268</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-08-26T14:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Handling NMI on bootup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973185#M55269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the quick response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NMI handler is already defined and is invoked on bootup, in handler the NMI pin is configured to other alternate function, there are no repeated NMI interrupts observed.&lt;/P&gt;&lt;P&gt;There is an observation, the reset handler (_thumb_start) is invoked twice. As per my understanding reset handler should be called&amp;nbsp;only once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;During debugging I added a breakpoint in main function which is invoked from reset handler, here is the call stack once after entry into reset handler&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/89150iB7AEE4D76B4FFB3E/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I give run, the next call stack shows as given below, the control returned back to main again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/63022iB4111D46C7B03FA1/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In first call stack frame, the 'NMI Exception' PC address shows as 0xFFFFFFF9, Is it valid address? As per my understanding, the PC address in call stack for this should show the NMI handler address (vector table offset 8). Is it because handler invoked before initialization complete?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Naven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Aug 2019 16:14:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973185#M55269</guid>
      <dc:creator>nsuresh2</dc:creator>
      <dc:date>2019-08-26T16:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Handling NMI on bootup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973186#M55270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Naven&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the NMI interrupt will be taken immediately out of reset it may not be that easy to clearly see what happens with the debugger. Basically it sounds as though it is working as it should.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The 0xfffffff9 is the EXC_RETURN value - see Cortex Interrupt documentation for details - and this post: &lt;A href="https://community.arm.com/developer/ip-products/processors/f/cortex-m-forum/4557/cortex-m4-exception-return-sequence" target="test_blank"&gt;https://community.arm.com/developer/ip-products/processors/f/cortex-m-forum/4557/cortex-m4-exception-return-sequence&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Aug 2019 17:32:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Handling-NMI-on-bootup/m-p/973186#M55270</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-08-26T17:32:55Z</dc:date>
    </item>
  </channel>
</rss>

