NXP Kinetis K12 - FreeRTOS Flextimer

Hi, I am using MK12DX256VLH5 running on FreeRTOS.

I am trying to generate a 20kHz tone using FTM0 channel 2.

I tried with my code below but doesn’t seem to work.

Is someone able to help to advise if I did any mistake?

Thank you.

void Init_FTM(void)
{
ftm_config_t ftmConfig
ftm_chnl_pwm_signal_param_t ftmParam;

/* Configure ftm params with frequency 20kHZ */
ftmParam.chnlNumber = (ftm_chnl_t)kFTM_Chnl_2;
ftmParam.level = kFTM_LowTrue;
ftmParam.dutyCyclePercent = 50U;
ftmParam.firstEdgeDelayPercent = 0U;

/* Get FTM Config & Init FTM */
FTM_GetDefaultConfig(&ftmConfig);
ftmConfig.pwmSyncMode = kFTM_HardwareTrigger_0;
FTM_Init(FTM0, &ftmConfig);

FTM_SetupPwm(FTM0, &ftmParam, 1U, kFTM_CenterAlignedPwm, 20000U, kFTM_SystemClock);
FTM_EnableInterrupts(FTM0, kFTM_Chnl_2);
FTM_StartTimer(FTM0, kFTM_SystemClock);
}

void FTM_0_HANDLER(void)
{
/* Clear interrupt flag.*/
FTM_ClearStatusFlags(FTM0, kFTM_TimeOverflowFlag);
ftmIsrFlag = true;
}

int main(void) {

    /* Init board hardware. */
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();

    Init_FTM();

    while(1) {

    	if (ftmIsrFlag)
    	{
    		ftmIsrFlag = false;
            printf(" -- ");
    	}

    }

Hi,
The main function needs to call

vTaskStartScheduler ();

to start FreeRTOS, and let it be able to schedule threads and timers.
the call to vTaskStartScheduler should be the last call as it never returns.

Hope this solves it for you!

It seems that you are trying to use hardware timer without FreeRTOS. If so, I’d suggest to ask on NXP forums as this is not related to FreeRTOS.