STM32F4 Development Environment Setup on Ubuntu - matianfu/arabesque GitHub Wiki

Prerequisite

Ubuntu: 12.04 LTS

OpenOCD: master branch from official source repository

Hardware: STM32F4 Discovery and STM32F4 Breakout

Courtesy

http://www.wolinlabs.com/blog/linux.stm32.discovery.gcc.html

Installation

GNU Toolchain

The full name is "GNU Tools for ARM Embedded Processors". The project is official maintained by ARM developers.

https://launchpad.net/gcc-arm-embedded

In download page (https://launchpad.net/gcc-arm-embedded/+download), pick linux tarball, (as writing, the latest is gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2).

Untar:

tar xzvf gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2

(Working in Progress)

OpenOCD

Build and Install OpenOCD

git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd OpenOCD

./bootstrap

./configure --enable-maintainer-mode --enable-ft2232 --enable-stlink

make -j16

sudo make install

Not sure if --enable-stlink is necessary, may be not. Some online tutorials suggested --enable-ft2232_libftdi but OpenOCD says it's deprecated and --enable-ft2232 should be used instead.

ma@ma-aspire:~$ which openocd

/usr/local/bin/openocd

After installation, OpenOCD scripts folder is located in /usr/local/share/openocd.

Configure USB permission

USB device identification:

  • idVendor 0x0483
  • idProduct 0x3748

lsusb can be used to figure them out. First issue lsusb to get a summary of usb devices on system. Then use lsusb -v -s bbb:ddd to list specific device [ddd] on specific bus [bbb], with -v for verbose output, for example:

lsusb -v -s 003:007

Create a udev rules file in /etc/udev/rules.d, for example: 99-stlink-v2.rules

# STLink/V2

SUBSYSTEM=="usb", ATTR{idVendor}=="0483", MODE="666", GROUP="plugdev"

Without this rules, or some misspelling embedded in the rule file, you get an libusb_open LIBUSB_ERROR_ACCESS error.

To make this rules taking effect, reboot system, or restart udev service:

sudo service udev restart

or just force udev reload rules:

sudo udevadm control --reload-rules

Run OpenOCD

This command works:

openocd -f /usr/local/share/openocd/scripts/board/stm32f4discovery.cfg

Open On-Chip Debugger 0.9.0-dev-00184-g885f438 (2014-12-16-13:00)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.sourceforge.net/doc/doxygen/bugs.html

Info : The selected transport took over low-level target control. The results might differ compared to

plain JTAG/SWD

adapter speed: 1000 kHz

adapter_nsrst_delay: 100

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : clock speed 1000 kHz

Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748

Info : using stlink api v2

Info : Target voltage: 3.079759

Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints

But these two do not:

openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg \

-f /usr/local/share/openocd/scripts/target/stm32f4x.cfg

openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg \

-f /usr/local/share/openocd/scripts/target/stm32f4x.cfg

Open On-Chip Debugger 0.9.0-dev-00184-g885f438 (2014-12-16-13:00)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.sourceforge.net/doc/doxygen/bugs.html

Error: session's transport is not selected.

Info : session transport was not selected, defaulting to JTAG

Error: Debug adapter doesn't support 'jtag' transport

Runtime Error: embedded:startup.tcl:20:

in procedure 'script'

at file "embedded:startup.tcl", line 58

at file "/usr/local/share/openocd/scripts/target/stm32f4x.cfg", line 6

in procedure 'transport' called at file "/usr/local/share/openocd/scripts/target/swj-dp.tcl", line 23

in procedure 'ocd_bouncer'

at file "embedded:startup.tcl", line 20

Adding -c transport select swd does NOT cure.

The stm32f4discovery.cfg works for both discovery and breakout board, so it seems something missing in original stlink-v2.cfg or stm32f4x.cfg, need further investigation on cfg scripts. The workaround solution now is to use original discovery cfg file.

By default, OpenOCD listens to 4444 tcp port after started. You can verify this by telnet.

telnet localhost 4444

You should have:

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

Open On-Chip Debugger

>

Now you have OpenOCD console with prompt >; try help command.

Ctrl+] will quit to telnet session with a telnet > prompt, another quit to close telnet session.

Or you can use exit to quit to shell directly.

⚠️ **GitHub.com Fallback** ⚠️