How to create an FreeRTOS project with MCUXpresso IDE

Document created by Daniel Chen Employee on Nov 6, 2018
Version 1Show Document
  • View in full screen mode

This article is for beginners. It describes how to create an FreeRTOS project based on MCUXpresso IDE 10.2.1.

 

Software and 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

 

Before creating a FreeRTOS project, you have to install SDK first.

Download the SDK package SDK_2.4.1_FRDM-K66F.zip,  drag and drop it into the “Installed SDKs” view. You will be prompted with a dialog asking you to confirm the import –click OK. The SDK will be automatically installed into MCUXpresso IDE part support repository.

 

 

 

Quick Start

Go to the ‘QuickStart’ Panel in the bottom left of the MCUXpresso IDE window, and click new project.

 

On the “Board and/or device selection” page, select board frdmk66f. You will see some description relating to the your selection.

 

 

Click ‘next’…

You will see the basic project creation and setting page.

 

 

Basic setting

The project will be given a default name based on the MCU name. Name the project, select the right device package.

 

 

Board files: This field allows the automatic selection of a default set of board support files, else empty board files will be created.

Project type:  Selecting ‘C’ will automatically select Redlib libraries, selecting c++ will select NewllibNaro librarires.

Project option: enable semihost will cause the semihost variant of the chosen library to be selected;  CMSIS-Core will cause a CMSIS folder containing a variety of support code to be created.

OS: For a FreeRTOS project, make sure FreeRTOS is selected.

Please select the drivers and utilities according to your requirements.

 

Click ‘next’, you will go to advanced project settings page.

 

Advanced Project setting

 

This page will take certain default options based on settings from the first wizard project page.

 

Set library type:    Please use Redlib for C projects, and NewlibNarno for SDK C++ projects.

Next panel allows options to be set related to Input/Output.

Hardware settings: set options such as the type of floating point support available/required.

MCU C compiler:  Set various compiler options

Click ‘finish’ will create a simple ‘hello world’ C project for Freedom K66f . Basically does the initialization of the pins, clocks, debug console and peripherals.

 

int main(void) {

 

       /* Init board hardware. */

    BOARD_InitBootPins();

    BOARD_InitBootClocks();

    BOARD_InitBootPeripherals();

       /* Init FSL debug console. */

    BOARD_InitDebugConsole();

 

    PRINTF("Hello World\n");

 

    /* Force the counter to be placed into memory. */

    volatile static int i = 0 ;

    /* Enter an infinite loop, just incrementing a counter. */

    while(1) {

        i++ ;

    }

    return 0 ;

}

 

 

Click the project settings, we can see some basic information of this project, a right click on these nodes provides direct options to edit the associated setting.

 

 

 

Add FreeRTOS task

 

#include <stdio.h>

#include "board.h"

#include "peripherals.h"

#include "pin_mux.h"

#include "clock_config.h"

#include "MK66F18.h"

#include "fsl_debug_console.h"

/* TODO: insert other include files here. */

 

/* FreeRTOS kernel includes. */

#include "FreeRTOS.h"

#include "task.h"

 

 

/* TODO: insert other definitions and declarations here. */

 

 

 

 

 

/* Task priorities. */

#define my_task_PRIORITY (configMAX_PRIORITIES - 1)

/*******************************************************************************

 * Prototypes

 ******************************************************************************/

static void my_task(void *pvParameters);

 

 

/*!

 * @brief Task responsible for printing of "Hello world." message.

 */

static void my_task(void *pvParameters)

{

    for (;;)

    {

        PRINTF("Hello World!\r\n");

        vTaskSuspend(NULL);

    }

}

 

 

 

/*

 * @brief   Application entry point.

 */

int main(void) {

 

       /* Init board hardware. */

    BOARD_InitBootPins();

    BOARD_InitBootClocks();

    BOARD_InitBootPeripherals();

       /* Init FSL debug console. */

    BOARD_InitDebugConsole();

 

    if (xTaskCreate(my_task, "my_task", configMINIMAL_STACK_SIZE + 10, NULL, my_task_PRIORITY, NULL) != pdPASS)

    {

        PRINTF("Task creation failed!.\r\n");

        while (1)

            ;

    }

    vTaskStartScheduler();

 

    /* Enter an infinite loop, just incrementing a counter. */

    while(1) {

 

    }

    return 0 ;

}

 

 

Run the application

 

Build your application, go to menu Project > Build Project. Alternatively go to the quick start panel and click the hammer button.

 

 

Go to menu Run> Debug configurations…

 

Select the ‘Debug configuration’ that matches your connection type, in this example Segger Jlink is used. Then click ‘Apply’ and ‘Debug’

 

 

 

Open a terminal, select the appropriate port and set baudrate to 115200

 

 

 

Run the application, you will see “Hello world” in terminal

 

 

 

 

For information about configuring with MCUXpresso pins tool in an FreeRTOS project, please see the following document

https://community.nxp.com/docs/DOC-341987

 

For information about configuring with MCUXpresso peripheral tool in an FreeRTOS project, please see the following document.

https://community.nxp.com/docs/DOC-341986

Attachments

    Outcomes