An example to configure a peripheral timer in an FreeRTOS project

Showing results for 
Show  only  | Search instead for 
Did you mean: 

An example to configure a peripheral timer in an FreeRTOS project

An example to configure a peripheral timer in an FreeRTOS project

This article describes how to configure a peripheral timer in a FreeRTOS project with MCUXpresso config tools.

Software and Tools

In this article, I’m using the following:

MCUXpresso IDE 10.2.1

MCUXpresso SDK 2.4.1 for  Frdm-k66f  board.  With Amazon FreeRTOS v10 .

You can get it from

FRDM-K66 board

First make sure you have a working FreeRTOS project. Please refer to below link for creating a new FreeRTOS project.

To open the tool, simply right click on the project in Project Explorer and select the appropriate Open command:


With the peripheral Tool, we can use it to configure initialization of selected peripherals and generate code for them. we are picking the FTM0 timer ,of course we could use any other timer too.



Click OK, then configure the timer to 10KHz.


We will use the timer interrupt to increase a counter, so don’t forget to turn on the interrupt


To update the generated code in the related tool chain project, click the Update Project button.



Click OK, new code will be generated. Please check peripheral.c & peripheral.h


Timer ISR

Next we add the timer interrupt code to the application.

#include "fsl_ftm.h"



 * Variables


volatile bool ftmIsrFlag = false;

volatile uint32_t milisecondCounts = 0U;




void FTM_1_IRQHANDLER(void)


    /* Clear interrupt flag.*/

    FTM_ClearStatusFlags(FTM0, kFTM_TimeOverflowFlag);

    ftmIsrFlag = true;


Adding Timer Drivers

The project won’t compile yet, because the necessary drivers are not part of the project yet. To add them, use the ‘Manage SDK components’ button:


Then check the ftm driver and press OK and get the extra driver sources added to the project.



We can see that fsl_ftm.c & fsl_ftm.h added into this project.


Adding timer to FreeRTOS application:

In this task, the FTM interrupt will trigger a message printed to the terminal


 * @brief Task responsible for printing message with FTM0.


static void my_task(void *pvParameters)



    uint32_t cnt;

    uint32_t loop = 2U;

    uint32_t secondLoop = 1000U;

    const char *signals = "-|";


    cnt = 0;


    while (true)


        if (ftmIsrFlag)



            ftmIsrFlag = false;

            if (milisecondCounts >= secondLoop)


                PRINTF("%c", signals[cnt & 1]);


                if (cnt >= loop)


                    cnt = 0;


                milisecondCounts = 0U;






Run the demo

console output:


For information about how to use MCUXpresso pins tool in a FreeRTOS project, please see the following document.

For information about how to create an FreeRTOS project with MCUXpresso IDE, please see the following document 


Hi Daniel,  when I click the 'open peripheral' , I can't see the peripherals view, as below, why?     



Hi David:

Maybe you closed the peripherals view, please open it as below.


click other...

input peripherals, then click open, you will see the peripherals view.




No ratings
Version history
Last update:
‎11-06-2018 10:42 PM
Updated by: