Ubuntu下Eclipse+GDB+OpenOCD搭建ARM Cortex-M3开发环境
2013-07-04 20:12:12| 分类: Embedded System | 标签:eclipse gdb openocd configuration |举报 |字号 订阅
硬件环境:HP CQ45 308
操作系统:KUbuntu12.04 LTS 32bit
目标平台:LM3S811最小系统
关于OpenOCD与目标平台的连接,请参考这篇博客:
http://blog.163.com/thinki_cao/blog/static/8394487520136325112103/,当连接成功之后OpenOCD启动守护进程,此时可以使用GDB连接OpenOCD,这里OpenOCD充当了GDB Server的角色。接下来我们需要在eclipse中配置编译以及调试环境。
操作系统:KUbuntu12.04 LTS 32bit
目标平台:LM3S811最小系统
1.下载eclipse以及交叉编译器,我们选择eclipse cdt indigo版本。下载完毕之后记得安装虚拟机,这里不作介绍,下面我们需要下载交叉编译器,交叉编译器一共有两种,一种是ARM官方发布的,还有一种是MentorGraphics发布的Code Sourcery G++ Lite,这里选择Code Sourcey G++ Lite版本,这个版本也是免费的,而且稳定性更好一些。下载链接:
http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/,网页中
记得选择“
Download the EABI Release
”下载,不要选错了,成功后会将链接发送至邮箱。
2. 安装一系列插件来进行交叉编译。
a. GNU ARM Eclipse Plug-in插件安装在eclipse中(help->install new software...),到 http://gnuarmeclipse.sourceforge.net/updates 安装插件(网络要连接上)。功能:eclipse CDT 扩展插件,使eclipse可以支持CodeSourcery G++ Lite, GNUARM, WinARM, Yagarto, devkitPro的GNU ARM工具链。免费。b. Zylin Embedded CDT插件安装功能:通用GDB调试插件。免费。
3. 工程设置
4. 在eclipse中使用gdb调试。a. 新建工程选择File->New->C Project,Projcet type选择ARM Cross Target Application/Empty Project,Toolchains选择ARM Linux GCC(Sourcery G++ Lite),如下图所示,然后一路next,然后finish。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:3333monitor resetmonitor haltloadb 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 encodingset host-charset CP1252set target-charset CP1252
# Reset to known statemonitor reset
# Load the program executableload
# 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 encodingset host-charset CP1252set target-charset CP1252
# Reset to known statemonitor reset
# Load the program executableload
# Enable Debug connection in low power modes (DBGMCU->CR)set *0xE0042004 = (*0xE0042004) | 0x7
# Start the executablecontinue----------------------------------------------------------------------------------------------------------------------------------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 encodingset host-charset CP1252set target-charset CP1252
# Reset to known statemonitor reset
# Load the program executableload
# Enable Debug connection in low power modes (DBGMCU->CR)set *0xE0042004 = (*0xE0042004) | 0x7
# The executable starts automatically)
参考资料: http://vedder.se/2012/12/debugging-the-stm32f4-using-openocd-gdb-and-eclipse/如果程序已经编译通过的话,那么鼠标点击Run->External Tools->External Tools Configurations..,在弹出的窗口中鼠标左键选择Program->OpenOCD,即之前已经配置过的OpenOCD,并且单击Run开启openocd守护进程。然后再鼠标点击Run->Debug Configurations..,在弹出的串口中鼠标左键选择Zylin Embdded debug(Native)目录下的已经配置好的选项,并点击窗口右下角的Debug,即开始运行,中途如果出现窗口询问,点击yes,然后进入调试窗口,按F8使其自动运行,然后PC指针会在main函数第一条程序处停下来,如下图所示:接下来的调试就像在调试PC上运行的程序一样简单方便了!