转自:http://blog.chinaunix.net/uid-26849357-id-3534534.html
1. Sourcery G++ Lite安装
a.去官网下载Sourcery G++ Lite源码包并解压
假设下载目录:~/Software/Sourcery_G++_Lite/package.tar.bz2
安装目录: ~/Software/Sourcery_G++_Lite/Setupp
依次执行下面4条指令:
bunzip2 ~/Software/Sourcery_G++_Lite/package.tar.bz2
mkdir ~/Software/Sourcery_G++_Lite/Setupp
cd ~/Software/Sourcery_G++_Lite/Setupp
tar xf ~/Software/Sourcery_G++_Lite/package.tar
然后发现路径 ~/Software/Sourcery_G++_Lite/Setupp 下出现一个解压后的文件夹 arm-2011.03
b.设置环境变量
打开 ~/.bash_profile 文件 加入环境变量 $HOME/Software/Sourcery_G++_Lite/Setupp/arm-2011.03/bin
c.检测路径是否设置正确
> arm-none-eabi-g++ -v
查看终端最后一行输出是否包含:Sourcery G++ Lite 2011.03-42.
2. OpenOCD安装
a.下载OpenOCD源码包并安装
./configure --enable-ft2232_libftdi 出现error:Cannot build &run test program using libftdi
这是因为OpenOCD信赖于libftdi和libusb,先安装这两个包,如果用源码包安装后还出现上面的错误就用yum命令安装OpenOCD来自动解决依赖,
然后再回到OpenOCD源码包中分别运行下述指令
./configure --enable-ft2232_libftdi
./configure --enable-jlink
make
make install
3. 用jlink+OpenOCD+Sourcery连接板子并在线仿真
a.将jlink仿真器连接板子
b.在终端打开OpenOCD
打开一个终端输入下面两条指令:
cd /usr/local/share/openocd/scripts
openocd -f interface/jlink.cfg -f target/stm32f1x.cfg
执行上述两条指令后即打开了OpenOCD,下面进行在线仿真时要保持该终端不变,另打开一个新终端操作
c.使用Sourcery G++ Lite进行在线仿真
打开一个新的终端输入
arm-none-eabi-gdb 回车
(gdb) target remote localhost:3333
(gdb) monitor reset init
(gdb) monitor halt //执行load之前应先执行该指令将运行的程序暂停
(gdb) load gpio_test.o
(gdb) symbol-file gpio_test.o
(gdb) n //单步运行
(gdb) c //连续运行
此时可应用gdb的一些命令如break 30, info breakpoints, delete 1等进行调试。