<?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>ColdFire/68K Microcontrollers and ProcessorsのトピックRe: MCF52259 Spurious interrupt, help tracking it down</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176283#M6897</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, the latest is that I went through all the code, scattered the proper disable-store-twiddle-enable code liberally about whenever I found the IMR or peripheral interrupt registers being modified and so far there's been no more spurious interrupts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hesitate to say "problem solved" (very difficult with intermittent faults of any sort) but it certainly looks like a great leap in the right direction. Plus I've learned a thing or two along the way, so a good result all round.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers Tom!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Jan 2011 03:49:29 GMT</pubDate>
    <dc:creator>FridgeFreezer</dc:creator>
    <dc:date>2011-01-20T03:49:29Z</dc:date>
    <item>
      <title>MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176272#M6886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A bit cheeky as I've already posted in the CW section but not had much luck:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fcommunity.freescale.com%2Fmessage%2F75148%2375148" rel="nofollow" target="_blank"&gt;https://community.freescale.com/message/75148#75148&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are using an MCF52259 on our own PCB, CW7.2. We have interrupts and ISR's set up for:&lt;/P&gt;&lt;P&gt;QSPI&lt;/P&gt;&lt;P&gt;I2C&lt;/P&gt;&lt;P&gt;UART0,1 &amp;amp; 2&lt;/P&gt;&lt;P&gt;/IRQ1,3,5,7&lt;/P&gt;&lt;P&gt;PIT0,1 (as fixed interval timers)&lt;/P&gt;&lt;P&gt;DTIM0,1,2,3 (variable freq, driving stepper motors)&lt;/P&gt;&lt;P&gt;RTC (seconds)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All seem to be working correctly, but at seemingly random intervals we are getting spurious interrupts. There seems to be no pattern to it - we can shove data up the UARTS, drive motors, leave the thing idle, whatever and sometimes it is fine for hours but other times it hits the spurious ISR in seconds. In our current prototype we are not using UART2, but I have left the ISR in place doing a dummy read of the Rx buffer and clearing any flags.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read MJBSwitzerland's excellent post about spurious interrupts, but nothing contained in it seems to have helped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any wisdom on how to track down the source of the problem?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jan 2011 23:21:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176272#M6886</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2011-01-13T23:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176273#M6887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case , spurious interrupt was generated by a bad UART programming, RX/TX interrupt and was enabled while DMA transfer was enabled too.&lt;/P&gt;&lt;P&gt;DMA channel clear pending UART flags, while interrupt controller knows there's a pending interrupt, but doesn't know which is pending because flag is cleared.&lt;/P&gt;&lt;P&gt;Set breakpoint&amp;nbsp; inside spurious exception routine, and try to see in IPRL/IPRH register which interrupt is pending, and try to find an explanation &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Emmanuel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 00:30:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176273#M6887</guid>
      <dc:creator>Nouchi</dc:creator>
      <dc:date>2011-01-14T00:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176274#M6888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We don't have DMA configured (we're not using it) but I will double-check the settings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When it drops into the spurious ISR, as per my other thread the registers are as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IPRH: 0x00000000&lt;/P&gt;&lt;P&gt;IPRL: 0x00008000&lt;/P&gt;&lt;P&gt;IMRH: 0x7E7FFFFF&lt;/P&gt;&lt;P&gt;IMRL: 0XFF839F56&lt;/P&gt;&lt;P&gt;IRLR: 0x00000000&lt;/P&gt;&lt;P&gt;IACKLPR: 0x00000000&lt;/P&gt;&lt;P&gt;SWIACK: 0x00000000&lt;/P&gt;&lt;P&gt;L1IACK: 0x00000000&lt;/P&gt;&lt;P&gt;L2IACK: 0x00000018&lt;/P&gt;&lt;P&gt;L3IACK: 0x00000018&lt;/P&gt;&lt;P&gt;L4IACK: 0x00000018&lt;/P&gt;&lt;P&gt;L5IACK: 0x00000018&lt;/P&gt;&lt;P&gt;L6IACK: 0x00000018&lt;/P&gt;&lt;P&gt;L7IACK: 0x00000018&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 01:12:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176274#M6888</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2011-01-14T01:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176275#M6889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; A bit cheeky as I've already posted in the CW section but not had much luck:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would have helped if you'd summarised here all the things you've already tried there. I was going to suggest "masking interrupts around IMR accesses" but you've already tried that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; It seems that common best practice is to mask interrupts by SET_IPL(7)&lt;/P&gt;&lt;P&gt;&amp;gt; before modifying the interrupt mask to prevent spurious interrupts. I'm&lt;/P&gt;&lt;P&gt;&amp;gt; now doing this every time I modify the IMR. I don't know if there are&lt;/P&gt;&lt;P&gt;&amp;gt; other places this should be done, for example when modifying&lt;/P&gt;&lt;P&gt;&amp;gt; peripherals interrupt control registers?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you have to re-enable interrupts after that somehow. It is better practice to use something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saved_isr = SET_IPL(7);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change the IMRs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET_IPL(saved_isr);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But you need a version of "SET_IPL()" that returns the CURRENT IPL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your code is simple enough so that you can guarantee that you never call "SET_IPL(7) ; xxx ; SET_IPL(0);" anywhere that the IPL isn't already zero you're OK, but that prevents you from writing code with functions called from both mainline and interrupt-code. Technically it doesn't stop you doing this, it just makes lots of new and nasty bugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; I don't know if there are&lt;/P&gt;&lt;P&gt;&amp;gt; other places this should be done, for example when modifying&lt;/P&gt;&lt;P&gt;&amp;gt; peripherals interrupt control registers?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The interrupt is about to happen, and then the mask is changed so it is blocked. That's like going to sit on a chair and having someone pull it away. That's a "spurious interrupt". Any time you do anything to a control register that might make it "pull the chair away" you have to mask CPU interrupts. So if you're changing any peripheral registers to disable an interrupt you have to do it there too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To find out where it is happening, have your Spurious interrupt routine DUMP THE STACK. You should see the PC on the stack just after the code that disabled the interrupt (that you shouldn't have done). If you're running under a debugger, put a breakpoint in there and then the debugger should show where it was interrupted from.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 07:01:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176275#M6889</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2011-01-14T07:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176276#M6890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; Then you have to re-enable interrupts after that somehow. It is better practice to use something like:&lt;/P&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; saved_isr = SET_IPL(7);&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change the IMRs;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET_IPL(saved_isr);&lt;/P&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;gt; But you need a version of "SET_IPL()" that returns the CURRENT IPL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, I didn't give the full picture, the code does indeed do:&lt;/P&gt;&lt;P&gt;set_ipl(7)&lt;/P&gt;&lt;P&gt;&amp;lt;twiddle registers&amp;gt;&lt;/P&gt;&lt;P&gt;set_ipl(0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the included Freescale routines from "mcf5xxx.c":&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;void mcf5xxx_irq_enable (void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm_set_ipl(0);&lt;BR /&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;void mcf5xxx_irq_disable (void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm_set_ipl(7);&lt;BR /&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; If your code is simple enough so that you can guarantee that you never call "SET_IPL(7) ; xxx ; SET_IPL(0);"&lt;/P&gt;&lt;P&gt;&amp;gt; anywhere that the IPL isn't already zero you're OK, but that prevents you from writing code with&lt;/P&gt;&lt;P&gt;&amp;gt; functions called from both mainline and interrupt-code.&lt;/P&gt;&lt;P&gt;&amp;gt; Technically it doesn't stop you doing this, it just makes lots of new and nasty bugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you explain what you mean by this? Are you saying that, for example, in an ISR the IPL may be non-zero and that blindly resetting it to 0 will mess things up? If so, it seems my predecessor and possibly also freescale have made the same mistake in places :-O&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I've come into this embedded lark from a bit of a sideways direction (most previous coding in PHP!)&amp;nbsp; so there are some glaring gaps in my knowledge where "everyone knows that" but I really don't. For example, I have no idea how I might dump the stack in C (I realise I can see it in the debugging window though).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 20:31:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176276#M6890</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2011-01-14T20:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176277#M6891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; If your code is simple enough so that you can guarantee that you never call "SET_IPL(7) ; xxx ; SET_IPL(0);"&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; anywhere that the IPL isn't already zero you're OK, but that prevents you from writing code with&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; functions called from both mainline and interrupt-code.&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Technically it doesn't stop you doing this, it just makes lots of new and nasty bugs&lt;/P&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Can you explain what you mean by this? Are you saying that,&lt;/P&gt;&lt;P&gt;&amp;gt; for example, in an ISR the IPL may be non-zero and that&lt;/P&gt;&lt;P&gt;&amp;gt; blindly resetting it to 0 will mess things up?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, sure will.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Coldfire CPUs have seven IPLs. Devices can interrupt at any level from 1 to 6, or 7 which is "non maskable" and best avoided.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This means that when everything is set up OK, a device interrupting at (say) level 6 can interrupt OTHER INTERRUPT SERVICE ROUTINES running from lower level interrupts. This can be very useful if you need it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other primitive ancient CPUs (cheap 8-bitters and their derivatives like the Pentium in your PC &lt;IMG alt="Smiley Happy" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="https://community.nxp.com/i/smilies/16x16_smiley-happy.png" title="Smiley Happy" /&gt; have only one level. They can support multiple levels by faking it in the interrupt controller. This means the CPU has to program the interrupt controller with the heirarchy if multi-level nested interrupts are needed and let it know when interrupt service routines end. Whether this should be done in the CPU ir the interrupt controller is somewhat of a "religious argument", and you can see which one I like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The CPU starts of in the "mainline" at Level zero. When a level "N" interrupt happens, the CPU's IPL is set to Level N. That means that device can't interrupt the CPU again. It is really bad news if you're in an ISR (Interrupt Service Routine), get the levels wrong and the device interrupts the SAME service routine in the middle. This is uncontrolled re-entrancy and almost always bad.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if you're running in an interrupt service routine for a device at level "N", and have to set the level to "7" in order to mess with the mask register, it is ESSENTIAL to restore the level back to "N" and *NOT* back to Zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ugly and dangerous way to do this is to have to know that a particular ISR is interrupted by a device at a specific hardwired level (say "5"), and then you do::&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm_set_ipl(7);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change mask;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm_set_ipl(5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is "ugly" as it means you can change the IPL somewhere else and forget to change it in this routine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It also means you can't write general purpose functions that need to disable the interrupts and be called from mainline (return IPL to zero) and multiple different ISRs where the IPL has to be returned to different values. It also means that if someone cut/pastes that code into a different ISR and doesn't change the "magic numbers" it'll cause more problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*BUT* if you track down the source code for "asm_set_ipl()" (should be in mfcxxx.s) you should find it returns the previous level. So your code for disabling interrupts (everywhere that you disable and restore interrupts) should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int saved_ipl = asm_set_ipl(7);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Change the IMRs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm_set_ipl(saved_ipl);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you can't find mcf5xxx.s in your distribution, then google for "_mcf5xxx_wr_other_sp" and you'll find a copy somewhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; For example, I have no idea how I might dump the stack in C (I realise I can see it in the debugging window though).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And when you check the debugger, where was the code when the spurious interrupt happened? That's where the bug is. That's the problem you were looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the simple way to dump the stack ("DEBUG" is our print function - replace with whatever you're using, and "dump_stack890' dumps frames, but you could just have it print 10 or 20 words and look for addresses manually)::&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;__attribute__((interrupt_handler)) static void int_addr_isr( void ){    uint32_t i[1];    unsigned int sr = i[2] &amp;amp; 0xffff;    unsigned int fs = ( ( i[2] &amp;gt;&amp;gt; 16 ) &amp;amp; 0x3 ) | ( ( i[2] &amp;gt;&amp;gt; 24 ) &amp;amp; 0xc );    unsigned int vector = ( i[2] &amp;gt;&amp;gt; 18 ) &amp;amp; 0xff;    unsigned int format = ( i[2] &amp;gt;&amp;gt; 28 );    unsigned int pc = i[3];    DEBUG( 1, "sr=0x%04X fs=0x%01X vector=%d format=0x%02X pc=0x%08X",           sr, fs, vector, format, pc );     dump_stack( &amp;amp;i[1], 1 );&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that "i" is a local variable on the stack. So the rest of the stack is "up" from the address of that variable. For each CPU you want to do this with you have to check the manuals to see what the exception stack looks like and where the PC and other things are. Since the "frame pointer" is pushed on the stack it is pretty simple to walk back through all previous stack frames, printing all the previous function addresses too. That's how the debugger does it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if you've got a debugger it'll do all that for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:25:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176277#M6891</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2020-10-29T09:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176278#M6892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom, that was incredibly handy &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had done some digging along the lines you suggested and found the asm_set_ipl() routine returns a value, is there any reason not to use the following to mask/restore interrupts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void TwiddleInts(uint8 onoff){ static uint8 ipl = 0;  if(!onoff) {  ipl = asm_set_ipl(7); } else
        {  asm_set_ipl(ipl); }}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:25:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176278#M6892</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2020-10-29T09:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176279#M6893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom, just one question about your routine above:&lt;/P&gt;&lt;P&gt;If you define a one-element array &lt;STRONG&gt;uint32 i[1]&lt;/STRONG&gt; then the first element is accessed as &lt;STRONG&gt;i[0]&lt;/STRONG&gt;, the 2nd element is &lt;STRONG&gt;i[1]&lt;/STRONG&gt;, so should the references to &lt;STRONG&gt;i[2]&lt;/STRONG&gt; as stack frame pointer in fact be &lt;STRONG&gt;i[1]&lt;/STRONG&gt; ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After waiting for the thing to crash again (things never fail when you want them to) I have a result (using your routine, subject to my query above):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;FS = 0x00000000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Vector = 0x00&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Format = 0x00&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PC = 0x00000001&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SR = 0x0105&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which doesn't seem quite right to me (as in I don't entirely believe the answer).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 03:03:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176279#M6893</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2011-01-18T03:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176280#M6894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; is there any reason not to use the following to mask/restore interrupts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Opaque. Hidden variable. Requires strictly calling it in "disable/enable" pairs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Provides no extra functionality to directly calling asm_set_ipl() apart from making bugs more likely and being slower.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It doesn't look thread-safe or interrupt safe as there's only one storage location for the saved interrupt (which can't be interrupted, so it is safe, but took me 5 minutes to prove it). So almost by accident, if called properly, it probably is safe.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Don't use "uint8" on this CPU. Just use "int". All parameters are passed as 32 bits and so 16 and 8 bit variables on this CPU are "harder". Ditto storage, unless you have arrays of 8 or 16 bits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"uint8 onoff" should be "bool" or preferably "typedef enum { INTERRUPT_OFF, INTERRUPT_ON } eInterrupt_t;", as otherwise it isn't obvious what the value should be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 11:36:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176280#M6894</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2011-01-18T11:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176281#M6895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;&amp;gt; Tom, just one question about your routine above:&lt;/P&gt;&lt;P&gt;&amp;gt; If you define a one-element array &lt;STRONG&gt;uint32 i[1]&lt;/STRONG&gt; then the first element is accessed&lt;/P&gt;&lt;P&gt;&amp;gt; as &lt;STRONG&gt;i[0]&lt;/STRONG&gt;, the 2nd element is &lt;STRONG&gt;i[1]&lt;/STRONG&gt;, so should the references to &lt;STRONG&gt;i[2]&lt;/STRONG&gt; as stack&lt;/P&gt;&lt;P&gt;&amp;gt; frame pointer in fact be &lt;STRONG&gt;i[1]&lt;/STRONG&gt; ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;No. The array is there to get the address of where the stack pointer is.&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;Backtrack a bit. Say your code is running, there are variables on the stack and the stack pointer is currently pointing to just under the last of them. They you get an interrupt. An "Exception Stack Frame" is pushed onto the stack. Search for that in your Reference Manuals. It consists of one 32-bit word for the interrupted Program Counter and then one word for the Status, Format, Vector and Status Register. Then you end up in your interrupt service routine. It pushes the Frame Pointer on the stack, allocates the local variables (in this case "i[1]"), saves the registers and leaves the stack pointer pointing under that.&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;Here's the disassembly. You should do the same to your code and make sure it is similar, or if anything else has snuck in, or if it is using a different calling convention. I'm using CodeSourcery's gcc-based build system running under Cygwin, so "m68k-elf-objdump is what I use to get a dissassembly. Your tools may do this from within the gui, or you might be able to disassemble within the debugger more easily:&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;&lt;PRE&gt;$ m68k-elf-objdump -S interrupt.o | less
...
__attribute__((interrupt_handler))
static void int_spur_isr( void )
{
   0:   4e56 ffdc       linkw %fp,#-36
   4:   48d7 033f       moveml %d0-%d5/%a0-%a1,%sp@
   8:   242e 0004       &lt;STRONG&gt;movel %fp@(4),%d2 &amp;lt;&amp;lt;&amp;lt;&amp;lt;---- Stacked first word&lt;/STRONG&gt;
   c:   701c            moveq #28,%d0
   e:   2602            movel %d2,%d3
  10:   e0ab            lsrl %d0,%d3
  12:   2802            movel %d2,%d4
  14:   103c 0012       moveb #18,%d0
  18:   e0ac            lsrl %d0,%d4
  1a:   2202            movel %d2,%d1
  1c:   103c 0018       moveb #24,%d0
  20:   e0a9            lsrl %d0,%d1
  22:   2002            movel %d2,%d0
  24:   2a2e 0008       &lt;STRONG&gt;movel %fp@(8),%d5 &amp;lt;&amp;lt;&amp;lt;&amp;lt;----- Stacked PC
&lt;/STRONG&gt;  28:   2f05            movel %d5,%sp@-
  2a:   2f03            movel %d3,%sp@-
  2c:   760c            moveq #12,%d3
  2e:   4240            clrw %d0
  30:   4840            swap %d0&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;So in this simplistic case, i[0] is the variable, i[1] is outside of the bounds of our array - that 's the trick, but is the stacked Frame Pointer, i[2] is the SR/Status/Format/Vector, i[3] is the program counter and i[4] is looking back into the previous stack frame.&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;&lt;BR /&gt;Where it all goes wrong is if you have "indirect interrupt service routines" and you've put your code in a function that is called from the real interrupt service routine. There'll be another stack frame in there in that case. likewise if you have more local variables and the compiler doesn't make "i[1]" the FIRST one, but puts something else in front of it (it is allowed to). You should make the ISR *VERY* simple, only containing "i[1]} and call through to another function to do the printing. You have to disassemble the function to find out where "fp" (the Frame Pointer) is pointing to, and then use i[2], i[3], i[4] or whatever matches your code and compiler and so on.&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;But you have a debugger so why not set a breakpoint and ask it where you are?&lt;/DIV&gt;&lt;DIV class="lia-component-body lia-message-body"&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt; FS = 0x00000000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt;&lt;/STRONG&gt; &lt;STRONG&gt;Vector = 0x00&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt;&lt;/STRONG&gt; &lt;STRONG&gt;Format = 0x00&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt;&lt;/STRONG&gt; &lt;STRONG&gt;PC = 0x00000001&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt;&lt;/STRONG&gt; &lt;STRONG&gt;SR = 0x0105&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;gt;&lt;/STRONG&gt; Which doesn't seem quite right to me (as in I don't entirely believe the answer).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That means i[2] is 0x00000105 and i[3] is 0x00000001.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd expect 0x418020xx for the first word and something within your code space for the second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why not dump from i[1] to i[30] in hex and look for matching patterns? Some of the words should match to addresses in your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you call in someone who has done this before? Assembly level debugging is a very steep leaning curve. "Higher" language programmers&amp;nbsp; (even PHP &lt;IMG alt="Smiley Happy" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="https://community.nxp.com/i/smilies/16x16_smiley-happy.png" title="Smiley Happy" /&gt; never need to know this stuff."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:25:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176281#M6895</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2020-10-29T09:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176282#M6896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again Tom, more excellent advice. It's been a long time since I touched asm (6502 &amp;amp; Z80 when they were still just about current!) I thought the way of things these days was to get a Java machine running on it and then forget all about that low-level nonsense &lt;IMG alt=":smileytongue:" class="emoticon emoticon-smileytongue" id="smileytongue" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-tongue.gif" title="Smiley Tongue" /&gt; I'm still amazed by the state of things these days - using an arduino to flash an LED &lt;IMG alt=":smileysurprised:" class="emoticon emoticon-smileysurprised" id="smileysurprised" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-surprised.gif" title="Smiley Surprised" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try your suggestions for proper handling of the mask/unmask routine and debug dump, I'm learning through necessity here (often the best way to learn, if not most relaxing), unfortunately on this project we are "the guys who know about stuff" so have to work it out ourselves.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 19:12:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176282#M6896</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2011-01-18T19:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176283#M6897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, the latest is that I went through all the code, scattered the proper disable-store-twiddle-enable code liberally about whenever I found the IMR or peripheral interrupt registers being modified and so far there's been no more spurious interrupts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hesitate to say "problem solved" (very difficult with intermittent faults of any sort) but it certainly looks like a great leap in the right direction. Plus I've learned a thing or two along the way, so a good result all round.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers Tom!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jan 2011 03:49:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176283#M6897</guid>
      <dc:creator>FridgeFreezer</dc:creator>
      <dc:date>2011-01-20T03:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: MCF52259 Spurious interrupt, help tracking it down</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176284#M6898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad to help. Check your Forum private mailbox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jan 2011 15:05:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF52259-Spurious-interrupt-help-tracking-it-down/m-p/176284#M6898</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2011-01-21T15:05:41Z</dc:date>
    </item>
  </channel>
</rss>

