STM32F0-Discovery + CooCox III (english version)

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:, or from my mirror.

FreeRTOS official site

FreeRTOS stripped for STM32F1

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.

b) Manually

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:

Listado de rutas de carpetas
El número de serie del volumen es xxxxxxxxxxxxxxxx
│ └───startup
│ ├───bin
│ └───obj
│ ├───Demo
│ ├───License
│ └───Source
│ ├───include
│ └───portable
│ ├───GCC
│ │ └───ARM_CM0
│ └───MemMang
│ ├───inc
│ └───src

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

(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.

8 comentarios sobre “STM32F0-Discovery + CooCox III (english version)

  1. Hi,

    Firts of all, sorry by my bad english.

    I’m new in this “RTOS word”, i have a STM32Discovery and I’m trying to use FreeRTOS and CoIDE.

    When I saw this post I thought that was everythig that I needed, but in your code don’t use nothing related whit RTOS, like a task, queue or semaphore.

    Now I’m trying to modify your code and put a task to blinky the LEDs, but I still can’t do this. Can you help me?

    Best Regards

    1. Hi, thank you for reading my blog.

      Please give me some more information regards your question. What do you mean with “I still can’t do this?” What is the meaning of “this” in your question? With more facts shurely is going to be easy for me to assist you.

      Have a nice day.

  2. Hello,

    I have a question. Your post has a title “STM32F0 Discovery …” so it’s obviously about this kit, but your “stripped” version of FreeRTOS seems to be “FreeRTOS stripped for STM32F1”. Why F1 and not F0? Would it even work on STM32F0 Discovery kit? Thanks.

    1. Hi, there is not so much difference between F1 and F0 in this regard, just need to change some linker scripts and some underlying FreeRTOS files. ASAP I got some free time I’ll be back to this tutorials. Meanwhile let me say that I’m not using anymore the Coocox platform, and you might do the same. It’s better off startig the toolchain from scratch.

  3. Few more questions about the example (code), if you don’t mind. Not sure if it’s your code or not, though, but here it goes:

    1.) what’s the point of BSRR_VAL (#define BSRR_VAL 0x0300) and where is it used?

    2.) Same question for macro BIT (#define BIT(x) (1<<(x)))

    3.) Same question for: delayInMilliSeconds(uint32_t delay)

    Thanks in advance!

    1. 1.) what’s the point of BSRR_VAL (#define BSRR_VAL 0x0300) and where is it used?

      This is a reminder of a project in which main was based upon. In this scenario it is not used at all, so don’t worry

      2.) Same question for macro BIT (#define BIT(x) (1<<(x)))

      This is a handy macro to set to the boolean true value a specific bit in a byte or word. Even if it hasn't been used here you may add it to your toolbox.

      3.) Same question for: delayInMilliSeconds(uint32_t delay)

      With this function you get a very accurate time delay.

      Thanks in advance!

      1. Hi,

        Saddly, my account was closed in that server, that’s way you cannot find it. ASAP I’ll find another server I’ll let you know it. I want to mention that I’ve abandoned both, Coocox and STM32 controllers, towards something better and I feel more comfortable with: the NXP LPC platform.


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s