How to create an FreeRTOS project with MCUXpresso IDE

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

How to create an FreeRTOS project with MCUXpresso IDE

How to create an FreeRTOS project with MCUXpresso IDE

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.

pastedImage_3.png

Quick Start

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

pastedImage_5.png

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

pastedImage_6.png

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.

pastedImage_7.png

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.

pastedImage_8.png

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.

pastedImage_10.png

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.

pastedImage_11.png

Go to menu Run> Debug configurations…

pastedImage_12.png

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

pastedImage_14.png

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

pastedImage_15.png

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

pastedImage_16.png

 

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

Comments

A project that is configured to build a simply blink demo will still build all the source files used by the comprehensive demo, even though the simply blink functionality is contained within the single file MyBKExperience.

MCUXpresso is really giving me a headache. If I create a new FreeRTOS project for my board (IMX1050 RT), trying to compile the empty project gives me this error:

In file included from ../usb/include/usb.h:15:0,

                 from ../usb/host/usb_host.h:12,

                 from ../usb/host/usb_host_framework.c:10:

../osa/usb_osa.h:77:10: fatal error: usb_osa_bm.h: No such file or directory

I traced it down to this ifdef in usb_osa.h:

/* Include required header file based on RTOS selection */

#if defined(USB_STACK_BM)

#include "usb_osa_bm.h"

#elif defined(USB_STACK_FREERTOS)

#include "usb_osa_freertos.h"

But where is USB_STACK_FREERTOS defined? Looking at an RTOS usb example, I discovered it in the XML .cproject file. However, a new RTOS project doesn't correctly include these preprocessor definitions.

In this case, I can find and fix the solution, but chasing down these bugs in the IDE is exhausting. Just a heads up..

The SDK examples are defining these defines in the compiler settings, e.g.

pastedImage_1.png

I hope this helps,

Erich

No ratings
Version history
Last update:
‎11-06-2018 12:50 AM
Updated by: