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.

When installing eclipse, also install zylin plugin as described below.

Follow instructions at http://gnuarmeclipse.livius.net/blog/install/ generic for all ARM CPU, not just STM32

eclipse: project creation

Performed only when new project is needed.

For a USB device based project, see further below.

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

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)

<periphroot>/STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Device/ST/STM32L1xx/Include
<periphroot>/STM32L1xx_StdPeriph_Lib_V1.2.0/Libraries/CMSIS/Include
..
<periphroot>/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"

openocd installation

obtain from https://sourceforge.net/projects/openocd/files/openocd/

eclipse: zylin plugin installation

only performed once during eclipse installation

use eclipse update site http://opensource.zylin.com/zylincdt as described at http://opensource.zylin.com/embeddedcdt.html

openocd use

running openocd (acts as GDB-server)

openocd must be ran from the eclipse project directory (current working directory) in order to load the correct .elf file into target flash

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

target script for openocd:

erases and programs flash monitor halt monitor poll

monitor flash probe 0
#monitor flash protect 0 0 31 off
monitor reset halt
monitor transport select
#monitor flash erase_sector 0 0 31  
monitor flash erase_sector 0 0 15
monitor flash write_image Debug/<project_name>.elf
#monitor flash protect 0 0 31 on
mon reset init</code>

Not all, but some devices may require unprotect/protect of flash for programming

You may choose to erase only some of the sectors based upon your program size.

If you do not know the flash bank number or sector range, you can telnet into openocd at port 4444

$ telnet localhost 4444
> reset halt
> flash banks
#0 : stm32lx.flash (stm32lx) at 0x08000000, size 0x00020000, buswidth 0, chipwidth 0
> flash info 0
#0 : stm32lx at 0x08000000, size 0x00020000, buswidth 0, chipwidth 0
        #  0: 0x00000000 (0x1000 4kB) not protected
        #  1: 0x00001000 (0x1000 4kB) not protected
        ...
        # 31: 0x0001f000 (0x1000 4kB) not protected
stm32lx - Rev: W

eclipse: debugging using openocd

in Project Explorer (left side), right click project -> Properties

  • debugger tab:

    embedded GDB

    GDB debugger: arm-none-eabi-gdb

    GDB command file: <gdb/your_target_name.script>, using script as above described

    Standard/mi2

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

USB project creation, from STM32_USB-FS-Device_Lib_V4.0.0

Clone this wiki locally