Tutorial PDF
Tutorial PDF
Tutorial PDF
By Manos Tsachalidis
Tutorial for setting up STM32F4 discovery board on linux with
Eclipse, GNU ARM toolchain, OpenOCD and RTOS ChibiOS +
uGFX and eventually experiment with my DSO project
This is a tutorial for setting up the STM32F4 discovery board on linux. The distro i am using at this
tuto is Kubuntu 13.10 64bit. First thing to do is download the apps. The following links are related
to architecture specific releases and may not work fo your distro. You need to be aware of your
distro's architecture (32 or 64bit). You may of course experiment with different versions.
ChibiOS 2.6.0
http://sourceforge.net/projects/chibios/files/ChibiOS_RT%20stable/Version%202.6.0/ChibiOS_2.6.0.zip/download
uGFX 1.80
http://ugfx.org/images/resources/downloads/releases/ugfx-release-18.zip
In this tutorial i will mkdir a directory named .devel in my ~/ .After downloading eclipse, unzip it
anywhere you like and move it in ~/.devel . Same applies for the GNU arm toolchain. After
unzipping the toolchain you can move the dir in ~/.devel. Do the same for openocd. After
unzipping, move the dir to ~/.devel . ChibiOS and uGFX should be downloaded in a common path
if a network drive is used. For users that will work from exclusively one computer, they can use
the path ~/.devel .
After you download ChibiOS 2.6.0, unzip it in ~/.devel and rename the folder to ChibiOS_2.6.0.
After you download uGFX, unzip it and rename the folder to ugfx_1.8. Next thing to do is to move
the ugfx_1.8 directory inside ChibiOS_2.6.0/ext .
OpenOCD
This may be tricky for some people but i hope you will get over it. Besides, linux users should
know the basics of building an application.
Install the libftdi (or libftdi1) and libusb (plus dependencies) with the following command:
sudo apt-get install libftdi1 libusb-1.0
The openocd version i built is 0.6.1 and worked fine but 0.7.0 should work as well.
To build the executables go to: ~/.devel/openocd-0.6.1
Run this: ./configure --enable-ft2232_libftdi1 enable-stlink to enable support for the stm32f4
stlink.
Next run: make to compile the source files.
Last thing to do is install the executables by doing: sudo make install
You are done with OpenOCD. This has worked for me fine in a fresh Kubuntu 13.10 installation.
GNU ARM toolchain
You have to update your environment variable $PATH with the path of the executables. For
Kubuntu, you need to make a new file in ~/.kde/env/ called whatever you like (i named mine
envar.sh) and enter the following text:
export PATH=$HOME/.devel/gcc-arm-none-eabi-4_8-2013q4/bin:$PATH
In Ubuntu, you need to edit your ~/.profile and add the following text:
PATH=$HOME/.devel/gcc-arm-none-eabi-4_8-2013q4/bin:$PATH
Both files above are used to update your environment variable $PATH while entering your
personal session in Ubuntu or Kubuntu. To confirm that your $PATH contains the path to the arm
toolchain, you must log out and log back in or try rebooting. Then open a terminal window and
see if the environment variable contains the path to the arm toolchain executables with the
following command: echo $PATH
Project directory
This will need your full attention as everything needs to be in perfect order for everything to work.
Make a new directory called projects into ~/.devel/ . Navigate to ~/.devel/ChibiOS_2.6.0/demos/ ,
copy dir ARMCM4-STM32F407-DISCOVERY and paste it to ~/.devel/projects . Navigate to the
path ./devel/projects/ARMCM4-STM32F407-DISCOVERY/ . You can delete the dirs iar & keil
as you are using eclipse. Create a file named OpenOCD.launch and paste the xml code that
follows:
NAME_OF_PROJECT: Replace with the dir name of your project which in our case is:
ARMCM4-STM32F407-DISCOVERY
Download the zip file http://naftilos76.net/dl/openocd.zip that contains the openocd scripts that will
make it work with your stm32f4 discovery board and unzip it in your project:
~/.devel/projects/ARMCM4-STM32F407-DISCOVERY/. Let's consider that referring to your
stm32f4 project will from now on mean dir: ./devel/projects/ARMCM4-STM32F407-DISCOVERY/ .
Download the zip file http://naftilos76.net/dl/Makefile.zip and copy / overwrite the file Makefile in
your project. This file will be used by eclipse to compile, Link, include the proper header files etc.
IMPORTANT: Edit the file Makefile after you copy. Go to line 67 and substitute with your own
home path. Save and close the file.
#FT2232
ATTRS{idProduct}=="6010", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
#FT230X
ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
#STLINK V1
ATTRS{idProduct}=="3744", ATTRS{idVendor}=="0483", MODE="666", GROUP="plugdev"
#STLINK V2
ATTRS{idProduct}=="3748", ATTRS{idVendor}=="0483", MODE="666", GROUP="plugdev"
Copy the text in the empty file and save. Now you need to reload the udev rules with
sudo /etc/init.d/udev restart
in order to allow the discovery board to operate in linux. Actually the last line of the above text is
the one that you need if you have a st-link v2 programmer.
int main(void) {
halInit();
chSysInit();
// Set port D and pins 12-15 to push pull output.
// Push-pull means that whenever we set a pin to 1, 3 Volts will appear at that pin.
// If we set that pin to 0, then the pin will be connected to GND.
palSetPadMode(GPIOD, 12, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOD, 13, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOD, 14, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOD, 15, PAL_MODE_OUTPUT_PUSHPULL);
while (1) {
// Set the pins to an opposite value. If they are 1, make their output 0 and so on...
palTogglePad(GPIOD, 12);
palTogglePad(GPIOD, 13);
palTogglePad(GPIOD, 14);
palTogglePad(GPIOD, 15);
// Create a delay of 500ms
chThdSleepMilliseconds(500);
}
return (0);
}
Tab: Main
Text field Name: You can rename it to Flash and Debug or you can leave it as is.
Text field C/C++ Application: Enter the text build/ch.elf without the quote signs.
Tab: Debugger
Text field GDB Command: Enter the debugger executable of the GNU ARM toolchain which is
arm-none-eabi-gdb without the quote signs.
*As i said i am on a Kubuntu 64bit. When i run this debugger i got an error message that a
shared library libncurses was not found. This is due to the fact that the ARM tool chain needs
32 bit executables. The solution was to install the 32 bit version of that library as the 64 bit
version was already installed but on a different path.
To install that, do this: sudo apt-get install libncurses5:i386
Text field Port number: This is the port where openocd actually listens. The default value is
probably 10000. Change that to 3333 and this tab is done.
Tab: Startup
Uncheck the two check boxes Reset and Delay (seconds) and Halt. Enter the init
commands mon reset init on the text window below the Halt checkbox.
Tab: Source
Nothing to do
Tab: Common
Check the checkbox Debug
Click on the Apply button at the bottom right and you are done.
You can now click on the Debug button. This will load the compiled code ch.elf in your
build directory in the microcontroller and start the debugging session. As in openocd window,
the name that you used above Flash and Debug or any other will appear in the menu of the
debugger button so that you won't have to do all this again and again.
Hopefully you have already flashed your code into the STM32F4 and thinking about what
debugging is really all about (if you have not done this before). Debugging is about discovering
and finding solutions in error situations and generally see what is going on in our code, see the
values of variables as they are updated and every other entity that caries one or more values.
If your code is executing you will see the leds of the discovery board to keep blinking once per
second. Below is the tab Debug of Eclipse tha contains openocd and GDB debugger. You can
click on the row of the debugger and then click on the red stop button in case you want to stop
the debugger and re-upload the code to the uC. Same applies for the openocd.
Open the main.c and enable the line numbers by right clicking on the left most blueish column and
selecting from the menu the menu item Show line numbers
Double click on line number 35. You will see a blue round shape to appear on the left of the
number. After an instant the arrow, as seen below, should appear as well. The execution stops and
the Green led is the only one lit. This means that palTogglePad(GPIOD, 12); has executed but not
the next line. In order for the execution to continue, you have to click on the play button which is
enabled everytime execution is interrupted. After clicking on the play button, the execution will
continue until the next time it reaches the breakpoint.
Using the DSO project makes sense if you have a SSD1963 TFT lcd display 800x480 pix with a
touch panel compatible with ADS7843 controller like this one i bought from ebay:
http://www.ebay.com/itm/New-5-0-800-480-TFT-LCD-Module-Display-Touch-Panel-SSD1963-5
1-AVR-STM32-/180910383286?pt=LH_DefaultDomain_0&hash=item2a1f1960b6
However any SSD1963 lcd will do as long as you initialise it properly. The supplier usually offers
code samples that can help you make it work.
http://ugfx.org/
http://ugfx.org/forum/
http://www.chibios.org/dokuwiki/doku.php
http://chibios.sourceforge.net/html/index.html
I will set up a website to post this tuto and further update it as well as being able to accept
comments and offer help where i can.