FreeRTOS port compile errors.

Hi,
I am endeavouring to create an application using the Arduino MKZero board and FreeRTOS kernel.

For my first attempt, I included the FreeRTOS library included with the Arduino Studio IDE. This immediately failed to compile as it is a port the AVR platform and not compatible with the Zero's ARM based processors.

I then searched the web for a port to the Zero platform and fount the following GitHub repository which claims to be a working port created in 2015.

However after adding the library to the project, had to relocate the automatically added FreeRTOS.h & FreeRTOSConfig.h to the beginning of the include list as this was generating errors while compiling.

Having cured this minor problem, I was faced with a list of errors concerning the delay library function assignments as follows.

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp: In function 'void rtos_run()':

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:37:8: error: assignment of function 'void delay(long unsigned int)'

  delay = &rt_delay;

        ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:37:8: error: cannot convert 'void (*)(uint32_t) {aka void (*)(long unsigned int)}' to 'void(long unsigned int)' in assignment

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:38:9: error: assignment of function 'long unsigned int micros()'

  micros = &rt_micros;

         ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:38:9: error: cannot convert 'uint32_t (*)() {aka long unsigned int (*)()}' to 'long unsigned int()' in assignment

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:39:9: error: assignment of function 'long unsigned int millis()'

  millis = &rt_millis;

         ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:39:9: error: cannot convert 'uint32_t (*)() {aka long unsigned int (*)()}' to 'long unsigned int()' in assignment

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:40:20: error: assignment of function 'void delayMicroseconds(unsigned int)'

  delayMicroseconds = &rt_delayMicroseconds;

                    ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:40:20: error: cannot convert 'void (*)(uint32_t) {aka void (*)(long unsigned int)}' to 'void(unsigned int)' in assignment

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp: In function 'void rtos_stop()':

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:48:11: error: '_delay' was not declared in this scope

  delay = &_delay;

           ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:49:12: error: '_micros' was not declared in this scope

  micros = &_micros;

            ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:50:12: error: '_millis' was not declared in this scope

  millis = &_millis;

            ^

C:\Users\scamb\Documents\Arduino\libraries\FreeRTOS-Cortex-M0\src\helper.cpp:51:23: error: '_delayMicroseconds' was not declared in this scope

  delayMicroseconds = &_delayMicroseconds;

I would be grateful if someone could assist me in correcting these errors or perhaps point me in the direction of a fully working port of the library.

Many thanks

Scamb09

Hello scamb09,

I had the same issues with plcengineers last year and couldn't resolve them either. I ended up having to port FreeRtos on my own.

I have been using my port since last November, and have tested it on a SparkFun SAMD21 Mini/Dev, Adafruit Feather M0, and a Atmel Xplained SAMD21. I am developing laser tag guns, and it works great for multi-threaded project. The samD21 is perfect for FreeRtos, the additional ram allows for alot of threads with large stacks.

I have been meaning to post it to github, this gives me a good excuse to make time and do it. If you can survive afew days without it I can post it this weekend for you to give it a try :wink:

That would be brilliant, I know that the SAMD21 is very capable of running FreeRTOS very well, I have been using them in my projects for some time.

My hope is that some day someone will port the Arduino language to the SAMS7x series of microcontrollers as I have a few project ideas that require an even more powerful controller.

But for now using FreeRTOS on a SAMD21 would be good start. May be if your port works then you should submit it to Arduino to be included as a downloadable library extension.

Many thanks and hope to hear from you soon.

Scamb09

Here you go!

I added a example program to the library, you should be able to open that program and flash it right to your board without any problems. It should be a good project to branch off of and make things work.

When I have free time, I will try to add more examples and update the readme more.

Let me know how it works, would love to hear what you end up making with it :slight_smile:

I Have downloaded your port of FreeRTOS and it works just fine, great job.

Was wondering how much effort it would take to upgrade the files to the latest version 9 of the kernel and if this was something I could do by myself, I have never really bothered porting libraries myself but am eager to learn how, particularly with the forth coming ATSAMD51 based modules, as Adafruit have in development.

I intend to use such a device in a switch mode power supply project with specific tasks to handle PWM management, input & output monitoring, display handling etc.

Anyway, many thanks for your help and again great work.

Scamb09

Porting the FreeRtos libraries shouldn't be to bad, there is a guide online to help you through it.

As far as porting it to arduino... thats where I had the most problems. From what I was told by a colleague is it should be as easy as creating a wrapper like header file, including the files you need (find the port.c and portmacro.h for your processor architecture), edit the FreeRTOSConfig.h settings header, and you are set. A upgrade to the rtos would just require you to copy and past the newer source files over the old source files and update your FreeRTOSConfig.h settings header.

Where I ran into problems in that the arduino compiler had alot of scope issues with the original freertos source files, I couldn't seem to figure out a way to have a single header include all the files I wanted without there being some sort of scope issue, it was very frustrating. I ended up having to go in and add alot of includes in the rtos source in order to make it compile. I also added in some code in order to call the led blink error hooks.

Upgrading to the newest version of the freertos is totally doable, you would need to copy the new source code over the current source, but then go into the new source and make the same changes I did. Notepad++ has a nice compare feature that lets you compare two pieces of code side by side, might make life alot easier to see what was changes and needed to be merged. Also, the FreeRTOSConfig.h would probably have to be changed (no idea how drastic a change would be needed).

One of these days I think I will upgrade this library to the newest version (and make a second attempt to do it the proper way :wink: ) It might be awhile, I have plenty of projects to keep me busy lol.

Hope this helps, let me know if you end up trying to update the library :slight_smile: