Hello all!
MCU is a K32L2A41
On flashing the chip via Cyclone debugger, the code flashes and breakpoint at main() correctly. Continuing to run the code, everything starts up correctly including TMP2 (called ‘WAIT1MS’ peripheral).
This is used for a 1ms general timer, set to interrupt every 1ms and deduct from a few systems counters as long as they are > 0.
/* Clear interrupt flag.*/
WAIT1MS_PERIPHERAL->CNT = 0;
uint32_t intStatus;
/* Reading all interrupt flags of status register */
intStatus = TPM_GetStatusFlags(WAIT1MS_PERIPHERAL);
TPM_ClearStatusFlags(WAIT1MS_PERIPHERAL, intStatus);
/* Enable interrupt WAIT1MS_IRQN request in the NVIC */
EnableIRQ(WAIT1MS_IRQN);
Here is the IRQ Handler:
/* TPM2_IRQn interrupt handler */
void WAIT1MS_IRQHANDLER(void) {
uint32_t intStatus;
/* Reading all interrupt flags of status register */
intStatus = TPM_GetStatusFlags(WAIT1MS_PERIPHERAL);
/* Place your code here */
if(Cpu_Delay1000US){Cpu_Delay1000US--;}
if(sendLegacy_McuWait_ms){sendLegacy_McuWait_ms--;}
/* Clear interrupt flag.*/
TPM_ClearStatusFlags(WAIT1MS_PERIPHERAL, intStatus);
} /* end of WAIT1MS_IRQHANDLER */
Everything runs as expected.
PROBLEM- ON THE FIRST RUN ONLY from factory new:
On a new PCB with a factory new chip, the 1st flash does NOT work initially.
The code flashes, starts up, runs through main() correctly, everything starts up correctly until TMP2 is set up, just before it’s first needed, before the main forever-loop.
As soon as it executes EnableIRQ(WAIT1MS_IRQN);
(which is NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); in the core_cm0plus.h code)
it throws the 'signal handler' and hangs up. It is still connected to the Cyclone and if I simply click the "Restart" button in MCUXpresso, the code restarts and runs perfectly as expected (no SIGINT issue).
When the code stops on the 1st flash, this is what is shown for Fault and Exception. In my code above, I have tried to clear any pending interrupts and reset the count before EnableIRQ (I was initially just allowing MCUXpresso to set this up fully from Peripheral code generated).
CS2030-K32v1.axf
Thread #1 (Suspended : Signal : SIGINT:Interrupt)
0x1c00429c
<signal handler called>() at 0xfffffff9
__NVIC_EnableIRQ() at core_cm0plus.h:750 0x7348
EnableIRQ() at fsl_common_arm.h:535 0x1c5cc
main() at CS2030-K32.c:352 0x78f4
ipsrfaults 0x24Interrupt Program Status Register
Exception Number 0x8 Indicates which exception the processor is handling
After this initial flash and run, with SIGINT error, I seem to be able to run the code any time from cold start, with or without the debugger, power off/on, as well as re-flash with code changes (as I debug other parts of my code) and it just starts up as expected. It is just on this very FIRST flash, from factory new, that the system hangs on this SIGINT.
Rather than just shrug it off as "well, it's fine after the 1st flash, just one of those things", I want to understand what's wrong and correct it properly of course, before deploying as a finished product. It happens on every single new PCB/factory-new chip I try it on. Once it happens, I cannot duplicate it on that same PCB, only happens on that first flash.
Please let me know what you think, my dear fellow NXP lovers!
Happy to provide additional detail, but these bits seemed most relevant.
<jeff>