STM32-P405 Development Environment

The development environment consists of:

  • Host PC running Linux Mint 17.3
  • OpenOCD (On Chip Debugger) to interface with the JTAG controller
  • GNU Arm binutils package  (Arm assembler, linker, etc.)
  • GNU Arm GCC compiler
  • GNU Arm GDB debugger
  • USB to serial adaptor (using the Prolific PL2303 chipset)

The first step is to validate the JTAG setup using OpenOCD, as I wish use a netbook based on an older version of Ubuntu as well as my host PC, I decided to build OpenOCD from source to enable the functionality on both the host PC and the netbook. The version of OpenOCD I used was 0.9.0, the source code for this version can be downloaded here.

After downloading the OpenOCD tar/bz2 archive unpack it using the following commands:

mkdir openocd_build
cd openocd_build
cp $HOME/Downloads/openocd-0.9.0.tar.bz2
bunzip2 openocd-0.9.0.tar.bz2
tar -x < openocd-0.9.0.tar
cd openocd-0.9.0

The OpenOCD package is now ready to be built, it’s possible that some additonal libraries may need to be installed for USB support and FTDI support (FTDI is the chipset used by the JTAG connector), to install these libraries on Linux Mint 17.3 (and also other Debian/Ubuntu derivatives) the following commands can be used:

sudo apt-get install libftdi-dev
sudo apt-get install libusb-1.0-0-dev

The OpenOCD package should now be ready to built, however additional libraries may need to be installed based upon the output from the configure script. To build the package run the following command in the openocd-0.9.0 directory:

./configure --enable-ftdi
checking for makeinfo... makeinfo
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
Created Makefile from
Created build-jim-ext from

OpenOCD configuration summary
MPSSE mode of FTDI based devices yes
ST-Link JTAG Programmer yes (auto)
TI ICDI JTAG Programmer yes (auto)
Keil ULINK JTAG Programmer yes (auto)
Altera USB-Blaster II Compatible yes (auto)
Versaloon-Link JTAG Programmer yes (auto)
Segger J-Link JTAG Programmer yes (auto)
OSBDM (JTAG only) Programmer yes (auto)
eStick/opendous JTAG Programmer yes (auto)
Andes JTAG Programmer yes (auto)
USBProg JTAG Programmer yes (auto)
Raisonance RLink JTAG Programmer yes (auto)
Olimex ARM-JTAG-EW Programmer yes (auto)
CMSIS-DAP Compliant Debugger no

The output above indicates that the OpenOCD package will be built with Olimex JTAG support enabled, to build and install the package use the following commands:

sudo make install

To verify the package has installed correctly run the following command, and check the version number is correct:

openocd --version
Open On-Chip Debugger 0.9.0 (2016-03-11-11:15)
Licensed under GNU GPL v2
For bug reports, read

If the version number is correct the OpenOCD package is now ready to be used with the JTAG debugger.

The OpenOCD command requires a configuration file to work with the STM32-P405 board, first create a directory structure to be used for all cortex based code and tools, for example:

mkdir -p $HOME/arm/cortex/stm32p405/openocd
mkdir $HOME/arm/cortex/stm32p405/examples

This creates two directories, one to contain the OpenOCD configuration file and another directory to contain example source code.

To create the configuration file use the following commands:

cd $HOME/arm/cortex/stm32p405/openocd

echo "set WORKAREASIZE 0x20000" > openocd.cfg
echo "source [find target/stm32f4x.cfg]" >> openocd.cfg

This creates a file called openocd.cfg, the WORKAREASIZE parameter is the available RAM on the board, in the case of the STM32-P405 this is 128KB (0x20000 in hexadecimal), the second line of the configuration is used to instruct the OpenOCD command to use a configuation file provided by the package to support stm32f4c class devices.

The JTAG connection can now be tested with the following command:

sudo openocd -f /usr/local/share/openocd/scripts/interface/ftdi/olimex-arm-usb-tiny-h.cfg -f openocd.cfg
Open On-Chip Debugger 0.9.0 (2016-07-28-08:43)
Licensed under GNU GPL v2
For bug reports, read
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : clock speed 2000 kHz
Info : JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Info : JTAG tap: tap/device found: 0x06413041 (mfg: 0x020, part: 0x6413, ver: 0x0)
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints

The above output now shows that the JTAG connection is working, it is now possible to program, debug and flash the board using the standard GNU toolchain and debugger.

To install the GNU toolchain use the following commands:

sudo binutils-arm-none-eabi
sudo apt-get install gcc-arm-none-eabi
sudo apt-get install gdb-arm-none-eabi

With the toolchain and OpenOCD now installed it is now time to write some simple startup code.