-
Notifications
You must be signed in to change notification settings - Fork 6
STM32 tools
Summary of using eclipse for STM32 development
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.
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).
-
Help -> Install New Software -> work with:
click Add button if this site is not already added
under "CDT Optional Features", select GDB Hardware Debugging
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
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.
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
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"
-
C/C++ Build -> Settings ->
-
C preprocessor defined symbols:
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
-
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
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
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.
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.
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