-
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
Add to your PATH the bin directory of the extracted archive.
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:
select GDB Hardware Debugging
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)
Set target processor
- C/C++ Build -> Settings -> Target Processor
- defaults to Cortex-M4 (yours might be M3)
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:
/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"
-
C/C++ Build -> Settings ->
-
C preprocessor defined symbols:
USE_STDPERIPH_DRIVER
-
optimization:
-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.
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 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
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
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 describedStandard/mi2
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