element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog PSoC 6 and ModusToolbox: Create a FreeRTOS 10.3 Project
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 27 Feb 2021 11:03 AM Date Created
  • Views 6790 views
  • Likes 11 likes
  • Comments 11 comments
  • infineon
  • modustoolbox
  • psoc 6
  • psoc_6
  • psoc6
  • freertos
  • cypress
Related
Recommended

PSoC 6 and ModusToolbox: Create a FreeRTOS 10.3 Project

Jan Cumps
Jan Cumps
27 Feb 2021

The steps to create an empty PSoC 6 project and run FreeRTOS on the CM4 core.

image

 

It's easy to set up a FreeRTOS project in ModusToolbox. The simplest way is to start from one of the examples of the IDE's Application Creator.

But adding FreeRTOS to a project is straightforward too. And it allows you to select the newest version. In my case 10.3.

 

Start an empty project

File > New > ModusToolbox Application

image

Select the PSoC empty project for your board:

image

I use the WiFi BT prototyping kit, so I selected that one. Press Next.

Look up and select the empty project. Rename it (I used PSoC6_FreeRTOS_10_3). Press Create.

image

Once the wizard generated the project, press Close and return to the IDE.

 

Add FreeRTOS 10.3

 

With the project active, select the Library Manager in the Quick Panel.

image

 

On the Libraries tab, select freertos, shared, and version 10.3.1 release (or the version you want to use).

image

Click Update, then Close when finished. Return to the IDE.

 

Then, add a FreeRTOSConfig.h file to your project. You do that by copying the one from the shared FreeRTOS area into your project:

image

 

Paste this in the root of your project.

Then open that copied file, and remove the "#warning This is a template. Copy this file to your project and remove this line" line.

 

As last step in the preparation, add this to the include section of your main.c file:

 

#include "FreeRTOS.h"

 

Edit the Make file

 

Now a step that was not needed for the rtos version 10.1xxx. But if you don't do it for 10.3, your build will fail:

Open the Makefile by double-clicking it. You find it in the root of your project.

Update the COMPONENTS section:

 

COMPONENTS=FREERTOS

 

image

 

Now that we are in the make file, let's also change the name of the output file. It's called mtb-example-psoc6-empty-app by default. See the orange part of the image above.

 

APPNAME=mtb-example-psoc6-freertos-10-3-app

 

When you change the output file name, you need to update the execution configuration.

You do that by, after saving the make file,  clicking the Generate Launches option in the Quick Panel. See the blue part in the image.

 

This is a good time to do a first build. If it succeeds, you know you have a good start.

 

Add a Task and Start FreeRTOS

 

We're going to make a blinky (I tried to keep that a secret until the end of the post image ).

Our project will have one FreeRTOS task that will toggle the led every time it's activated by the scheduler.

 

The Task

 

I will discuss the task first, and then the activities to configure the LED and schedule the task.

 

void task_blink(void* param) {
  /* Suppress warning for unused parameter */
  (void) param;

  /* Repeatedly running part of the task */
  for (;;) {
    cyhal_gpio_toggle(CYBSP_USER_LED);
    vTaskDelay(pdMS_TO_TICKS(1000));
  }
}

 

The task is very simple. A LED is toggled, and the task yields to the RTOS scheduler for one second. In an ever lasting loop.

The effect is that the led will blink every 2 seconds:

  • LED toggle
  • yield for a second

During the Delay, the task is inactive and the scheduler can execute other tasks.

This is different to delay mechanisms that use MCU ticks to burn time. Those occupy the MCU for a second. The FreeRTOS vTaskDelay() task frees the MCU for a second.

 

I've put the task in a separate header and source file:

 

task_blink.h

#ifndef SOURCE_TASK_BLINK_H_
#define SOURCE_TASK_BLINK_H_

#include "FreeRTOS.h"
#include "task.h"

void task_blink(void* param);

#endif /* SOURCE_TASK_BLINK_H_ */

 

task_blink.c

#include "cybsp.h"
#include "cyhal.h"
#include "FreeRTOS.h"
#include "cycfg.h"
#include "task_blink.h"

void task_blink(void* param) {
  /* Suppress warning for unused parameter */
  (void) param;

  /* Repeatedly running part of the task */
  for (;;) {
    cyhal_gpio_toggle(CYBSP_USER_LED);
    vTaskDelay(pdMS_TO_TICKS(1000));
  }
}

 

The Scheduler

 

In the main() function, create and register the task, then start the scheduler:

 

  xTaskCreate(task_blink, "blink task", configMINIMAL_STACK_SIZE,
    NULL, configMAX_PRIORITIES - 7, NULL);

  vTaskStartScheduler();
  /* RTOS scheduler exited */
  /* Halt the CPU if scheduler exits */
  CY_ASSERT(0);

  for (;;) {
  }

 

The first call registers our task. The constants in the parameters are defined in the FreeRTOSConfig.h file you placed in the project root.

Then the scheduler is started. In a FreeRTOS project, this call is going to be active forever. Any line of code below that should never run.

 

The last thing to discuss here is that the hardware has to be initialised before it will be used. In our case, the LED:

 

    /* Initialize the User LED */
    result = cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT,
                             CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);

    /* GPIO init failed. Stop program execution */
    if (result != CY_RSLT_SUCCESS)     {
        CY_ASSERT(0);
    }

 

You may have to adapt this (and the task) to use an LED that's available on your board. I think that CYBSP_USER_LED is available on all evaluation kits, but I'm not sure.

 

main.c

#include "cy_pdl.h"
#include "cyhal.h"
#include "cybsp.h"

#include "FreeRTOS.h"
#include "task.h"

#include "task_blink.h"

int main(void) {
  cy_rslt_t result;

  /* Initialize the device and board peripherals */
  result = cybsp_init();
  if (result != CY_RSLT_SUCCESS) {
    CY_ASSERT(0);
  }

  /* Initialize the User LED */
  result = cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT,
      CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);

  /* GPIO init failed. Stop program execution */
  if (result != CY_RSLT_SUCCESS) {
    CY_ASSERT(0);
  }

  __enable_irq();

  xTaskCreate(task_blink, "blink task", configMINIMAL_STACK_SIZE,
    NULL, configMAX_PRIORITIES - 7, NULL);

  vTaskStartScheduler();
  /* RTOS scheduler exited */
  /* Halt the CPU if scheduler exits */
  CY_ASSERT(0);

  for (;;) {
  }
}

 

This is it. Build the project, then execute it on your board.

The end result is a blinking LED.

 

The project I used for this post is attached.

 

PSoC 6 series
Create a Project with its own Board- and Module configurations
Low Power Management - prepare the board for current measurements
Power consumption without WiFi or Bluetooth
Create a FreeRTOS 10.3 Project
UART receiver with FreeRTOS
FreeRTOS message queue
UART receiver with FreeRTOS - Deep Sleep support
Attachments:
PSoC6_FreeRTOS_1_3.zip
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 4 years ago in reply to DAB +4
    Can you please stop rating my posts DAB? They are at the bottom of the e14 ratings because you tag a 3 star to virtually all of them. When I have a 5 star post on e14 with a typo, I don't fix the typo…
  • genebren
    genebren over 4 years ago +2
    Very nice write up on this FreeRTOS project. I had used FreeRTOS years ago, but I keep thinking that this is something that I need to re-learn and use in some of my projects. Thanks for the info!
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to genebren +2
    It hasn't changed that much. The number of supported controllers has increased significantly. But if you used it years ago, the same mechanisms still apply: - tasks - schedules - semaphores - queues and…
Parents
  • DAB
    DAB over 4 years ago

    Nice walk through Jan.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 4 years ago

    Nice walk through Jan.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to DAB

    Can you please stop rating my posts DAB? They are at the bottom of the e14 ratings because you tag a 3 star to virtually all of them.

    When I have a 5 star post on e14 with a typo, I don't fix the typo. Because it brings it on the top of the recent posts. Then you see it, and hopla, one or 2 stars down.

    It does not motivate me.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 4 years ago in reply to Jan Cumps

    Hi Jan,

     

    Sorry if my ratings are lower than you like.

    That said, my rating scale is intended to encourage everyone to do better.

    For perspective, over the decades I have sat through hundreds of presentations and I have read thousands of reports/posts/blogs.

    Yes my standards are high, but most people find the challenge of my scale sufficient to work towards another star or two.

     

    Would it motivate you if I provided a more detailed response and identify the areas in your posts that could be improved to get another star?

    I will try to remember not to rate your posts, but us older folks tend to forget, so please have patience.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube