一、概述
1、說明
筆者已經寫了一篇Linux下STM32開發環境的搭建 ,這兩篇文章的最區別在於開發環境所處的系統平台不一樣,而其實這個區別對於開發環境的搭建其實影響不大,制作局部上的操作上發生了改變。鑒於此,本文沒有必要對windows下搭建STM32開發環境的詳細過程進行闡述,讀者可以結合Linux下STM32開發環境的搭建和本文進行windows下STM32開發環境的搭建。
2、開發環境描述
硬件開發板:野火STM32開發板
Cortex-M3型號:STM32F103VET6
下載器與調試接口:Jlink + JTAG
操作系統:windows XP
集成開發環境平台:eclipse IDE for C/C++ developers
交叉編譯鏈:arm-none-eabi-gcc
調試服務器:JLink GDB Server
二、搭建步驟
1、安裝eclipse IDE for C/C++ developers
- 下載地址:https://www.eclipse.org/downloads/
- 選擇安裝包:eclipse IDE for C/C++ developers(windows 版本)
安裝之后,Eclipse還不能正常運行,因為Eclipse要運行在Java虛擬機上,所以還需要安裝JDK或者JRE,以創建Java虛擬機,給Eclipse的運行提供一個環境。
2、安裝JDK
參考安裝JDK,安裝JDK成功之后,重新啟動Eclipse就可以看到能夠成功運行了。
3、安裝交叉編譯鏈arm-none-eabi-gcc
- 下載地址:https://launchpad.net/gcc-arm-embedded/+download
- 選擇版本:Windows installer
- 雙擊安裝,注意在安裝的最后選擇不要把安裝路徑添加到環境變量中(否則將會把安裝路徑添加到用戶的環境變量PATH中,當將來安裝其他版本的工具鏈時,有可能發生名字沖突)
- 測試安裝是否成功
4、安裝編譯工具(make & rm)
make 和 rm 是Linux和OS X下的工具,windows上沒有這樣的工具,但是使用交叉編譯鏈時需要調用Makefile腳本,其中使用了這些工具。所以,在windows上還需要安裝這樣的工具。
- 下載地址:http://sourceforge.net/projects/gnuarmeclipse/files/Miscellaneous/
- 解壓后就可以使用,在使用前先進行重命名,去掉"cs-“前綴
- 檢查版本
- 添加此編譯工具的目錄到Eclipse的環境變量中,Eclipse的環境變量都在選項Window->Preference中
The echo command
The archive also contains an executable for the echo command. It is not mandatory for the build to succeed, but it is recommended to have it in the build path, to avoid an annoying CDT bug, that triggers an error during the first build of a new project, claiming that ‘Program “gcc” not found in PATH’.
參考:Build tools (make & rm) on Windows
5、安裝JLink軟件
JLink軟件包含:GDB Server、JLink驅動等等工具
注意:JLinkGDBServer.exe、JLinkGDBServerCL.exe其實是相同的工具,都是GDB調試服務器。區別在於前者是圖形界面,而后者是命令行界面。在windows上使用的話,推薦使用命令行模式的工具。
6、安裝GNU ARM Eclipse插件包
此插件包包含了6個插件,能實現不同的功能。其中第一個插件是為了使Eclipse支持交叉編譯,最后的兩個是硬件調試的支持。
7、新建一個LED_Test工程並配置、編譯
參考2:STM32開源開發環境的搭建
另外,倘若交叉編譯工具鏈找不到的話,可以看看下邊的選項是否配置正確
倘若想要生成反匯編、Map文件等,可以在Build Steps中添加命令
三、使用GDB Hardware Debugging進行硬件調試
1、安裝GDB調試插件--C/C++ GDB HardWare Debugging
- Eclipse-->Help-->Install new software-->ADD
名字:CDT Juno
地址:http://download.eclipse.org/tools/cdt/releases/juno
- 選中插件C/C++ GDB HardWare Debugging
- 一路Next,完成安裝
2、設置Eclipse調試環境並啟動調試
四、使用GDB SEGGER J-Link Debugging調試
1、GDB SEGGER J-Link Debugging優於GDB Hardware Debugging
- transparent integration of the GDB server, automatically started/stopped for each debug session
- advanced graphical user interface to configure most GDB client and GDB server SEGGER specific options
- transparent integration of the semihosting and Serial Wire Viewer (SWV) window as a standard Eclipse console
- a functional restart button, to reset the target and restart the debugging session, without having to rewrite the executable image
- direct use of project toolchain definition (prefix, suffix, path) to simplify configuration of the GDB client
- macro based J-Link folder path definition, for simplified management of the GDB server location when upgrades to new SEGGER versions are released
- support for SWO registers configuration to match a given system clock frequency
2、安裝GDB SEGGER J-Link Debugging插件
在我們安裝GNU ARM Eclipse插件包的時候,已經將這個插件安裝了
3、配置Eclipse調試環境並啟動調試
1> 將Jlink軟件的安裝目錄添加到Eclipse的環境變量中,此環境變量再接下來的配置中會用到
2> 設置Debug Configurations
3> 啟動調試
本章參考:The J-Link hardware debugging Eclipse plug-in
五、直接使用arm-none-eabi-gdb進行調試
1、創建系統環境變量HOME
變量的值為當前登陸用戶目錄,例如管理員目錄:C:\Documents and Settings\Administrator
2、在用戶目錄中創建.gdbinit文件
在winows上創建以“.”開頭的文件方法是在Windowx下創建以點開頭的.hatccess文件。該文件的內容為:
set auto-load safe-path /
3、在工程的Debug目錄中創建.gdbinit文件
target remote :2331 set mem inaccessible-by-default off monitor speed auto monitor endian little monitor reset monitor flash device = STM32F103ZE monitor flash breakpoints = 1 monitor flash download = 1 load monitor reg sp = (0x08000000) monitor reg pc = (0x08000004) break ResetHandler break main continue
4、啟動JlinkGDBServerCL
進入Jlink軟件的安裝目錄,啟動JlinkGDBServerCL
5、啟動調試
打開命令終端(win徽標+R-->cmd),進入工程的Debug目錄,輸入調試命令
調試結果如下:
此時JlinkGDBServerCL的情況如下: