Getting Started with STM32L-Discovery Board

From EdWiki

This article describes about setting up an opensource environment for STMicroelectronics STM32 Cortex-M based Microcontrollers using CodeSourcery toolchain, eclipse, and OpenOCD. In particular, It uses STM32L-Discovery Board and its STM32L1xx_StdPeriph_Driver's Touch Sensing example.

Setting up the ARM Lab

It is Assumed that, youe have setup an Embedded ARM Lab, If not, Please do so before proceeding further.

STM32L-Discovery Blinky Project

Start Eclipse with new workspce. Instead of creating a new project, we will Import an existing Project from the file system. Download STM32L-Discovery Eclipse Project and extract to your home folder. Now Import STM32L-Discovery Blinky Project into the Eclipse workspace

Toolchain Prefix and Path

To make sure that the toolchain Prefix and Path are correct, Select Project > Properties > C/C++ Build > Settings > Cross Settings. The Prefix field is set to arm-none-eabi- and modify the Path field to the folder where you have installed the CodeSourcery toolchain.


if you have accepted the default installation folder.

Setting Compiler, Assembler and Linker Options

Since we have imported a pre-configured project, various options for compiler, assembler, and linker for Debug Configuration are already set. Then, let's build the project.

Building Project

To Build the Project on demand, click on the Project menu and un-select Build Automatically.

Un-Select Build Automatically

From the main menu, Select Project > Build Project.

Build Progress Bar

If everything goes well, you will see in the console window something like the following:

Build Console Output

Build will be completed with some Warning Messages. For the time being we can ignore these warning messages.

GDB, OpenOCD and Eclipse

To use OpenOCD with our projects, we need to do more than just connecting the STM32L-Discovery board to PC through USB cable and then starting the OpenOCD server.

  1. We need to configure OpenOCD server so that it knows about the adapter(Dongle) and the board(CPU).
  2. We also need to configure OpenOCD such that it communicates to GDB using Eclipse GUI for flashing the code and debugging.
  3. The Eclipse GUI environment will also needs to be configured such that both GDB and OpenOCD are integraed with in the IDE

OpenOCD Project Setup

It is assumed that OpenOCD v0.9.0 is compiled and is available in your home folder such as:


with all the necessary configuration files.

To configure OpenOCD, select Run > External Tools > External Tools Configurations... from the main menu.

External Tools Configurations...

In the External Tools Configurations window, enter (browse to the) openocd executable as

Configuring OpenOCD

  • OpenOCD in the Name,
  • /home/USERNAME/openocd-0.9.0-bin/openocd in the Location,
  • /home/USERNAME/openocd-0.9.0-bin in the Working Directory, and
  • -f board/stm32ldiscovery.cfg in the Arguments fields.

Next, Select Common tab in the same External Tools Configurations window and Select Externals Tools to Display in favourite menu as shown in the following screen.

Configuring OpenOCD

Make sure that Launch in background option is checked.

Next, select Apply followed by Close button.

Configuring the Debugger

To configure the Debugger, select Run > Debug Configurations... from the main menu.

Debug Configurations Menu

In the Debug Configurations window, select GDB Hardware Debugging from the left pane, and make sure that C/C++ Application, Project and Build Configuration fields are selected properly from the main tab as shown in the following screen.

Debug Configurations

In the same Debug Configurations window, select Debugger tab. In this window tab, specify :

Debugger Configurations
  • /home/USERNAME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gdb as GDB Command,
  • Check Use remote target option
  • Select Generic TCP/IP for JTAG Device,
  • localhost for Host Name and
  • 3333 for Port Number as shown in the screen.

Next, Select the Startup tab and enter the following Commands in the text window:

Startup Commands
monitor reset init
monitor halt
monitor flash probe 0
monitor sleep 500
monitor poll on

Next, Select the Common tab and check Debug to Display in favourites menu as shown in the following screen.

Favourites menu

That’s it. We have completed the Debug Configurations. Click on Apply followed by Close button to complete the Debug Configurations.

STM32L-Discovery Board

  1. Check jumper position on the board, JP1 ON, CN3 ON
  2. Connect the STM32L-Discovery Board to a PC with a Mini-USB cable to power the board. RED LED LD2 (PWR) then lights up.

Running OpenOCD

We have already configured OpenOCD, just select OpenOCD from the External Tools Tool Bar.

Run OpenOCD

OpenOCD Output

Note: OpenOCD will be running in the background, don’t terminate.

Launching the Debugger

To launch the debugger, select the Debug icon from the tool bar.

Invoking Debugger

When we launch the Debugger for the first time, eclipse tries to switch the Perspective from C/C++ to debug, select Remember my decision and click YES.

Eclipse Perspective Switch

The Debugger should break at C main function as we have configured it.

Debug Window

Now you can use all the debugging commands like, single step, examine registers, examine data etc.

if Debugger launch gets stuck at "Configuring GDB" then may be 32-bit libncurses library is missing.

To install use following command

sudo apt-get install lib32ncurses5   lib32ncurses5-dev

Resources and References

Sample Projects

  1. STM32L-Discovery Blinky Eclipse Project
  2. STM32L-Discovery Current Consuption and TouchSensing Eclipse Project
  3. STM32L-Discovery Blinky Codelight Project
  4. Download STM32L-Discovery Blinky & USART Eclipse Projects and unzip. There are 3-Projects (Blinky, StdPeripheral Library and USART), Import all the three Projects into a new eclipse workspace. Select StdPeriph_v1.2.0_Lib Project and Build it first. The other 2-Projects (Blinky and USART) depend upon StdPeriph_v1.2.0_Lib Project.
  5. You can also clone a codelite STM32L-Discovery Blinky git repository
git clone


  1. STM32L1xx Standard Peripherals Library
  2. STM32L-Discovery Board Documents
  3. Toolchain for Linux Intel x86 platform
  4. Eclipse IDE for C/C++ Developers -- Linux 32-bit
  5. Eclipse IDE for C/C++ Developers -- Linux 64-bit


  1. GCC Compiler for Cortex-M3
  2. CodeSourcery G++ Lite -- Getting Started Guide
  3. GNU Assembler Manual
  4. GNU GCC Manual
  5. GNU LINKER Manual
  6. Debugging with GDB
  7. An Introduction to GCC
  8. GNU Make
  9. OpenOCD User's Guide