Skip to content
Wayne Roberts edited this page Dec 5, 2013 · 26 revisions

Summary of using eclipse for STM32 development

Cortex-M toolchain install

Performed once first time, or when desired to upgrade compiler

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

Add to your PATH the bin directory of the extracted archive.

eclipse: installation

Performed once first time, or in the rare case of desired eclipse upgrade. (generic for all ARM CPU, not just STM32)

Using GNU ARM Eclipse plugin eases use of ARM cross compilers with eclipse, follow instructions at http://gnuarmeclipse.livius.net/blog/install/ (eclipse installation is there as well).

install GDB hardware debugging

eclipse: project creation

Performed only when new project is needed.

This is bare-bones template example from ST stdperiph library, For a USB device based project, see STM32 USB project creation.

File -> New -> C project:
ARM cross target application:
    Empty Project
    toolchain:
        ARM Linux GCC (Sourcery G++ Lite)

Set target processor

  • C/C++ Build -> Settings -> Target Processor
    • defaults to Cortex-M4 (yours might be M3)

eclipse: adding source files to project

This section refers to the project template in ST standard peripheral library. for example, that found in STM32L1xx_StdPeriph_Lib_V1.2.0/Project/STM32L1xx_StdPeriph_Templates/

Eclipse by default will use whatever .c files or .S files are present in the project directory, but if you copy new file into there, you must refresh.

files to copy (stdperiph template project example)

startup_stm32l1xx_md.s
    from
STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Device/ST/STM32L1xx/Source/Templates/TrueSTUDIO/
Rename to .S

High-density:        384K flash
medium-density:      64 to 128K flash       = STM32L152VBT6
medium-density plus:     256K flash         = STM32L152RCT6

from STM32L1xx_StdPeriph_Lib_V1.2.0/Project/STM32L1xx_StdPeriph_Templates/:
    system_stm32l1xx.c
    stm32l1xx_conf.h
    stm32l1xx_it.c
    stm32l1xx_it.h
    main.[ch]       use as template, edit out to your needs

-----> *_it.c (interrupt handling source file) can be missing
            from project and still link properly <------

from STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/STM32L1xx_StdPeriph_Driver/src/:
    copy all periph src driver files to subdir in project

eclipse: include paths (STM32L example)

With desired project selected (in Project Explorer on left side), Project -> Properties, or right click project in explorer.

  • C/C++ Build -> Settings -> click Directories under in C compiler section, then add:

    /STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Device/ST/STM32L1xx/Include

    /STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Include

    ..

    /STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/STM32L1xx_StdPeriph_Driver/inc

periphroot is location where you extracted the ST peripheral library.

The '..' is workspace directory, because CWD of toolchain will be the subdirectory of build configuration name, such as "Debug" or "Release"

eclipse: C compiler setup:

  • C/C++ Build -> Settings ->

  • C preprocessor defined symbols:

    USE_STDPERIPH_DRIVER

  • optimization:

    -O2 (optional)

    -ffunction-sections

    -fdata-sections

eclipse: C linker setup:

  • C/C++ Build -> Settings ->

  • General:

    Script file (-T): ../STM32_flash.ld

    Remove unused sections (--gc-sections)

    C language only: uncheck -nostartfiles, or you get undefined reference to _init from __libc_init_array

OpenOCD Installation

for latest bug fixes, obtain the v0.8.0 release git clone git://git.code.sf.net/p/openocd/code openocd-code

If you want to run openocd as regular user, install udev rules. See contrib/openocd.udev in the openocd source tree.

OpenOCD use

running openocd (acts as GDB-server)

Run from eclipse project directory: openocd -f openocd/interface/stlink-v2.cfg -f openocd/target/stm32lx_stlink.cfg

Run this from a separate terminal window, so you can watch the operation during first debug session.

eclipse: debugging using openocd

Creation of Debug Configuration

  • Run -> Debug Configurations, or click down arrow on bug icon in eclipse toolbar

    highlight "GDB Hardware Debugging" on left side

    click "New lauch configuration" icon, or right click "GDB Hardware Debugging" -> New

    • Main tab:

      set Project if not already showing (browse button), "C/C++ Application" should then be auto-filled

      near bottom, if not "Using Standard GDB Hardware Debugging Launcher" then Select other to change

    • Debugger tab:

      set GDB command: arm-none-eabi-gdb

      set command set/protocol version: Standard, mi2

      set Port number: 3333

    • Startup tab:

      put into Halt text area: mon reset halt

    • Common tab:

      under Display in favorites menu: check Debug

When starting debugging for first time, watch the terminal openocd is running in for status of correct functioning. In addition, make sure eclipse has switched to Debug perspective. You should see program paused at first instruction of Reset_Handler.

When finished debugging, close debug session with red square in toolbar, Also, in upper left Debug pane, right click toplevel [GDB Hardware Debug] for "Terminate and Remove". In upper-right corner of eclipse, switch back to C/C++ perspective.

using printf

for stub functions, see https://sites.google.com/site/stm32discovery/open-source-development-with-the-stm32-discovery/getting-newlib-to-work-with-stm32-and-code-sourcery-lite-eabi

Clone this wiki locally