b.编译器设置
选择Project->Properties->C/C++ Build->Settings设置工程,在Tools Settings选项卡中选择Target Processor中的Processor为cortex-m3,如下图所示:
再选择Tools Settings选项卡中的ARM Sourcery Linux GCC C Linker->General中指定Script file的路径,即链接脚本。如下图所示:
c. openocd以及gdb启动设置
为了能够在ecilpse中启动openocd,可以在eclispe中的external tools选项中设置。点击Run->External Tools->External Tools Configurations..。弹出窗口之后鼠标双击Program,将Name修改成OpenOCD,这里只需要设置Main选项卡中的内容,Location中是openocd命令的位置,Arguments中是openocd的参数,除了openocd命令以外的内容都要填在这里。如下图所示:
设置完之后点击Apply应用以后可点击Run使其运行,运行结果可以在ecilpse的console选项卡中看到。
接下来设置gdb。点击Run->Debug Configurations..弹出窗口之后,鼠标双击Zylin Embedded debug(Native)之后鼠标选择到ebugger选项卡,将Main子选项卡中的GDB debugger修改成arm-none-eabi-gdb如下图所示:
再点击Commands选项卡,选择在'Initialize' commands选项卡中添加内容,这里的内容主要是gdb启动时候的初始化内容,比如连接openocd,复位cpu等等,我参考了几个博客,添加的内容如下:
target remote localhost:3333
monitor reset
monitor halt
load
b main
(PS:这里再贴几个人家工具里面带的初始化设置:
Atollic TrueSTUIDO for ARM Lite:
------------------------------------------------------------------------------------------------------------------------
Start Debug:
# Set flash parallelism mode to 32, 16, or 8 bit when using STM32 F2/F4 microcontrollers
# Uncomment next line, 2=32 bit, 1=16 bit and 0=8 bit parallelism mode
#monitor flash set_parallelism_mode 2
# Set character encoding
set host-charset CP1252
set target-charset CP1252
# Reset to known state
monitor reset
# Load the program executable
load
# Enable Debug connection in low power modes (DBGMCU->CR)
set *0xE0042004 = (*0xE0042004) | 0x7
# Set a breakpoint at main().
tbreak main
# Run to the breakpoint.
continue
-------------------------------------------------------------------------------------------------------------
Start Analyse:
# Set flash parallelism mode to 32, 16, or 8 bit when using STM32 F2/F4 microcontrollers
# Uncomment next line, 2=32 bit, 1=16 bit and 0=8 bit parallelism mode
#monitor flash set_parallelism_mode 2
# Set character encoding
set host-charset CP1252
set target-charset CP1252
# Reset to known state
monitor reset
# Load the program executable
load
# Enable Debug connection in low power modes (DBGMCU->CR)
set *0xE0042004 = (*0xE0042004) | 0x7
# Start the executable
continue
----------------------------------------------------------------------------------------------------------------------------------
Start Unit Test:
# Set flash parallelism mode to 32, 16, or 8 bit when using STM32 F2/F4 microcontrollers
# Uncomment next line, 2=32 bit, 1=16 bit and 0=8 bit parallelism mode
#monitor flash set_parallelism_mode 2
# Set character encoding
set host-charset CP1252
set target-charset CP1252
# Reset to known state
monitor reset
# Load the program executable
load
# Enable Debug connection in low power modes (DBGMCU->CR)
set *0xE0042004 = (*0xE0042004) | 0x7
# The executable starts automatically)
添加后如下图所示: