FreeRTOS

Working libraries, libraries being ported and related hardware
victor_pv
Posts: 1261
Joined: Mon Apr 27, 2015 12:12 pm

FreeRTOS

Post by victor_pv » Fri May 08, 2015 2:11 am

I just tested the FreeRTOS library from the "untested" folder, with a simple blinking sketch, and seems to work fine out of the box.

When I have time I will see if I can setup a couple of different tasks and see how it goes.

User avatar
Luc_Exe
Posts: 37
Joined: Fri May 01, 2015 6:08 pm
Location: Viña del Mar, Chile

Re: FreeRTOS

Post by Luc_Exe » Tue May 12, 2015 9:23 pm

Can you put more details? MCU/board in wich you tested FreeRTOS and tools used to compile?

Looks interesting.

I'm still trying to find a good IDE to test stuff like this (bootloaders, RTOS, etc) using windows, but none of the IDEs that I could use have the ability to import sources (Arduino IDE, Coocox coIDE, emIDE). Tried eclipse and derivatives and I can get the code to import, but with these I have problems with the toolchain. Hope I can find a solution without dealing with the command line, still have to try with linux running on virtualbox.

victor_pv
Posts: 1261
Joined: Mon Apr 27, 2015 12:12 pm

Re: FreeRTOS

Post by victor_pv » Wed May 13, 2015 4:29 am

Luc I used the maple mini in Arduino IDE.
All the files I used at in that repository (https://github.com/victorpv/STM32F1_Modified/)
I am keeping that repo for the experiments, and if something works I report it here. I need to update my main one up to Rogers master, and then I can send him pull requests to make updates easier, I feel bad having to ask him to pull files from one repo to update another when I could just do a pull request.

I don't think I had to modify anything in the freeRTOS files, just took them off the untested libraries folder. I did create one example off of code I found in the leaflabs forums. It is just a blink one. I plan of doing a larger test with the ILI 9341 display using DMA transfers.
If that works, it would be great cause DMA can transfer hundreds of bytes, while the RTOS can assign time to some other function until DMA completes.
If I get it working, I will post an example of it.

victor_pv
Posts: 1261
Joined: Mon Apr 27, 2015 12:12 pm

Re: FreeRTOS

Post by victor_pv » Sun May 17, 2015 2:46 am

Just an update on FreeRTOS.

I decided to test something more complicated than a blink, so I took the Cube example from the ILI9163 library, tweaked it a bit to make it a function that I can call several times to have multiple cubes in the screen, and added 2 rotating cubes as additional threads to the Cube example.
Everything seems works really good.
I am uploading the example to my repo, for anyone to use as an example.
Currently it runs 4 tasks in parallel:
-Blinking the board led.
-Drawing a rotating cube in the center of the screen.
-Drawing another rotating cube in a corner.
-Sqrt calculations with the lowest priority.

Both cube drawing tasks use a semaphore to signal when one of them writing to the display, so the other will not try to do it at the same time.

It's doing all that, while using the Serial port to print the time it takes for the square root calculations, and using SPI with DMA for the display.
And the ILI library is not optimized for FreeRTOS, otherwise if it released the CPU every time it is waiting for the DMA to complete, it could free up a lot more CPU cycles.


I want to test FreeRTOS 8.2, I am really liking how easy is to schedule a bunch of different tasks with different priorities easily.

User avatar
mrburnette
Posts: 1783
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: FreeRTOS

Post by mrburnette » Sun May 17, 2015 3:24 pm

victor_pv wrote: ...
I want to test FreeRTOS 8.2, I am really liking how easy is to schedule a bunch of different tasks with different priorities easily.
This is encourging. Any feel for the 'cost' associated with the supervisory code? With finite resources, core cycles and SRAM are always a concern.

Ray

victor_pv
Posts: 1261
Joined: Mon Apr 27, 2015 12:12 pm

Re: FreeRTOS

Post by victor_pv » Sun May 17, 2015 3:48 pm

Let me compare compiling the rotating cubes example with and without RTOS.
I believe it will use more RAM because of the way the RTOS reserves head space directly, rather than letting malloc() manage it, but I don't know for sure.

Do you have any interesting example that could benefit from running in RTOS that would try? I only used the cubes ones to confirm peripheral access and DMA run good, but I don't have anything bigger than that to test with right now.

EDIT: Just quickly tested.
FreeRTOS heap space can be configured, as in my tests was set to 8KB.
I can check in the memory map that 8KB are reserved for xHeap, so out of the total memory used by the sketch at compile time, we should substract those 8KB. For the test I commented out the led blinking task and the Sqrt task from the FreeRTOS example, so it only has the 2 rotatin cubes, exactly as the sketch without FreeRTOS.
These are the numbers:

Code: Select all

FreeRTOS:
Sketch uses 26,444 bytes (21%) of program storage space. Maximum is 122,880 bytes.
Global variables use 11,672 bytes of dynamic memory.

No RTOS:
Sketch uses 22,980 bytes (18%) of program storage space. Maximum is 122,880 bytes.
Global variables use 3,168 bytes of dynamic memory.
Taking out the 8KB of reserved heap, the differences are:
FreeRTOS uses 312 bytes of RAM, and 3464 bytes of flash.
I think those numbers are pretty good for what it does.

EDIT: Just tested FreeRTOS 8.2.1. I took their CortexM3 port, then did the 3 changes I had found were done to the Maple port of the 7.0.1, and with those 3 changes both my examples compile and run fine. I have not tested every single functionality, so there could be things that do not work.
With 8.2.1 there are 5 choices for heap management. With the most basic one it results in 80 more bytes used of Flash, but 40 less used bytes of RAM.

User avatar
mrburnette
Posts: 1783
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: FreeRTOS

Post by mrburnette » Sun May 17, 2015 4:34 pm

victor_pv wrote:Let me compare compiling the rotating cubes example with and without RTOS.
I believe it will use more RAM because of the way the RTOS reserves head space directly, rather than letting malloc() manage it, but I don't know for sure.

Do you have any interesting example that could benefit from running in RTOS that would try? I only used the cubes ones to confirm peripheral access and DMA run good, but I don't have anything bigger than that to test with right now.
<...>
Taking out the 8KB of reserved heap, the differences are:
FreeRTOS uses 312 bytes of RAM, and 3464 bytes of flash.
I think those numbers are pretty good for what it does.

EDIT: Just tested FreeRTOS 8.2.1. I took their CortexM3 port, then did the 3 changes I had found were done to the Maple port of the 7.0.1, and with those 3 changes both my examples compile and run fine. I have not tested every single functionality, so there could be things that do not work.
With 8.2.1 there are 5 choices for heap management. With the most basic one it results in 80 more bytes used of Flash, but 40 less used bytes of RAM.
That is much better than I expected. I tend to just publish simple projects on my project blog hackster.io/rayburne for demonstration purposes, so "real" projects are few that would actually strain the STM32F1xx - even the 20K SRAM one. But knowing that it can be done and the "cost penalty" associated with the technology - I may venture into some more complicated posts in a future article.

Many thanks for the numerics!

Ray

victor_pv
Posts: 1261
Joined: Mon Apr 27, 2015 12:12 pm

Re: FreeRTOS

Post by victor_pv » Sun May 17, 2015 4:53 pm

I was seriously impressed. I had never used an RTOS in a microcontroller before, I expected it would eat up resources like crazy, but doesn't seem to to do so, and I believe using DMA for peripherals as much as possible may help a lot more with an RTOS than if we have to carefully go timing things around to use those cycles with something else.
At this point the LCD library is not even optimized for the RTOS. I am sure with some small changes so it releases the CPU to the RTOS whenever a long enough DMA is taking place, would improve performance greatly. Probably not for small transfers that just take a few cycles, but anything over a few hundred cycles should take longer than the task switching in the RTOS. I may give it a shot later.

User avatar
RogerClark
Posts: 5936
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: FreeRTOS

Post by RogerClark » Mon May 18, 2015 9:53 pm

Victor,

I've move FreeRTOS from untested into the normal part of the libraries folder

When Ray has had chance to confirm its working OK for him, and perhaps when we have a some examples people can try, we can post an announcement as I'm sure a lot of people would be very interested

Thanks

Roger

User avatar
mrburnette
Posts: 1783
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: FreeRTOS

Post by mrburnette » Tue May 19, 2015 2:50 pm

http://feilipu.me/2011/09/22/freertos-a ... vr-atmega/

For the old 8-bit Arduino units, the revised library freeRTOS library above (updated 4/2015) looks promising, too. As I was discussing in another thread, the very cheap 328P 16MHz mini boards under $2 may become useful in future projects to manage sensors and pre-digest some of the data before sending over to the STM32 (master/hub).

Ray

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest