I have written the NMI handler for the LPC1768 MCU based target board as below and I am using Keil MDK Lite v4.5. The CPU control enters the NMI handler when invoked by a logic High signal injected to P2.10 but, the issue is upon exit the CPU control loops in the HardFault_Handler implemented in the startup_LPC17xx.s file. Stack memory is set for 100 bytes. Also,is it possible to simulate NMI implementation in Keil MDK v4.5, i have tried it but no success.
void NMI_Handler (void){ LPC_GPIO1->FIOPIN |= (1<<29); delay(); LPC_GPIO1->FIOPIN &= ~(1<<29); } int main (){ //Configuring GPIO P1.29 as Output to which an LED is interfaced LPC_PINCON->PINSEL3 &= ~((1<<27)|(1<<26)); LPC_GPIO1->FIODIR |= (1<<29); LPC_GPIO1->FIOPIN &= ~(1<<29); //Configuring P2.10 as NMI pin LPC_PINCON->PINSEL4 &= ~(1<<20); LPC_PINCON->PINSEL4 |= (1<<21); //Enable NMI NVIC_EnableIRQ(NonMaskableInt_IRQn); while(1); }
Remember that an enable command need not be responsible for a failure - if it enables broken code it will be the broken code that will hurt. And there are also often a number of setup steps needed before an "enable" is allowed.