Hi
I have one critical HW INT and plan to adapt to PD7 as NMI.
Is there any sample code to refer how to implement?
thanks
Gavin
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi
I have one critical HW INT and plan to adapt to PD7 as NMI.
Is there any sample code to refer how to implement?
thanks
Gavin
Amit Ashara said:Enable the GPIO PD7, GPIODEN register bit for Digital function.
Hi Amit,
Of course you're blameless in this (on-going) "NMI-hiccup" situation - but is it not strange - and inconsistent - that the default setting of NMI appears "incomplete?" (that conclusion based upon the (seeming) necessity to attend to GPIODEN.)
Would it not have been far simpler - and more proper - to default the NMI pin "all the way" into NMI "readiness" - and not leave yet another pitfall (GPIODEN) for (already) hapless users?
As an aside - iirc - we once employed the NMI successfully w/in LX4F (may they rest in peace) and I can't recall, "jumping thru the GPIODEN hoop!" Due to the (apparent) "incomplete default set-up" and our (long past) anecdotal finding - are you quite sure that GPIODEN must be tweaked to achieve NMI functionality?
Hi Amit
About Step.3, you mean that enabling PD7 as interrupt pin and setting GPIODEN register only.
Do I get the wrong understanding?
Do I need to unlock PD7?
thanks
Gavin
My first thought is. Are you really, really, really sure you need an NMI for this? NMIs look attractive for high priority interrupts but they are a double edged sword with a really sharp blade.
The Cortex interrupt structure allows for prioritizing interrupts. In every case I can think of for a HW interrupt you would bring in on an external interrupt line you would be better off reserving the highest priority (non-NMI) interrupt level for your HW interrupt. That gives you almost all of the benefits of an NMI with none of the hazards. In my experience the additional benefits you get from an NMI are better obtained in another fashion in most cases.
Robert
Certainly, although I may ramble a bit.
Summary: In the worst case an NMI resembles a HCF (Halt and Catch Fire) instruction.
Let's take a step back. Consider what the basic characteristic of an interupt is. An interrupt stops the current execution (on some processors this can be in the middle of an instruction) and switches to a new set of instructions. That is a rather severe action to take and it has consequences
Now with standard interrupts all these consequences can be dealt with
The simple setup works well for most cases as long as the critical sections are kept short. Interrupts respond within the time of the longest critical section + the longest interrupt sequence tht can occur and the consequences of the interrupts can be managed. The problem occurs when you need a faster interrupt response than the longest critical time. Traditionally there have been two methods of dealing with this
These techniques can be used together.
Some people are tempted to use an NMI as the highest priority interrupt but consider what that means.
Because the NMI is not maskable there is no way to create a critical section. There is really no recovery action you can safely take. You can safely read memory and I (as long as the inputs are not modified by the read). You can safely write memory or output but only as long as no other interrupt or procedure in the code writes to that location or output. And you can use single instruction non-interruptable RMW sequences in both the main application and the NMI if you are careful. Anything else will create a race condition. The only other possible safe actions are to reset the processor or come to a complete halt.
Even that subset is not necessarily safe. Since the NMI is not maskable it can interrupt itself. There is a set of consequences from this
It is only possible to prevent multiple reoccurences in hardware. If the NMI is being used for something like a shutdown that can usually be done in H/W as easily as preventing re-triggers of the interrupt allowing extra time to respond.
The good news is that with the priority scheme and number of available interrupts there is very little reason (I think none) to use an NMI.
And, yes, I have literally seen an NMI emulate an HCF instruction.
Robert
Well - that's one possibility, Amit. (but - rather outside Robert's main thrust - I believe)
Why do two NMI (as default) pins exist? Would not ONE cause sufficient "pain/suffering" to the 95%+ of users who have no knowledge of - nor need for - NMI?
Robert argues against the need for any NMI - but those seeking that fine detail are few - and far between. Surely the removal of those pins from, "Default to NMI" would meet Robert's - and so many other users' - approval... And avoids the always problematic, "featured post!" (how many find - read - comply with those?)
Just as the (famed) 0-ohm Rs strike fear/disarray into new L-Pad users - should not the NMI pins be cast as normal GPIO - with the option to, "Order them into NMI - by those users - skilled enough to require such?" (ANS: mais certainement!)
Same method would "fix" those 0-ohm Rs - compatibility is nice - but pack those Rs in a bag - to be installed (only) by those seeking such! (a very clear minority - by any fair reading of user 0-ohm ills - long (& repeatedly) - reported here...)
Of course - Robert & this reporter represent "NIH" - our ideas will never "see light of day" - and festering sores (invented HERE) will claim more victims...
Amit Ashara said:
Indeed. We should make this a featured post?
You may feel free to do so if you wish.
You may be in danger of running out of room for such items with the large font though ;)
Robert
cb1- said:Robert argues against the need for any NMI
Yep, although I think that ship has sailed for this processor.
The presence on an NMI did give me a little pause when selecting the chip for use, but only a little. The ever-reoccuring configuration issues do argue against including it in future devices.
Robert
Amit Ashara said:I would be consolidating a lot of the Sticky Posts and sending them over for Application Note or Integrating into existing Sticky Notes...
But - as this poster has proved (and hundreds before him) - have not the "Sticky Notes" and (likely) unfound & unread App Notes - proved an abject failure?
Believe that General Custer - returning to "Little Big Horn" - outnumbered & outmaneuvered by skilled foe - would meet same (overwhelming) defeat.
And too - the "Band-Aid parade" of (too often ignored) sticky notes and (where are they now) App Notes - which may not precisely define their subject matter...
Pretending such a fundamental flaw can be fixed by (yet more) of the same, failed, past techniques makes almost no sense! (we seem NOT to learn/adapt!)
As "proof" - look @ the subject of this thread - it's completely devoid of PF0/PD7 mention! Would rushed/frustrated user "ever" think to read this - to escape his inability to bring PF0/PD7 to GPIO Life?
I'll bring the bass drum, Robert the bugle, Amit the stickies (and failed/hapless posters the tears!) - let the "Band-Aid Parade" begin...
cb1, you are quite right that an app note won't prevent people from asking about PF0/PD7. What it does do is give a common place to point to. "Here go read this, come back if it leaves any questions". If such a note mentions multiple traps for the unwary it may prevent the need subsequent questions.
I know, when I was starting, such notes saved me many an hour. Less so now when answers can be reached for with a few caresses of the keyboard. I'm afraid there are only a few of us left who actually read datasheets and user manuals fully. That's generally to our advantage I think, although even after reading it is quite possible to miss the significance of an offhand sentence.
Robert