This article describes how to configure a peripheral timer in a FreeRTOS project with MCUXpresso config tools.
In this article, I’m using the following:
MCUXpresso IDE 10.2.1 www.nxp.com/mcuxpresso
MCUXpresso SDK 2.4.1 for Frdm-k66f board. With Amazon FreeRTOS v10 .
You can get it from https://mcuxpresso.nxp.com
FRDM-K66 board www.nxp.com/frdm-k66f
First make sure you have a working FreeRTOS project. Please refer to below link for creating a new FreeRTOS project.
https://community.nxp.com/docs/DOC-341972
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
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;
}
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.
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)
{
milisecondCounts++;
ftmIsrFlag = false;
if (milisecondCounts >= secondLoop)
{
PRINTF("%c", signals[cnt & 1]);
cnt++;
if (cnt >= loop)
{
cnt = 0;
}
milisecondCounts = 0U;
}
}
__WFI();
}
}
console output:
For information about how to use MCUXpresso pins tool in a FreeRTOS project, please see the following document.
https://community.nxp.com/docs/DOC-341987
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?
Thanks
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.
Regards
Daniel