Kineties-L是32位的微處理器家族,基于ARM Cortex M0+。我手上有一個(gè)FRDM-KL25Z的開(kāi)發(fā)板,官方有一個(gè)基于eclipse的IDE——CodeWarrior,可以很方便地進(jìn)行編譯、下載、調(diào)試。但是不足的是免費(fèi)版本的CodeWarrior不能很方便地使用C++,如圖,當(dāng)我選擇C++時(shí)就不能選擇Device Initialization或者Processor Expert了。
我們使用eclipse來(lái)配置一個(gè)純凈的KL25Z的開(kāi)發(fā)環(huán)境:
1、 安裝交叉編譯工具:
a) 首先安裝交叉編譯工具,推薦使用Codesourcery。
http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/
b) 選擇ARM processors,點(diǎn)擊Download the EABI Release,在隨后的頁(yè)面中注冊(cè)賬戶(有賬戶的話直接登錄),下載鏈接會(huì)發(fā)送到你注冊(cè)的郵箱中。
c) 然后下載,安裝。
d) 安裝完畢后就能在命令行下編譯ARM程序了。
2、 安裝eclipse:
a) 訪問(wèn)http://www.eclipse.org/downloads/
b) 下載Eclipse IDE for C/C++Developers。
c) 解壓即可使用。(前提是已經(jīng)安裝JDK)
3、 安裝GNU ARM Eclipse Plug-in
這是一個(gè)eclipse的插件,裝上這個(gè)插件之后,eclipse就能夠編譯ARM程序了。
a) 在eclipse中點(diǎn)擊Help->Install New Software,輸入
http://gnuarmeclipse.sourceforge.net/updates/
b) 安裝成功后就能使用GNU ARM Eclipse插件了。
4、 新建C++工程
a) 輸入工程名
b) 工程類型選擇ARM Cross Target Application->Empty Project
c) 工具鏈選擇ARM Windows GCC (Sourcery G++ Lite)
a) 首先加入在CodeWarrior中新建C++工程時(shí)生成的代碼,包括三個(gè)目錄:Project_Headers、Project_Setting、Sources

b)
6、 配置工程
因?yàn)?span xml:lang="EN-US">CodeWarrior也是使用eclipse來(lái)配置工程的,所以可以參照CodeWarrior來(lái)配置工程。
a) 在工程文件夾上單擊右鍵,選擇Properties。在彈出的對(duì)話框中選擇C/C++ Build->Setting。
b) Target Processor:
Processor: cortex-m0
Endiannes: Little Endian (-mlittle-endian)
Float ABI: Library (-mfloat-abi=soft)
c) Debugging
Debug level: Maximum (-g3)
d) Additional Tools
e) ARM Sourcery Windows GCC Assembler
Command line pattern:
${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
f) ARM Sourcery Windows GCC C Compiler
因?yàn)?span xml:lang="EN-US">eclipse會(huì)根據(jù)源文件的后綴名來(lái)判斷使用gcc還是g++,為了統(tǒng)一使用g++來(lái)編譯程序,將Command修改為arm-none-eabi-g++。
Command line pattern:
${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
g) Preprocessor
將Do not search system directories (-nostdinc)打鉤
h) Directories
加入Include路徑:
"${workspace_loc:/${ProjName}/Project_Headers}"
"${workspace_loc:/${ProjName}/Sources}"
"${workspace_loc:/${ProjName}/Generated_Code}"
"${workspace_loc:/${ProjName}/Project_Settings/Startup_Code}"
"D:\Freescale\CW MCU v10.3\MCU\ARM_GCC_Support\ewl\EWL_C\include"
"D:\Freescale\CW MCU v10.3\MCU\ARM_GCC_Support\ewl\EWL_C++\include"
"D:\Freescale\CW MCU v10.3\MCU\ARM_GCC_Support\ewl\EWL_Runtime\include"
其中后面三個(gè)在CodeWarrior的安裝目錄下。
i) Optimization
在Function sections (-ffunction-sections)和Data sections (-fdata-sections)前打鉤
j) Miscellaneous
在Other flags寫(xiě)入:-c -fmessage-length=0 -Iinclude -include lib_ewl_c++.prefix
k) ARM Sourcery Windows GCC C++ Compiler
和前面的ARM Sourcery Windows GCC C Compiler配置相同。
l) ARM Sourcery Windows GCC C++ Linker
Command line pattern:
${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
m) ARM Sourcery Windows GCC C++ Linker
Script file (-T)中寫(xiě)入工程中的鏈接文件
C:\Users\wangqi\workspace-cpp\cpp\Project_Settings\Linker_Files\MKL25Z128_flash.ld
n) Libraries
Library search path中寫(xiě)入庫(kù)文件的路徑:
"D:\Freescale\CW MCU v10.3\MCU\ARM_GCC_Support\ewl\lib\armv6-m"
o) Miscellaneous
Linker flags (-Xlinker [option])中寫(xiě)入:
--undefined=__pformatter_
--defsym=__pformatter=__pformatter_
--start-group
-lc++ -lrt -lsupc++ -lc -lgcc -luart
--end-group
Other flags中寫(xiě)入:
-n
7、 修改程序
此時(shí)如果運(yùn)行程序會(huì)發(fā)生這樣的錯(cuò)誤:
問(wèn)題出在Vector.c中,打開(kāi)Vector.c文件尋找__thumb_startup(void)聲明。
將extern void __thumb_startup( void );改成extern "C" void __thumb_startup( void );
8、 將elf文件轉(zhuǎn)化成bin文件
點(diǎn)擊工程目錄右鍵,選擇Properties->C/C++ Build->Setting->Build Steps
在Post-build steps一項(xiàng)的Command中輸入
arm-none-eabi-objcopy -O binary -S cpp.elf cpp.bin