在windowns下開發stm32剛開始學最煩的就是創建工程模板,都不知道為什么要那樣設置,而且步驟繁多。現在我告訴大家一個好消息,在linux下配置stm32開發環境包括創建工程,使用JLink仿真簡單到我都不知道怎么寫教程了,什么固件庫,OPENOCD,都成了浮雲。
先上我自己整理軟件,包括eclipse, arm-none-eabi-gcc, stm32 m3 3.5固件庫(備用),stm32 for eclipse插件, JLink 4.78驅動,JLink固件(在 JLink 4.78驅動下不丟固件,但要下進去以后在windowns下面升個級),還有stlink驅動,以及串口下載軟件都是linux下的,足夠讓玩stm32的linux用戶爽一陣了。
下載地址 http://pan.baidu.com/s/1c0GJiLE
1.安裝arm-none-eabi-gcc:
直接解壓復制到自己的安裝目錄下。我是在用戶目錄下建了一個software文件夾,直接放到里面就可以了。
設置好路徑:Ctrl+Alt+T
鍵入命令 sudo gedit ~/.profile
在password:輸入自己的密碼,不顯示。
在打開的文件最后面添加自己的路徑。我的是/home/godsend/software/arm-none-eabi-gcc/bin所以我自己的路徑就是
export PATH=$PATH:"/opt/microchip/xc8/v1.21/bin:/home/godsend/software/arm-none-eabi-gcc/bin:/home/godsend/software/opt/FriendlyARM/toolschain/4.4.3/bin:/home/godsend/software/jdk1.7.0/bin:/home/godsend/software/stlink-master:/home/godsend/software/stm32flash"
由於我的軟件比較多就是這樣,在這要注意一下,不同路徑之間用冒號隔開。完了以后重啟一下系統,使剛才設置的路徑生效。
打開終端,運行arm-none-eabi-gcc -v
如果出現下面的內容就說明arm-none-eabi-gcc已經安裝成功。
GNU gdb (GNU Tools for ARM Embedded Processors) 7.4.1.20121207-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
godsend@godsend-Vostro-1088:~$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/home/godsend/software/arm-none-eabi-gcc/bin/../lib/gcc/arm-none-eabi/4.7.3/lto-wrapper
Target: arm-none-eabi
Configured with: /home/build/work/GCC-4-7-build/src/gcc/configure --target=arm-none-eabi --prefix=/home/build/work/GCC-4-7-build/install-native --libexecdir=/home/build/work/GCC-4-7-build/install-native/lib --infodir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-lto --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/home/build/work/GCC-4-7-build/install-native/arm-none-eabi --build=i686-linux-gnu --host=i686-linux-gnu --with-gmp=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-mpfr=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-mpc=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-ppl=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-cloog=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-libelf=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for ARM Embedded Processors' --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r
Thread model: single
gcc version 4.7.3 20121207 (release) [ARM/embedded-4_7-branch revision 194305] (GNU Tools for ARM Embedded Processors)
2.安裝JLink驅動
首先在ubuntu軟件中心安裝gdebi,右擊JLink.deb選擇open with的GDebPackage installer來安裝(32位系統就選i386,64位系統就選x86_64)。
3.安裝eclipse
直接解壓,復制到自己的安裝目錄,我的是/home/godsend/software,進入eclipse目錄雙擊eclipse打開,單擊菜單欄Help下的Install New Software.
打開Install窗口,點擊Add,在Name處填STM32(可以隨意),在Location右邊點擊Archive,選擇剛下載好的ilg.gnuarmeclipse.repository-1.8.1-201401111229.zip,點擊OK
勾選剛才添加的插件。
一路Next+Agree+Ok,完成后eclipse會重啟。
到這里安裝已經完成了。
下面我們來點亮地一個發光二極管。
創建工程
點擊菜單欄File下的New,C Project.在Priject Name里填入工程名,m3,其他如圖,是不是簡單多了。
Next
我的芯片的STM32F103VE,所以選擇STM32f10x Hight Density ,Flash是512K,RAM是64K,自己根據自己的芯片選擇填。然后就是3個Next+1個Finish.
工程創建完了以后會發現有很多錯誤,怎么辦呢?其實不用管,過個幾秒鍾自己就沒有了。
工程已經建立完成。現在編譯就能通過,根本不用配置。不信我們可以查看工程文件夾和工程屬性。
芯片選擇OK!
庫鏈接OK!
宏定義OK!
腳本鏈接OK!
編譯沒有報錯,已經產生m3.hex文件。
不過在這需要設置一下。讓它產生.bin文件,原因是下載軟件好像都只支持二進制文件,
在編譯一下。產生了m3.bin文件
仿真。。。。。
菜單欄run下的Debug Configuration,在打開的窗口雙擊GDB SEGGER J-Link Debugging.
好像也配置好了。需要自己設置的可以自己設置一下,我的板子是SWD接口,在終端打開JLinkGDBServer找不到芯片,不知道什么原因,用別人的JTAG接口應該能夠直接點擊Debug運行了。
我只好借助JLink的命令下載了。
打開終端,命令JlinkExe
然后在輸入
h
speed 4000
exec device = STM32F103VE
loadbin m3.bin 0x8000000
r
g
這時就能看到板子上pinc12腳的LED在閃爍了。
解釋一下命令:
h //暫停運行
speed 4000 //設置下載速度
exec device = STM32F103VE //芯片型號
loadbin m3.bin 0x8000000 //下載命令 stm32的flash下載地址是0x8000000,
r //復位
g //運行
stlink:stlink-master
安裝:直接解壓復制到安裝目錄下,設置環境變量。參考arm-none-eabi-gcc的設置過程。
下載命令:st-flash write m3.bin 0x8000000
仿真用st-util,有興趣可以自己配置一下,這里就不多說了。
串口下載:stm32flash
解壓進入目錄make一下,產生可執行文件,全部復制到安裝目錄下,設置環境變量。參考arm-none-eabi-gcc的設置過程。有興趣的可以自己baidu or google。
ubuntu下的51開發環境:sdcc+8052ide +avrdude/gSTC-ISP/kSTC89-ISP/kSTC12-ISP,avrdude稍微配置一下就可以用USBasp下載At89s52,其他可以下載STC的89和12系列的最好配個自動下載器就更好了。整理好的下載地址,比較容易。
http://pan.baidu.com/s/1eQDrt2U
ubuntu下的AVR開發環境:avr-gcc+avrdude+kontrollerlab(IDE),支持很多下載工具。avr-gcc直接在ubunru的軟件中心找,安裝kontrollerlab(IDE)時可能會需要一些依賴包,我都整理在一起了,需要什么裝什么就可以,也比較簡單,
http://pan.baidu.com/s/1o6scryU
ubuntu下的pic開發環境:就兩個文件,很簡單。用bash安裝。
http://pan.baidu.com/s/1i3JqN4p
FPGA開發環境軟件4G多無法上傳,可以到Altera官網下載free版。我的是12.0sp1的,安裝類似與PIC但需要配置一下,也比較簡單,自己可以baidu or google一下。
Arduino在ubuntu的軟件中心就可以找到,要選擇最新版,舊版本有點小BUG。