STM32F4 Discovery (en) - iurobpn/pvtestes GitHub Wiki
Software Instalation for Programming stm32f4 Discovery kit
1. General Information
This guide is based on the installation guide from MCU GNU Eclipse, which is in constant evolution. In case of any problem, go to the original guide for help. The aim of this guide is to help the new user to avoid common mistakes and to provide a faster instalarion of the software.
The 3 main software needed to program the stm32f4 discovery are:
- GNU GCC toolchain: GNU Compiler Collection, which includes a c language compiler(gcc) and a debuger (gdb);
- Openocd: Open on chip debugger: A software that allows to program and debug the discovery via USB.
- Eclipse with "GNU MCU Eclipse" plugin: It is optional, but it facilitates the programming and debuging of firmware.
This guide is tested on ubuntu 16.04, but should work on any derivative of ubuntu 16.04 like Xubuntu, Linux Mint and others.
2. GCC Arm Toolchain Intallation and configuration.
Install the build-essential package, and if you decide to install eclipse, also install java.
$ sudo apt update
$ sudo apt install build-essential default-jre
The toolchain's installation instructions is based on: https://gnu-mcu-eclipse.github.io/toolchain/arm/install/.
Download the arm gcc toolchain download from: https://github.com/gnu-mcu-eclipse/arm-none-eabi-gcc/releases Choose the linux 64 bits, the current version is centos64 but it could be debian64 or ubuntu64 in future versions. Assuming that the download file is gnu-mcu-eclipse-arm-none-eabi-gcc-7.2.1-1.1-20180401-0515-centos64.tgz, the installation folder will be:
$HOME/opt/gnu-mcu-eclipse/arm-none-eabi-gcc/7.2.1-1.1-20180401-0515/
The binary folder will be:
$HOME/opt/gnu-mcu-eclipse/arm-none-eabi-gcc/7.2.1-1.1-20180401-0515/bin/
Installation
Run the folowing commmands:
$ mkdir -p $HOME/opt
$ cd $HOME/opt
$ tar xf ~/Downloads/gnu-mcu-eclipse-arm-none-eabi-gcc-7.2.1-1.1-20180401-0515-centos64.tgz -C $HOME/opt/
$ chmod -R -w $HOME/opt/gnu-mcu-eclipse/arm-none-eabi-gcc/7.2.1-1.1-20180401-0515/
Installation test
Run the folowing command and verify if the output is similar.
$ $HOME/opt/gnu-mcu-eclipse/arm-none-eabi-gcc/7.2.1-1.1-20180401-0515/bin/arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU MCU Eclipse ARM Embedded GCC, 64-bits) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
3. Openocd installation
This section is based on the tutorial on https://gnu-mcu-eclipse.github.io/openocd/install/. The download can be done from https://github.com/gnu-mcu-eclipse/openocd/releases. Download the linux 64 bits version, the current version is the centos64, but future versions could be debian64 ou ubuntu64, or others.
Assuming that the downloded file is: gnu-mcu-eclipse-openocd-0.10.0-7-20180123-1217-centos64.tgz, the installarion folder will be:
$HOME/opt/gnu-mcu-eclipse/openocd/0.10.0-7-20180123-1217
And the binary folder will be:
$HOME/opt/gnu-mcu-eclipse/openocd/0.10.0-7-20180123-1217/bin/
Installation
Run the commands:
$ cd ~/opt/
$ tar xf ~/Downloads/gnu-mcu-eclipse-openocd-0.10.0-7-20180123-1217-centos64.tgz
$ chmod -R -w $HOME/opt/gnu-mcu-eclipse/openocd/0.10.0-7-20180123-1217/
Installation test
Run the folowing code and verify the output.
$ $HOME/opt/gnu-mcu-eclipse/openocd/0.10.0-7-20180123-1217/bin/openocd --version
GNU MCU Eclipse 64-bits Open On-Chip Debugger 0.10.0+dev-00404-g20463c28 (2018-01-23-12:24)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Adding udev rules
In order to the linux OS to acknowledge the discovery hardware via USB, a udev rule must be enforced. Run the folowing commands and restart:
$ sudo cp /home/gagarin/opt/gnu-mcu-eclipse/openocd/0.10.0-7-20180123-1217/contrib/60-openocd.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
Check the serial port permissions
If you have trouble with USB access, add your user to the serial port owner group and restart. To find the group:
$ ll /dev/tty*
Choose the port with diferente name, in most cases is ttyUSB0, but it can be also ttyACM0. The group name will be after the root as showed in the folowing output line.
crw-rw-rw- 1 root dialout 166, 0 Mai 10 13:36 /dev/ttyACM0
In this case, the group is dialout. Run:
$ gedit /etc/group
and add your user name at the end of the dialout group line, after ':'.
dialout:x:20:user_name
Installation test:
Run the folowing code and verify the output.
$ ${HOME}/opt/gnu-mcu-eclipse/openocd/0.8.0-201501181257/bin/openocd \
-f board/stm32f4discovery.cfg
GNU MCU Eclipse 64-bits Open On-Chip Debugger 0.8.0-00036-gb7535dd (2015-01-18-12:57)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.sourceforge.net/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v14 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.905638
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
^C
Verify the openocd path on eclipse(if you install), go to menu Window → Preferences → MCU → Global OpenOCD Path
4. Eclipse installation
Download eclipse with the GNU MCU Eclipse plugin installed from: https://github.com/gnu-mcu-eclipse/org.eclipse.epp.packages/releases/.
Extract the linux 64 bits version to:
bash $HOME/opt/eclipse/
It is recommended to folow the folowing section to make the use of eclipse easier: https://gnu-mcu-eclipse.github.io/eclipse/workspace/preferences/
Create the provant-software project in Eclipse.
Go to the menu: file → new → project. Select "Makefile project with existing code".
Set the project name and the folder as:
folder_path/provante-software/
In this case:
$HOME/git/provant-software/
Select "Cross ARM gcc" and close the new project window.
Select the project in "Project Explorer" tab and go to: file → Properties. Go to c/c++ Build. Click "workspace" and select the folder:
io-board/stm32f4/app/remote-controlled-flight
as "Build directory". Click "Apply". This shows to eclipse where is the makefile of the project.
Expand c/c++ build, and click settings. In "Toolchain path:" insert the toolchain installation path.
Select the project in the "Project Explorer" tab and e go to menu Project → Build Project to compile it.
Configuring Eclipse to program and debug the Discovery using openocd.
Go to menu Run → Debug Configurations. Select "GDB OpenOCD Debugging", and click on "new launch configuration" button. Select app/remote-controlled-flight/bin/prj-remote-controlled-flight.elf in "C/C++ Application" in main tab.
In Debugger tab, insert into 'Config options':
-f board/stm32f4discovery.cfg
In 'Commands' option, insert:
set mem inaccessible-by-default off
set remote hardware-breakpoint-limit 6
set remote hardware-watchpoint-limit 4
In 'Startup' tab, insert:
monitor halt
Click in apply and close. This configuration will allow you to debug and program the stm32f4 discovery.