How to configure Ubuntu to program STM32

OpenOCD installation

The Open On-Chip Debugger (OpenOCD aims to provide debugging, in-system programming and boundary-scan testing for embedded target devices. If you using Ubuntu or any Debian like OS, OpenOCD could be installed by running following command:

sudo apt-get install openocd

ARM toolchain installation

Now we need compiler, linker and assembler (toolchain) for ARM Cortex architecture (

sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded


First install Eclipse IDE ( After installation run Eclipse and install plugin for STM32 procesors development. Follow this instruction .

USB rules

Next thing is to add proper permission to new devices.

cd /etc/udev/rules.d/
sudo nano 50-usb-stlink.rules

After opening 50-usb-stlink.rules (you can chose number to be anything integer under 99) file in nano, paste following rules for different ST-Link devices.

ATTRS{idProduct}=="6014", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
ATTRS{idProduct}=="6010", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403", MODE="666", GROUP="plugdev"
ATTRS{idProduct}=="3744", ATTRS{idVendor}=="0483", MODE="666", GROUP="plugdev"
#STLINK V2 and V2.1
ATTRS{idProduct}=="3748", ATTRS{idVendor}=="0483", MODE="666", GROUP="plugdev"

If you have different programmer you should change idProduct and idVendor. To find out your numbers first plug your USB device and then type lsusb

~$ lsusb
Bus 002 Device 007: ID 041e:323d Creative Technology, Ltd 
Bus 002 Device 005: ID 04d9:1702 Holtek Semiconductor, Inc. Keyboard LKS02
Bus 002 Device 004: ID 09da:9090 A4Tech Co., Ltd. XL-730K / XL-750BK / XL-755BK Mice
Bus 002 Device 003: ID 0424:2504 Standard Microsystems Corp. USB 2.0 Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 064e:a219 Suyin Corp. 1.3M WebCam (notebook emachines E730, Acer sub-brand)
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In the end restart USB service by pasting to terminal

sudo service udev restart


For tests I am using ST-Link 2.1 programmer from NUCLEO-F401RE board and  STM32F103C8T6 procesor in my USB Accelerometer device connected to Nucleo by SWD.

sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg

That’s it. If you had any troubles preparing you Ubuntu to program STM microcontrollers please let me know in the comment section below.


USB accelerometer sensor, tilt sensor

Nowadays everyone has accelerometer sensor in its own smartphone. It’s there for several reasons. First of all it’s used for detection of screen orientation relative to the gravity field. This is the sensor which gives your phone information when the screen should be switched from landscape mode to portrait. Beside this there are many other ideas how to use accelerometer.

One of them is pedometer. An app or device which uses accelerometer to track your steps. Application tries to analyse real time data from sensor to find peaks witch corresponding to human steps. Knowing average step length the program is able to calculate traveled distance.

Some guy from Hackday even made mechanical vibrations spectrum analyser using accelerometer and fourier transform decomposition. As you can see usefulness of this type of sensors is bounded only by your imagination 🙂

Such sensor may work as spirit level or angle reader to make something like ball on plate controlling machine just like this one bellow.

I though that it would be nice to have such a sensor in ordinary PC or Rasperry Pi computer for similar purposes so I designed one. My version is small, compact and Plug & Play.  You don’t need any Arduino or embedded coding. It’s just Plug & Play device which communicates with computer by USB port. If you are interested you can purchase it in electromake store.

USB Accelerometer fatures

  • The device uses well known ADXL345 accelerometer
  • USB bus communication
  • USB powered
  • This USB dongle following ADXL345 has user-selectable resolution
  • Fixed 10-bit resolution (from -512 to +511)
  • It is compatible with Linux and Windows OS
  • It is compatible with Raspberry Pi