<?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 Software Development KitのトピックRe: Installing interrupts with KSDK 2.0?</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509852#M5220</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Jason, that seems to work great! One other thing I neglected was to declare &lt;SPAN style="font-family: 'courier new', courier;"&gt;timerWentOff&lt;/SPAN&gt; as &lt;SPAN style="font-family: 'courier new', courier;"&gt;volatile&lt;/SPAN&gt;. Under Release, it was failing, and the only difference I could see is that Release uses &lt;SPAN style="font-family: 'courier new', courier;"&gt;-Os -g&lt;/SPAN&gt; while Debug uses &lt;SPAN style="font-family: 'courier new', courier;"&gt;-O -g3&lt;/SPAN&gt;. I made sure everything else was the same. I confirmed that it was &lt;SPAN style="font-family: 'courier new', courier;"&gt;-Os&lt;/SPAN&gt; that caused the failure -- it was most likely optimizing the &lt;SPAN style="font-family: 'courier new', courier;"&gt;while (!timerWentOff)&lt;/SPAN&gt; out, which would make sense for a nonvolatile &lt;SPAN style="font-family: 'courier new', courier;"&gt;timerWentOff&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Being able to see the disassembly would have helped :smileyhappy: Unfortunately (this is under KDS 3.1.0) pulling up the Disassembly window doesn't seem to do anything.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 14 Feb 2016 21:10:27 GMT</pubDate>
    <dc:creator>robertbaruch</dc:creator>
    <dc:date>2016-02-14T21:10:27Z</dc:date>
    <item>
      <title>Installing interrupts with KSDK 2.0?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509849#M5217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've only found a &lt;A _jive_internal="true" data-containerid="11234" data-containertype="14" data-objectid="104352" data-objecttype="102" href="https://community.nxp.com/docs/DOC-104352"&gt;document &lt;/A&gt;for KSDK 1.2, which refers to &lt;SPAN style="font-family: 'courier new', courier;"&gt;fsl_interrupt_manager.h&lt;/SPAN&gt;, which doesn't seem to exist in SDK 2.0. I did find a function &lt;SPAN style="font-family: 'courier new', courier;"&gt;InstallIRQHandler&lt;/SPAN&gt; in &lt;SPAN style="font-family: 'courier new', courier;"&gt;fsl_common.c&lt;/SPAN&gt;, but I'm not sure I'm using it properly. Basically, I'm trying to write a delay function:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;static bool timerWentOff = false;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;void timerIRQHandler() {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; PIT_StopTimer(PIT, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; timerWentOff = true;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;void delayMsec(uint32_t msec) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; timerWentOff = false;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; PIT_SetTimerPeriod(PIT, 0, (uint32_t) MSEC_TO_COUNT(msec, CLOCK_GetBusClkFreq()));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; PIT_StartTimer(PIT, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; while (!timerWentOff);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;void initTimerModule() {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; CLOCK_EnableClock(kCLOCK_Pit0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; pit_config_t timerConfig = {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .enableRunInDebug = true,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; };&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; PIT_Init(PIT, &amp;amp;timerConfig);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; EnableIRQ(PIT0_IRQn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; InstallIRQHandler(PIT0_IRQn, (uint32_t) timerIRQHandler);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then in main, something like:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; for (;;) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delayMsec(100);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LED_RED_TOGGLE();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I hit InstallIRQHandler, I get a hard fault. What's the right procedure to install an interrupt?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Feb 2016 04:28:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509849#M5217</guid>
      <dc:creator>robertbaruch</dc:creator>
      <dc:date>2016-02-14T04:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Installing interrupts with KSDK 2.0?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509850#M5218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update: I changed the linker settings to include &lt;SPAN style="font-family: 'courier new', courier;"&gt;-Xlinker --defsym=__ram_vector_table__=1&lt;/SPAN&gt;, and now I'm not getting the hard fault (it helps to make the vectors actually modifiable!) but now I'm not getting the interrupt. Anything wrong with the code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Update 2: Added &lt;SPAN style="font-family: 'courier new', courier;"&gt;PIT_EnableInterrupts(PIT, 0, kPIT_TimerInterruptEnable);&lt;/SPAN&gt; at the end of &lt;SPAN style="font-family: 'courier new', courier;"&gt;initTimerModule&lt;/SPAN&gt;. Now it seems the interrupt is going off (a breakpoint in the interrupt handler is hit), but it's going off continuously -- the LED never gets toggled.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Feb 2016 04:34:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509850#M5218</guid>
      <dc:creator>robertbaruch</dc:creator>
      <dc:date>2016-02-14T04:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Installing interrupts with KSDK 2.0?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509851#M5219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From your update 2 it looks like you're really close to solving your issue, you're only missing an interrupt clear inside of your timer interrupt handler. Adding this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_14554606003476308 jive_macro_code jive_text_macro" data-renderedposition="112_8_1192_16" jivemacro_uid="_14554606003476308"&gt;&lt;P&gt;PIT_ClearStatusFlags(PIT, 0, kPIT_TimerFlag);&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're seeing the CPU continually service the interrupt, since it's never cleared. It probably looks like it's running through the code properly because of the debugger delays, but it's really never able to go and do anything other than service the interrupt once it has been set by the PIT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now a little bit of background information on how you could have approached the use of interrupts in SDK 2.0 differently (hopefully a little easier as well).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each of the interrupt functions in SDK 2.0 are defined with the 'weak' attribute. From &lt;A href="https://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/Function-Attributes.html" rel="nofollow noopener noreferrer" target="_blank"&gt;gcc.gnu.org&lt;/A&gt;,&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;weak&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations. Weak symbols are supported for ELF targets, and also for a.out targets when using the GNU assembler and linker.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This means that in order to override the weak symbol, all you need to do is define the interrupt symbol in your own code. Interrupt symbols can be found in startup_&amp;lt;soc_name&amp;gt;.S. Choosing this route eliminates the need for the special linker directives as well as having to install the interrupt from application code; there's nothing to install when you're using the default symbol in the vector table. In my test, my interrupt handler looks like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14554614629894546 jive_text_macro" data-renderedposition="558_8_1192_128" jivemacro_uid="_14554614629894546"&gt;&lt;P&gt;void PIT0_IRQHandler() {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PIT_StopTimer(PIT, 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; PIT_ClearStatusFlags(PIT, 0, kPIT_TimerFlag);&lt;/P&gt;&lt;P&gt;&amp;nbsp; timerWentOff = true;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Feb 2016 14:51:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509851#M5219</guid>
      <dc:creator>Jmart</dc:creator>
      <dc:date>2016-02-14T14:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Installing interrupts with KSDK 2.0?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509852#M5220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Jason, that seems to work great! One other thing I neglected was to declare &lt;SPAN style="font-family: 'courier new', courier;"&gt;timerWentOff&lt;/SPAN&gt; as &lt;SPAN style="font-family: 'courier new', courier;"&gt;volatile&lt;/SPAN&gt;. Under Release, it was failing, and the only difference I could see is that Release uses &lt;SPAN style="font-family: 'courier new', courier;"&gt;-Os -g&lt;/SPAN&gt; while Debug uses &lt;SPAN style="font-family: 'courier new', courier;"&gt;-O -g3&lt;/SPAN&gt;. I made sure everything else was the same. I confirmed that it was &lt;SPAN style="font-family: 'courier new', courier;"&gt;-Os&lt;/SPAN&gt; that caused the failure -- it was most likely optimizing the &lt;SPAN style="font-family: 'courier new', courier;"&gt;while (!timerWentOff)&lt;/SPAN&gt; out, which would make sense for a nonvolatile &lt;SPAN style="font-family: 'courier new', courier;"&gt;timerWentOff&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Being able to see the disassembly would have helped :smileyhappy: Unfortunately (this is under KDS 3.1.0) pulling up the Disassembly window doesn't seem to do anything.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Feb 2016 21:10:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509852#M5220</guid>
      <dc:creator>robertbaruch</dc:creator>
      <dc:date>2016-02-14T21:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Installing interrupts with KSDK 2.0?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509853#M5221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're right about the volatile on the timerWentOff variable, and I did have that in my code, just failed to mention that difference in my last post. &lt;SPAN class="lia-unicode-emoji" title=":confused_face:"&gt;&lt;LI-EMOJI id="lia_confused-face" title=":confused_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt; It probably was being optimized, since it never saw a need to re-read that variable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm surprised you're encountering issues with the disassembly view in KDS 3.1. I'm able to step through with the disassembly window open and it works fine, albeit slow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're really wanting to put this question to rest (and this could be helpful in the future), the other option that you have is to use objdump. The following command will dump the assembly of a given executable or object file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arm-none-eabi-objdump -D &amp;lt;filename&amp;gt; - here's a snippet of the output from my main.o delay function, which is based on your code from your original post. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_14554858787863466 jive_macro_code jive_text_macro" data-renderedposition="320_8_1192_144" jivemacro_uid="_14554858787863466" modifiedtitle="true"&gt;&lt;P&gt;58:&amp;nbsp;&amp;nbsp;&amp;nbsp; f7ff fffe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bl&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &amp;lt;delay&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 5c:&amp;nbsp;&amp;nbsp;&amp;nbsp; bf00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nop&lt;/P&gt;&lt;P&gt;&amp;nbsp; 5e:&amp;nbsp;&amp;nbsp;&amp;nbsp; 4b05&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldr&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, [pc, #20]&amp;nbsp;&amp;nbsp;&amp;nbsp; ; (74 &amp;lt;delay+0x74&amp;gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp; 60:&amp;nbsp;&amp;nbsp;&amp;nbsp; 781b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldrb&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, [r3, #0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; 62:&amp;nbsp;&amp;nbsp;&amp;nbsp; b2db&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uxtb&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, r3&lt;/P&gt;&lt;P&gt;&amp;nbsp; 64:&amp;nbsp;&amp;nbsp;&amp;nbsp; f083 0301&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eor.w&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, r3, #1&lt;/P&gt;&lt;P&gt;&amp;nbsp; 68:&amp;nbsp;&amp;nbsp;&amp;nbsp; b2db&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uxtb&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, r3&lt;/P&gt;&lt;P&gt;&amp;nbsp; 6a:&amp;nbsp;&amp;nbsp;&amp;nbsp; 2b00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmp&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, #0&lt;/P&gt;&lt;P&gt;&amp;nbsp; 6c:&amp;nbsp;&amp;nbsp;&amp;nbsp; d1f7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bne.n&amp;nbsp;&amp;nbsp;&amp;nbsp; 5e &amp;lt;delay+0x5e&amp;gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Feb 2016 21:25:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Installing-interrupts-with-KSDK-2-0/m-p/509853#M5221</guid>
      <dc:creator>Jmart</dc:creator>
      <dc:date>2016-02-14T21:25:46Z</dc:date>
    </item>
  </channel>
</rss>

