MKL02Z32xxx4 (FRDM-KL02Z Board) Timer overflow interrupt not firing

43 Views Asked by At

I never get into the TPM0_IRQHandler() it's supposed to call. However, all of the register seem to be set, even the Timer Overflow Flag register when the timer actually overflows. So appears it just doesn't know where the IRQ handler is located, but the vector table looks okay.

I then tried an SDK example and it shows the same behavior. Pretty confident it isn't my code now. Not sure where else to look on why this might not be working.

void initTimer()
{
    tpm_config_t tpmConfig;
    TPM_GetDefaultConfig(&tpmConfig);
    tpmConfig.prescale = kTPM_Prescale_Divide_128;

    NVIC_SetPriority(TPM0_IRQn, 3);
    NVIC_EnableIRQ(TPM0_IRQn);

    TPM_Init(TPM0, &tpmConfig);

    uint32_t tpmClock = TPM_SOURCE_CLOCK;
    uint32_t timerPeriod = USEC_TO_COUNT(1000U, tpmClock) / 128; // 1ms

    TPM_EnableInterrupts(TPM0, kTPM_TimeOverflowInterruptEnable);

    TPM_SetTimerPeriod(TPM0, timerPeriod);
    TPM_StartTimer(TPM0, kTPM_SystemClock);
}

volatile uint32_t elapsedTime = 0;

void TPM0_IRQHandler()
{
    TPM_ClearStatusFlags(TPM0, kTPM_TimeOverflowFlag);
    elapsedTime++;

    printf("Elapsed time: %d\n", elapsedTime);

    if (elapsedTime >= 1000) // 1 ms has passed
    {
        elapsedTime = 0;
        // Toggle the LED_RED GPIO here
        // Example code assuming GPIO is already configured:
        GPIO_PortToggle(BOARD_INITPINS_LED_RED_GPIO, 1u << BOARD_INITPINS_LED_RED_PIN);
    }
}

Should be a pretty straightforward setup, any advice would be appreciated. I'm not even sure what else to check.

I'm using MCUXpresso (latest)

0

There are 0 best solutions below