Skip to content
Mariano Eduardo Rodriguez edited this page Oct 28, 2022 · 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

Do not set system PATH (environment variable) to toolchain, this path is set in project creation in GNU ARM eclipse.

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:
Project Type:
    Executable:
        empty project
    Toolchains:
        Cross ARM GCC

Set target processor

  • C/C++ Build -> Settings -> Target Processor
    • STM32L1xx is cortex-m3, STM32F4 is cortex-m4
    • if your program starts crashing, check again Target Processor type

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:

    <parentdir>/STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Device/ST/STM32L1xx/Include

    <parentdir>/STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Include

    ..

    <parentdir>/STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/STM32L1xx_StdPeriph_Driver/inc

<parentdir> 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, under Cross ARM C Compiler:

    USE_STDPERIPH_DRIVER

  • optimization:

    these are set at toplevel of C/C++ Build -> Settings (not under Cross ARM C Compiler)

    -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.

if you want to use openocd in windows, look at Cortex on Windows

OpenOCD use

running OpenOCD (acts as GDB-server)

You can run in the openocd source tree: src/openocd -f tcl/interface/stlink-v2.cfg -f tcl/target/stm32lx_stlink.cfg

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

running OpenOCD from eclipse

Once you are satisfied OpenOCD is functioning correctly, you make choose to start it from eclipse, rather than having a separate terminal window open

Run -> External Tools -> External Tools Configurations...

  • Location:

    browse to the openocd exe file

  • Arguments: those you use when running it from terminal, such as -f scripts\interface\stlink-v2.cfg -f scripts\target\stm32lx_stlink.cfg

  • You can then start openocd from the eclipse toolbar.

eclipse: debugging using openocd

Creation of Debug Configuration

This must be done once for every project

  • 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