I think we have found the issue. It has to do with the K81 or K82 NMI pin, which is connected to the IRQ pin of a PN5180 or PN5190 NFC frontend. This interferes with the flash configuration block, as set in startup_mk81f25615 or startup_mk82f25615. The default created from the SDK has the following:
//*****************************************************************************
// Flash Configuration block : 16-byte flash configuration field that stores
// default protection settings (loaded on reset) and security information that
// allows the MCU to restrict access to the Flash Memory module.
// Placed at address 0x400 by the linker script.
//*****************************************************************************
__attribute__ ((used,section(".FlashConfig"))) const struct {
unsigned int word1;
unsigned int word2;
unsigned int word3;
unsigned int word4;
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3DFE};
In this case:
- NMI_DIS bit is set, (NMI pin/interrupts reset default to 'enabled')
- BOOTPIN_OPT is not set (which forces Boot from ROM is BOOTCFG0 is asserted - requires RESET pin enabled)
Changing to:
- NMI is not set (NMI Interrupts are always blocked)
- BOOTPIN_OPT is set (requires BOOTSRC_SEL to be set)
- BOOTSRC_SEL is 00b (Boot from Internal Flash)
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF3BFE};
__NVIC_SystemReset() is now working.
(BTW, the reason why it worked after cycling power is because the FOPT register reverts to its unset state, 0xFFFFFFFF, after POR)