You are here

FreeRTOS PSoC Component | Cypress Semiconductor

FreeRTOS PSoC Component

[re-printed from]

This weekend I found myself down a rabbit hole, beating my head on the wall trying to make a USB driver work properly inside of Parallels & Windows 10 on my Mac (which I still don’t have quite right). While going through that excruciating process I ended up creating 3-4-5 different FreeRTOS PSoC projects, which although not difficult, is still a bit of a pain as it requires 1/2 dozen step. After reflecting on it a while I decided that I needed something easier. The obvious thing to do was to build a FreeRTOS PSoC Component, which I did, but eventually abandoned (I'll talk about that process in the next section). After the component idea was abandoned I decided to just make a template project that could be used to start a FreeRTOS PSoC Project (the next Article).

In this article I will show you:

  • An example project using a clever FreeRTOS PSoC Component that I found on GitHub built by E2ForLife
  • A discussion of the implementation details of that FreeRTOS PSoC Component
  • A discussion of problems with that implementation which lead me to build a template project.

FreeRTOS PSoC Component Example Project

When I first started looking at FreeRTOS I wasn’t totally sure where to start. When I googled FreeRTOS PSoC, one of the first hits was this repo which contains a PSoC Component that was built by “E2ForLife”. I really liked the idea of a component based FreeRTOS implementation, as all you would need to do is place the components… and then away you go. The more that I looked at the component the more that I liked what E2ForLife had done. When I cloned his repo, there was “nothing” in it, but it turns out there is another branch called “Implement-PSoC5” which makes me think that he was partially done (he hasn’t been changed since August 2015)

First, his example project. When you look at the schematic you see a nice looking FreeRTOS PSoC Symbol (obviously E2ForLife draws way better than me).

CY3295 Kit Image

When you double click the component you see all of the stuff that is normally in FreeRTOSConfig.h which you can set using the GUI instead of the FreeRTOSConfig.h

CY3295 Kit Image

When you “Generate Application” you can see that he setup all of the FreeRTOS files to come into the Generated Source automatically (though with different names)

CY3295 Kit Image

And his FreeRTOS PSoC Component example project is straight forward

#include <project.h>
xTaskHandle redTask;
xTaskHandle blueTask;
xTaskHandle greenTask;
void vRedTask( void* pvParameters);
void vGreenTask( void* pvParameters);
void vBlueTask( void* pvParameters);
int main()
    CyGlobalIntEnable; /* Enable global interrupts. */

void vRedTask( void* pvParameters)
    for(;;) {
        vTaskDelay( 125/portTICK_RATE_MS );
        RED_Write( ~RED_Read() );
void vGreenTask( void* pvParameters)
    for(;;) {
        vTaskDelay( 219/portTICK_RATE_MS );
        GREEN_Write( ~GREEN_Read() );

He built a function called “FreeRTOS_Start()” which installs the interrupt vectors then starts up the scheduler.

uint8 FreeRTOS_initVar = 0;
/* ------------------------------------------------------------------------ */
void FreeRTOS_Init( void )
    /* Handler for Cortex Supervisor Call (SVC, formerly SWI) - address 11 */
        (cyisraddress)vPortSVCHandler );
    /* Handler for Cortex PendSV Call - address 14 */
        (cyisraddress)xPortPendSVHandler );    
    /* Handler for Cortex SYSTICK - address 15 */
    CyIntSetSysVector( CORTEX_INTERRUPT_BASE + SysTick_IRQn,
        (cyisraddress)xPortSysTickHandler );

    FreeRTOS_initVar = 1;
/* ------------------------------------------------------------------------ */
void FreeRTOS_Enable( void )
    /* start the scheduler so the tasks will start executing */
/* ------------------------------------------------------------------------ */
void FreeRTOS_Start( void )
    if (FreeRTOS_initVar == 0) {

    * After the scheduler starts in Enable(), the code should never get to
    * this location.
    for (;;);

And when you run the FreeRTOS PSoC Component project you get the nice blinking LED (Red and Green)

Comparator Diagram CY8CKIT

FreeRTOS PSoC Component

After downloading the project, then opening it I first wanted to look at the components. You can do this by clicking the “Components” tab in the workspace explorer. It looks like he created (or was planning to create) several other components in addition to the “FreeRTOS”.

CY3295 Kit Image

When you double click on the “FreeRTOS_v8_2.cysym” you will get an editable view of the symbol.

CY3295 Kit Image

When you right click on the blank part of the canvas, PSoC Creator will bring up this menu.

CY3295 Kit Image

On the properties menu you can configure which tab the component belongs to in the Component Catalog. In this case he created a tab called “Community” which looks like this in the actual Component Catalog.

CY3295 Kit Image

To make that happen he setup the “Doc.CatalogPlacement” to be “Community/Operating System/FreeRTOS” (on the properties menu)

CY3295 Kit Image

The next thing that he did was add a whole bunch of Symbol Parameters which will let the user change the setup of FreeRTOS.Each  of these parameters show up as an editable field on the component customers (in the schematic).

CY3295 Kit Image

In the picture above you can see that he created two new “enumerated” datatypes called “FreeRTOS_CheckStackOverFlowType” “FreeRTOS_MemMangType”. In the picture below you can see the legal values for that type. This lets him restrict the things that the user of the component can select when he places it in his schematic.

CY3295 Kit Image

Here is what the component looks like when the user actually uses it. You can see the legal fields (from above) and the legal values for those fields (from above)

CY3295 Kit Image

The next thing that he did was copy all of the FreeRTOS files into component API.

CY3295 Kit Image

If you remember each FreeRTOS project needs to have a file called “FreeRTOSConfig.h”.  But, that file doesn’t appear to exist in the list above. How is that? Remember that when PSoC Creator builds a project it copies the API into your generated source directory, but it renames each of the files to be INSTANCE_NAME_filename. In this example, “Config.h” will become “FreeRTOS_Config.h” (FreeRTOS is the instance name in the schematic).

In FreeRTOS each of the features of the RTOS turn into a #define that is 0 or 1. When the component was created he modified “Config.h” so that each of the parameters on the component set values for the #defines in the “Config.h” file. And there is a bunch of them so that must have taken a good bit of work. Here is an example of a section of his “Config.h”.  Each place you see the back-tick $parameter back-tick PSoC Creator will substitute the value of the parameter (I am typing back-tick because WordPress interprets the actual symbol to mean something special and I don’t know how to get it into the text)

#if CY_PSOC4
    /* Port-dependent settings - not user-editable */
    #define configCPU_CLOCK_HZ          ( ( unsigned long ) CYDEV_BCLK__SYSCLK__HZ )
    /* Application settings - user editable */
    #define configMAX_PRIORITIES ( `$MAX_PRIORITIES` )
    #define configTOTAL_HEAP_SIZE ( `$TOTAL_HEAP_SIZE` )
#elif CY_PSOC5
    /* Device settings - not user-editable */
    #define configCPU_CLOCK_HZ ( ( unsigned long ) BCLK__BUS_CLK__HZ )
    /* Application settings - user editable */
    #define configMAX_PRIORITIES        ( `$MAX_PRIORITIES` )
    #define configTOTAL_HEAP_SIZE ( `$TOTAL_HEAP_SIZE` )
    #error "This FreeRTOSConfig.h file is for PSoC 4 and PSoC 5LP devices only"
#define configUSE_IDLE_HOOK `$USE_IDLE_HOOK`
#define configUSE_TICK_HOOK `$USE_TICK_HOOK`
#define configTICK_RATE_HZ ( ( portTickType ) `$TICK_RATE_HZ` )

Because each filename changes name, he had to go fix all of the #includes to look like this example from croutine.c (this was a bunch of work)

/* PSoC Component Customizations */
#include "`$INSTANCE_NAME`.h"
#include "`$INSTANCE_NAME`_task.h"
#include "`$INSTANCE_NAME`_croutine.h"

He also wanted to be able to have all of the FreeRTOS memory management schemes included in the project at one time. To solve this problem he put an #if around all of the code in heap_1, heap_2 … that adds and removes the appropriate memory manager.

#if (`$MemManager` == 2)

A FreeRTOS PSoC Template Project

When I started working on FreeRTOS I knew that I wanted to use V9.0.  But the component was setup for V8.2.  So I launched into the process of converting the component. This turned out to be a colossal pain in the ass because of the massive number of “small” changes. In addition I didn’t really like having to change the names of key files (even the stupidly named semphr.h).  Moreover, the source code as a component debate was raging wildly inside of Cypress and in general is on the way out. So I decided to implement this as a template project instead of a component.

All that being said, what E2ForLife did I continue to think was really clever.



warenbau321_2836316's picture

check out some myxer free ringtones

ChuckE's picture

Thank you for the critical acclaim :)and I'm glad to hear that people have found it useful.

The FreeRTOS component started as a side effort for a project of mine, and yes, I was originally working with the PSoC 5LP.Later I converted the project for the PSoC 4L family of devices, but never changed the name of the work stream.

The only reason that I haven't yet executed a pull request is that I haven't really fully tested everything.Using the component I also occasionally I run into something that I'd like to have the ability to do from the configuration screen.

So, for example, one of the major hangups with FreeRTOS 9 is the new "static" functions in the API. Most of the code that I've written using the RTOS port is dynamic allocation mode, so I haven't verified that the static implementations are working correctly.I really don't want to send some down the rabbit hole debugging ported OS code that was released too early :)

I use the component all the time at work, and it has saved me hours of setup and configuration time compared the suggested method on, which is what I used to do before I built the component. 



Dileep Yadav's picture

Thanks a lot and I'm glad to hear that people have found it useful.myxer vshare myxer Speed post tracking

Dileep Yadav's picture

 Indian Super League season is the fourth season of the Indian Super League, the football league, since its establishment T10 Cricket League Live Streaming isl live streaming
big bash Live Streaming



jiyakj123_2889706's picture

I referred the component example that you have shared here.But I didn’t understand the use of this project.What is it used for?Can you provide some uses and features of this project that can help in improving the present state?

hurak_2982191's picture

This code is awesome!I loved it!You might like to visit my site based on delhivery tracking!You'll like it!

goparoriw_2992466's picture

I like the way you code!It is really a good practice!Check out my latest blog on how to check pan card status!You will love it!

sunnyyadav0390_2753416's picture

To the save to the wsop free chips redeem codes good play for site.

r3646416_2927806's picture

The site has been providing a lot of such interesting topics regarding PSOC 4 Software Enablement.The codes offered here are very helpful in making the project all by me.The detailed instructions along with the image helped to understand the concept. highball glass

jiyakj123_2889706's picture

While reading your post, i came to know about PSOC 4 Software Enablement.But I got only minimal information about it.Could you please provide more details about it a soon as possible?Eagerly waiting for your updated post to get it. cheap internet

ratyzi_3248446's picture

In the news and the information you can set your target here in this news section and buy the product with best essays uk.You can also deal with more products here in this place and enjoy more valuable designs.

このサイトに掲示されているすべてのコンテンツと資料は、「そのままの状態」で提供されます。サイプレス セミコンダクタとその関連サプライヤは、これらの資料について、いかなる目的への適合性をも表明することはありません。また、これらの資料について、すべての保証や条件を放棄します。これには、暗示的な保証および条件、商用性、特定の目的への適合性、すべてのサードパーティの知的財産権に対する権利と非侵害などが含まれますが、これらに制限されることはありません。サイプレス セミコンダクタにより、明示または暗示にかかわらず、禁反言などによるライセンスは、付与されないものとします。このサイトに掲示されている情報の使用には、サードパーティまたはサイプレス セミコンダクタからのライセンスが必要となる場合があります。

このサイトのコンテンツには、特定のガイドラインや使用制限が含まれている場合があります。このサイトにおけるすべての掲示やコンテンツの使用は、サイトの利用規約に準じて行われるものとします。このコンテンツを使用するサードパーティは、制限やガイドラインに従い、このサイトの利用規約を遵守するものとします。サイプレス セミコンダクタとそのサプライヤは、コンテンツや資料、その製品、プログラム、サービスに対し、いつでも修正、削除、変更、改善、向上、その他の変更を加える権利を有します。また、いかなるコンテンツ、製品、プログラム、サービスを予告なく変更または閉鎖する権利を有します。