Hi fellows, this is the last post in this series of making the Discovery board to work along with the CooCox IDE and a RTOS like the FreeRTOS.
If you tried the last post, and you succeed, then adding the FreeRTOS won’t be too hard. There will be a number of ways for achieving our goal, so read all this post, so you make a choice.
There are two ways to get it: To download it from its official site: freeRTOS.org, or from my mirror.
Which are the differences?
a) The official bundle includes a lot of features that we aren’t going to use, besides it also includes all the official ports. All that stuff might make the process a mess, unless you know what are you doing.
b) My stripped version keeps only what is essential for our project. This is the fast and clean way.
Take into account that if you need some feature that was left out you can add it painless latter on.
A working project
This is a project that includes everything, so you can try FreeRTOS on the Discovery board as soon as possible.
Adding FreeRTOS to our project
Again, there are two ways for it: by hand, and by adding an already test project from here.
My project’s drawback is that you need to keep some paths strictly as I did, so the CoIDE can find the correct files in the correct places, otherwise the compiler will complain.
I’ve really tried to hard to create a template project that didn’t depend on absolute paths, but there is no such a way for doing it inside the CoIDE (if someone knows, please adviced me).
In the other option, you add the freeRTOS files tree by hand, so the CoIDE depends on your machine and not in mine.
a) Download and uncompress the test project following my paths. I’m pretty shure it will work. However, my advise is that you should try to add FreeRTOS manually first, it’s not as hard as it sounds, and you’ll get better results.
1.- Create a new project as we did in my previous post. Try to compile it just to test everything is ok ‘til this point, and you don’t stuck in case errors shows-up in the next step.
2.- Suppose you already have a strip FreeRTOS version in your hard disk, say in
and suppose your CoIDE project is located at
Now copy the FreeRTOS folder to c:\CooCox\CoIDE\workspaces\test_FreeRTOSBlog. Your project’s files tree should look something like this:
C:\CooCox\CoIDE\workspace\test_FreeRTOSBlog>tree Listado de rutas de carpetas El número de serie del volumen es xxxxxxxxxxxxxxxx C:. ├───cmsis_boot │ └───startup ├───cmsis_core ├───Debug │ ├───bin │ └───obj ├───FreeRTOSV7.2.0 │ ├───Demo │ ├───License │ └───Source │ ├───include │ └───portable │ ├───GCC │ │ └───ARM_CM0 │ └───MemMang ├───stm_lib │ ├───inc │ └───src └───test_FreeRTOSBlog.elf.xcodeproj C:\CooCox\CoIDE\workspace\test_FreeRTOSBlog>
Next step is to link the FreeRTOS folder to your project. Inside CoIDE, in project’s tab, you’ll notice that the FreeRTOS folder is not showed, although it is already in the project’s folder. That’s because we need to link it. In that same window right click in your project’s name (the parent project) and choose “Add link folder”. In “Link location” type (or browse) the FreeRTOS folder location. In my PC I got something like this:
Click on “Finish”, and the FreeRTOS folder is going to be linked. The linking process uses absolute paths, so it’s not important where the FreeRTOS folder is located, but I like that each project has its own copy. Maybe you don’t like this, so you’ll like to have one FreeRTOS copy for all of your projects.
3.- Before you can compile your project error-free you need to add the FreeRTOSConfig.h file. (You’ll find a copy of it either in the FreeRTOS stripped version, or in the project you downloaded before.) Save it along where your main.c file. For now you don’t need to edit it, but you can (and must) do it later. Your project’s files tree should look like this:
C:\CooCox\CoIDE\workspace\test_FreeRTOSBlog>ls -l total 32 -rw-rw-rw- 1 Administrador 0 1253 2012-09-23 14:22 arm-gcc-link.ld -rw-rw-rw- 1 Administrador 0 3965 2012-09-23 14:37 build.xml drw-rw-rw- 3 Administrador 0 0 2012-09-23 14:22 cmsis_boot drw-rw-rw- 2 Administrador 0 0 2012-09-23 14:22 cmsis_core drw-rw-rw- 4 Administrador 0 0 2012-09-23 14:23 Debug -rw-rw-rw- 1 Administrador 0 1040 2012-09-23 14:22 debug.config -rw-rw-rw- 1 Administrador 0 6734 2012-09-11 14:13 FreeRTOSConfig.h drw-rw-rw- 5 Administrador 0 0 2012-09-23 14:26 FreeRTOSV7.2.0 -rwxrwxrwx 1 Administrador 0 3205 2012-09-16 01:31 main.c -rw-rw-rw- 1 Administrador 0 723 2012-09-23 14:22 memory.ld drw-rw-rw- 4 Administrador 0 0 2012-09-23 14:22 stm_lib -rw-rw-rw- 1 Administrador 0 2305 2012-09-23 14:37 test_FreeRTOSBlog.cob drw-rw-rw- 2 Administrador 0 0 2012-09-23 14:23 test_FreeRTOSBlog.elf.xcodep roj C:\CooCox\CoIDE\workspace\test_FreeRTOSBlog>
(Although it looks like Linux’s console, actually it is a Window one, because I’m used to use Linux-like commands.)
Try to compile it. You’ll get some linker errors. This is because right now you have several copies for malloc() and alike functions. FreeRTOS includes (and needs) dynamic memory allocation, but we need to get rid of those copies we’re not going to use. I didn’t leave those files out when striping the FreeRTOS project ‘cause I think it’s important to keep them.
In the CoIDE’s project tab, go to FreeRTOSV7.2.0 -> Source -> Portable -> memMang. There are four files: heap_X.c. For now we only need the first one, heap_1.c, so right click in each of the others files and choose “Exclude from build”.
Compile it again, and (hopefully) your project will build without any troubles. Congratulations!! Now upload the code and run: Ctrl-F5. Both leds in the Discovery board will blink.
From here you might want to edit the FreeRTOSConfig.h file, or the main.c file in order to fit your own needs.
Hope this little series help you to get your Discovery board up and runing with sofisticated tools like debugging and programming using a RTOS.
As before, any doubts or comments are appreciated.