Août 22

Robotics 101 : Quick start with chibiOS

Quick start :

In this tutorial you will install everything you need to have a working program on your board, and learn how to use them.

Openocd and GDB installation :

In order to flash the chip, i.e put your program into the chip, you need to install a few softwares: openocd and gdb.

First install openocd with (it should ask for your password, it’s perfectly normal):
$ sudo apt-get install openocd

Then install gdb (it’s not the regular one, this one is for arm processors)
First download the latest version of gcc-arm-none-eabi-linux here, then open a shell and do this, it will install it and adds it to your local environment.
$ cd Downloads
$ tar xjvf gcc-arm-none-eabi-4_7-2013q2-20130614-linux.tar.bz2
$ sudo mv gcc-arm-none-eabi-4_7-2013q2 /opt/ARM
$ echo "PATH=$PATH:/opt/ARM/bin" >> /home/"$(whoami)"/.bashrc (if you use bash)

That’s it, you now have installed everything you need to flash your chip !

Now let’s go to the part where you really flash the chip.

First you need to open openocd with:
$ sudo openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg

This will allow your computer to communicate with the board.

Then launch gdb, passing the name of your executable file as a parameter (here ch.elf). You either need to launch it in the folder containing your file or to indicate the proper path to access it (ex: .../project/build/ch.elf):
$ arm-none-eabi-gdb ch.elf
Then you need to tell it what to communicate to, here openocd is in localhost:3333
$ target extended-remote localhost:3333
Eventually you can load your program into the chip:
First stop the current program with
$ mon halt
Then you can load the code with
mon flash write_image erase ABSOLUTE_PATH_TO_YOUR_ELF
(normally simply typing $ load should be enough, but in the last version of openocd it doesn't work any more with the board we are using here)
You can then launch the program with:
$ mon reset or $ continue
That’s it !

First: get ChibiOS/RT

ChibiOS is a real time operation system (RTOS), it could take a few hours to explain you what it is so we won’t do it, let’s simply say that it is an easy way to give and execute commands on your board without having to directly write into the registers.

For this course we will use the ChibiOS, you can find it here.

Then unzip it and create a ST_Tutorial folder and a ChibiOS one within in Documents (it doesn’t really need to be in this folder but is will help us to have the same paths all along the tutorial).
$ unzip ChibiOS_6.0.0.zip ../Documents/ChibiOS

This folder contains all the sources of ChibiOS.

Create and compile a project with ChibiOS/RT:

Then if you want to create a new project simply do (from /home/USERNAME) and replace PROJECTNAME by your project’s name:
$ cd Documents/ST_Tutorial

You will also have to change the path to ChibiOS in the Makefile, to do so simply replace at the 67th line
CHIBIOS = ../..
CHIBIOS = /home/USERNAME/Documents/ChibiOS

Now why did we do that ? An embedded system program is something reaaallllyyy complex you need to configure a lot of stuff, initialize even more stuff and more complex things. That’s what ChibiOS/RT is for.
What you did there is to copy the demo project (where everything works for sure) you will use it as a canvass to write your own code. When you changed the Makefile you updated the location of ChibiOS/RT relatively to the project (in order to get the source code of ChibiOS/RT).

Then simply go to this folder and write your project.
Once you are done you can compile it by typing in the command line
$ make
(it’s a unix tool which compiles every file in the right order, you simply have to edit the MAKEFILE to specify the order, we will see it in another lesson).
It will create a /build folder with an executable file with the extension .elf

Final test :

Now that you know how to create a project, to compile it and to load it into the board, you can try it with this sample code and simply create a project as seen higher and replace the content of the main.c file by:

Since it is already written you will simply have to compile and load it.
And that’s it, you have programmed and loaded your first stm32f4discovery program!
Now time for a beer !


Next part here.

Once again, feel free to use the comment section 😉

Note: for now the code is not indented, but i promess you that as soon as i manage to get my grip on how to properly use wordpress it will be indented.