KL17 Disable _NMI during boot only?

cancel
Showing results for 
Search instead for 
Did you mean: 

KL17 Disable _NMI during boot only?

243 Views
mitch1
Contributor II

Hey there NXP community, I could use some help!

I've been attempting to get _NMI to be disabled during boot, to no avail.

I've looked at:

Disable NMI_b pin/interrupt KL04Z? 

How to configure Flash Configuration setting from program to protect/un-protect the FRDM-K82F Board? 

and of course the manual: http://cache.freescale.com/files/32bit/doc/ref_manual/KL17P64M48SF6RM.pdf 

Here's my scenario, I'm using _NMI for another IC to wake the MCU and begin interaction. With debugger attached (using openOCD debugger if it matters) I have no problems, I assume because _NMI is stable in the high state. However, when I remove the debugger and plug it in, the app never starts. I'm assuming this is due to _NMI triggering. I've attempted editing the Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3FFE}; field in startup, but no matter what I do, FOPT is coming back with 0xFF (as inspected through the debugger). 

So what I need, I need _NMI to be disabled during initial bootup, and (to my understanding) for it to be enabled after initial boot so it can wake the mcu from sleep. What am I missing here?

See:

With debugger attached, you can see the app come alive (pin goes high). Then the external IC signals _NMI periodically. No problems.

with_debugger.png

No debugger attached, there is a short assert of _NMI, and the app never starts. (Note the quick assertion of _NMI at VCC on does happen with debugger attached too, but it doesn't matter because it is stable when debug is launched). 

NO_DEBUGGER.png

0 Kudos
1 Reply

127 Views
mjbcswitzerland
Specialist V

Mitchell

If you disable the NMI via the flash options (may be due to the debugger you use not allowing you to program the pattern - check it with the memory viewer) you will not be able to later use it for your application - therefore you can't disable it.

You need instead to handle the (spurious) NMI and in its default handler reconfigure the pin's function so that no more NMIs occur.

Later, when the input is stable and you want to use it you can reconfigure it for the NMI function and install a different NMI handle according to your application requirements.

Below is the code to do this from the uTasker KL17 project.

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

// Default NMI interrupt in vector table
//
static __interrupt void irq_NMI(void)
{
    // This is executed immediately out of reset if the NMI line is enabled and held low
    //
    _CONFIG_PORT_INPUT_FAST_LOW(A, PORTA_BIT4, PORT_PS_UP_ENABLE);       // set the NMI line to an input to remove the NMI function and allow the processor to continue
}


// Allow the user to enter an NMI handler, ensuring that the NMI pin is configured as NMI function
// - note that the NMI may not have been disabled to allow this to work
//
extern void fnEnterNMI(void (*_NMI_handler)(void))
{
    VECTOR_TABLE *ptrVect = (VECTOR_TABLE *)VECTOR_TABLE_OFFSET_REG;
    ptrVect->ptrNMI = _NMI_handler;                                       // enter interrupt handler
    _CONFIG_PERIPHERAL(A, 4, (PA_4_NMI | PORT_PS_UP_ENABLE));             // enable the NMI function on the pin
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos