ChibiOS for STM32F4-DISCOVERY

For setting up our ChibiOS develop enviroment integrated on our host machine we can follow this brief guide.

For setting up ChibiOS we need of:

- ChibiOS;

- A GNU GCC toolchain, for example YAGARTO or CodeSourcer installed;

- ST Toolset 4.2.1p2 or newer for flash programming.

 

I assumed that you had satisfied all prerequisite and had yet created in your $HOME directory the strucure for guest multiple toolchains.

If not made yet, do this procedure:

mkdir $HOME/development/

cd $HOME/development/

 

and in there you can perform the installation following the official guide:

git clone https://github.com/mabl/ChibiOS Chibios-STM32F4-Discovery

 

This allows, for multiple ChibiOS based projects, to share one Chibios codebase and also coexist in the same workspace.

I prefer keep my projects in another directory, but you can make your project dir where you want.

 

./$HOME/buildings/ChibiOS_prjS/src               Use this as your  workspace
./$HOME/buildings/ChibiOS_prjS/src/chibios -> ../chibios      

                          symbolic link to chibios (Check out the chibios source

                          code there)
./$HOME/buildings/ChibiOS_prjS/src/proj1                  project directory
./$HOME/buildings/ChibiOS_prjS/src/proj2                  project directory
./$HOME/buildings/ChibiOS_prjS/src/proj1/MakeFile    project files
./$HOME/buildings/ChibiOS_prjS/src/proj1/main.c
./$HOME/buildings/ChibiOS_prjS/src/proj1/chconf.h
./$HOME/buildings/ChibiOS_prjS/src/proj1/mcuconf.h
./$HOME/buildings/ChibiOS_prjS/src/proj1/halconf.h

 

Note: is important check that in your MakeFile file there are the correct paths to your toolchain and chibios directory.

 

Finished !

 

Installing STLink

Now we can configure the programmer:
cd /$HOME/development/

mkdir tools

cd tools/

perform the installation of STLink:

Clone the st-link repo:
        git clone https://github.com/texane/stlink

Compile and install:
        $ cd stlink
        $ ./autogen.sh
        $ ./configure
        $ make

 

Test it:

        $ st-util -s 2

        Chip ID is 00000413, Core ID is  2ba01477.
        KARL - should read back as 0x03, not 60 02 00 00
        init watchpoints
        Listening at *:4242...

 

If you want you can export an enviroment variable to path st-util.

For do this you must edit your .bashrc or .bash_profile, depend of system that you are using.

 

 

Build the our first program

I will show how to can use this demostration-demo as template for your projects.

ToBeDefined -> if show you how to make a template for demo example provided in your demo directory in ChibiOS or make a template from zero! sorry ! While you waiting... you can try the demos located in your

$HOME/development/ChibiOS/demos/ARMCM4-STM32F407-DISCOVERY-XXX directory using the debugg section below.

Debug a program with STLink and GDB

Boot the ST-Linker with desidered version  (2in my case)
    $ st-util -s 2

Run the debugger with the path to your elf file (in another terminal tab)
    $ arm-none-eabi-gdb /path2your.elf.file


Setup Target

From now on, every command is meant for the GDB command line and not for your bash. Next, we connect from our GDB to our target:

     (gdb) target extended-remote : 4242

Since typing a lot is getting annoying, we can take advantage of the command parser of GDB and use the short version:

     (gdb) tar ext :4242
--------------
Optionally:

If everything went right, we have to reset and halt our target to make it ready to receive the image:

     (gdb) monitor reset halt

Please note that the command monitor means that the following commands are not GDB but OpenOCD related. Therefore we cannot use any short version because it's not visible for the GDB command parser. The short version is therefore:

      (gdb) mon reset halt
--------
Now we can finally load our code into the MCU:
      (gdb) load

 

and:
      (gdb) continue

 

For stop Ctrl^C, kill (assert y), and quit.

Ctrl^C to the st-util terminal tab.

 

If you didn't start GDB with the path of the ELF file as an argument or using the file command afterwards, you have to specify the path as an argument of load. Please note that it is highly recommended to start GDB with the ELF file as an argument because you won't have the important debugging symbols available afterwards.

If everything went right, you should have an output like this:

      (gdb) load
Loading section startup, size 0x130 lma 0x8000000
Loading section .text, size 0x197d4 lma 0x8000130
Loading section .data, size 0x16c lma 0x8019908
Start address 0x8000130, load size 105072
Transfer rate: 22 KB/sec, 11674 bytes/write.
     (gdb)

     (gdb) run

 

Thank you for reading.

References