跳到主要內容

[Arduino][Eclipse]使用原生的Eclipse CDT建立Andes Andino M1燒錄檔

這篇文章在Windows上以原生的Eclipse CDT,建立Andes Andino M1燒錄檔,藉機探索Andes Andino M1的編譯流程。
歡迎各位多多指教~

前言提要

由於Arduino原生的IDE對於編寫程式的支援度不足,無法像一般編寫程式那樣點一下追蹤進每個function,也無法進行太多編譯參數的控制,所以想要使用Eclipse重建整個編譯流程,而Arduino搭配Eclipse其實不是件新鮮事,已經有Arduino Eclipse Plugin,Andes也在knect.me上提供Eclipse Arduino IDE,但是在選擇板子那邊一直沒看到Andino M1選項,而且再也不想繼續被Arduino的sketch綁住,讓我們回歸最原生的C++程式吧~

準備環境

請先Arduino IDE安裝完成與板子安裝(參考之前的文章)
從Eclipse官網下載Eclipse IDE for C/C++ Developers: https://eclipse.org/downloads/
基礎Eclipse操作請自己Google了歐~

建立核心專案

在先前的文章有提過,在撰寫Arduino sketch時,Arduino IDE會送你一包核心程式碼!!
這些核心程式碼就在Arduino IDE的board manager安裝板子時,幫你下載安裝的。
預設位置在%HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15
(%HOMEDRIVE%%HOMEPATH%是Windows上相應於Linux的HOME directory,可以下echo %HOMEDRIVE%%HOMEPATH%來看你的結果)
我們將這些核心程式碼建立為靜態函示庫,供Arduino sketch應用連結。
以下是Eclipse的核心專案建立步驟:
  1. [File]->[New]->[C++ Project],Project Name這裡為AndinoM1_Cores1.6.5,Project Type為Static Library,Toolchains為Cross GCC,按[Next]選擇Configuration可以只保留Debug,再按[Next]設定Cross Compiler Prefix為nds32le-elf-,設定Cross Compiler Path為%HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\bin(這一步一定要寫絕對位置,請一定要將%HOMEDRIVE%%HOMEPATH%展開,否則Eclipse會報錯)
  2. 將%HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\hardware\nds32\1.6.5\cores\arduino底下的程式碼複製到新建立的project下
  3. 對專案按右鍵,點[Properties]開始設定Project Properties,以下參數設定:
    [C/C++ Build]->[Builder Settings]->Builder type: Internal builder,讓Eclipse自己依照source code產生Makefile,不用自己寫Makefile
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Compiler]->[Symbols]->[Defined symbols(-D)]:
    ARDUINO=10607
    ARDUINO_Andino
    ARDUINO_ARCH_NDS32
    F_CPU=60000000L
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Compiler]->[Includes]->[Include paths(-I)]:
    "${workspace_loc:/${ProjName}}"
    "${workspace_loc:/${ProjName}/sys/m2c-arch}"
    "${workspace_loc:/${ProjName}/sys/inc}"
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Compiler]->[Optimization]->[Optimization Level]: Optimize for size(-Os)
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross G++ Compiler]->[Preprocessor]->[Defined symbols(-D)]:(同GCC的Defined symbols)
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross G++ Compiler]->[Includes]->[Include paths(-I)]:(同GCC的Include paths)
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross G++ Compiler]->[Optimization]->[Optimization Level]: Optimize for size(-Os)
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Archiver]->[General]->[Archiver flags]: rcs
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Assembler]->[Command]: gcc,Andes Andino M1這邊使用gcc
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Assembler]->[General]->[Assembler flags]: -g3 -Wall -DARDUINO=10607 -DARDUINO_Andino -DARDUINO_ARCH_NDS32 -DF_CPU=60000000L
    [C/C++ Build]->[Settings]->[Tool Settings]->[Cross GCC Assembler]->[General]->[Include paths(-I)]:(同GCC的Include paths)
  4. 在以上設定後應可成功編譯出libAndinoM1_Cores1.6.5.a,但是在點開source code會發現Eclipse有Unresolved symbol(如:stdio.h等都找不到),因為nds32le-elf toolchain吐出的compiler built-in path為cygwin的路徑,導致Eclipse找不到built-in的header而看不懂,這裡我的解法是依照CDT Cross GCC Built-in Compiler Settings加入User Setting Entries
    [C/C++ General]->[Preprocessor Include Paths, Macros etc.]->[Entries]->[GNU C]->[CDT User Setting Entries]:(以下%HOMEDRIVE%%HOMEPATH%請在Eclipse使用絕對路徑,否則會報錯)
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\lib\gcc\nds32le-elf\4.9.2\include
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\lib\gcc\nds32le-elf\4.9.2\include-fixed
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\sys-include
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\include
    [C/C++ General]->[Preprocessor Include Paths, Macros etc.]->[Entries]->[GNU C++]->[CDT User Setting Entries]:(以下%HOMEDRIVE%%HOMEPATH%請在Eclipse使用絕對路徑,否則會報錯)
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\include\c++\4.9.2
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\include\c++\4.9.2\nds32le-elf
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\include\c++\4.9.2\backward
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\lib\gcc\nds32le-elf\4.9.2\include
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\lib\gcc\nds32le-elf\4.9.2\include-fixed
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\sys-include
    %HOMEDRIVE%%HOMEPATH%\AppData\Local\Arduino15\packages\Andino\tools\nds32le-elf-mculib-v3m\4.0.3\nds32le-elf\include

    其中,CDT User Setting Entries可以按右邊的Export將專案設定繼承給reference此專案的子專案
  5. 完成~(當然記得要按build project)

建立LED Blink應用專案

在應用專案中,我們使用Arduino範例LED Blink的sketch,一樣建立C++ project,compiler設定等等的都是相同的,不同的點下列:
  1. 建立Project Type為Executable
  2. Linker為g++,command line pattern為
    ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} -Wl,--start-group ${INPUTS} -Wl,--end-group
    加上start-group與end-group
    勾起nostartfiles、nostdlib
    Libraries(-l): AndinoM1_Cores1.6.5、gloss、gcc、c、stdc++、m
    Library search path(-L): "${workspace_loc:/AndinoM1_Cores1.6.5/Debug}"
    linker flags: -static -T"${workspace_loc:/AndinoM1_Cores1.6.5/sys/board/M2C8001.ld}",提供_start的起始位置
  3. Builder Post-build steps加入:
    nds32le-elf-objcopy -O binary -R .note -R .comment -S ${ProjName}.elf ${ProjName}.bin
    將elf檔進行objcopy
  4. 建立一sketch_proxy.cpp檔案,來連結cpp與sketch,內容如下:
    #include <Arduino.h>
    
    void setup();
    void loop();
    
    #include "Blink.ino"
    
  5. 編譯與建置完成~

源碼下載

由於以上步驟時在蠻雜的,所以就open source在github上給各位了~

留言

這個網誌中的熱門文章

Run Android VTS with Android R emulator through WSL

Background Android VTS The Android Vendor Test Suite (VTS) provides extensive new functionality for Android testing and promotes a test-driven development process. Android R emulator Run the latest Android R image from Google CI build artifacts WSL WSL is a collection of components that enables native Linux ELF64 binaries to run on Windows . It contains both user mode and kernel mode components. It is primarily comprised of: User mode session manager service that handles the Linux instance life cycle Pico provider drivers (lxss.sys, lxcore.sys) that emulate a Linux kernel by translating Linux syscalls Pico processes that host the unmodified user mode Linux (e.g. /bin/bash) It is the space between the user mode Linux binaries and the Windows kernel components where the magic happens. By placing unmodified Linux binaries in Pico processes we enable Linux system calls to be directed into the Windows kernel. The lxss.sys and lxcore.sys drivers translate the Linux s...

[Qt][Embedded][PXA270]
Porting Qt 4.8.6 for Creator XScale PXA270

這篇文章介紹這學期我在嵌入式作業系統課程,使用Creator XScale PXA270板子的一些學習筆記與製作final project的一些過程,歡迎各位多多指教~ 背景介紹 Creator XScale PXA270開發版是一塊由 新華電腦(microtime) 公司出品的 模組化XScale/ARM/SoC/FPGA/DSP嵌入式行動通訊發展平台 ,在此課程與final project主要使用的是"Create XScale‐PXA270 子板"與"MTLCD‐0708048 LCD Module",在Create XScale‐PXA270子板上的為Intel(現在已出售給Marvell)的 Xscale系列 PXA270 處理器,基於ARMv5TE架構指令集,在旁附有SDRAM Memory 64MB、Flash Memory 32MB、SD Card Connectors、RJ45 10/100 Base‐T Ethernet Interface、USB 1.1 Device/Host Port各一、AC97 Audio Codec(Line_in、Mic_in、Headphone)、ADC Interface*4、PWM Interface、CMOS Camera Interface、TFT-LCD Interface、GPIO Interface...等;在軟體功能部分,由新華科技提供了GNU GCC cross compiler toolchain(arm-unknown-linux-gnu-gcc 4.0.2)、Uboot 1.1.5、Linux Kernel 2.6.15.3與patch(提供支援子板上的Ethernet、USB Host、TFT‐LCD(Frame buffer、Touch Screen)、AC97‐Codec...等與母板LED、7‐Seg LED、Key Pad...等的device driver)、rootfs,相關的實驗環境設定可以參考 User Guide 。 看到以上這麼多的軟硬體介面,別以為這板子有多強,其實這是 2006 年 ASUS P535 手機使用的規格了,不禁讓人感嘆科技進步之快阿~ 在此附上開發版本尊 Qt 是自由且開放原始碼的跨平台C...

[Android][AOSP][ddmlib][Intelij IDEA][Gradle]搭建Android ddmlib編譯環境

Android ddmlib在AOSP的platform/tools/base的repo內 可以使用以下指令將整個repo的master branch抓回: git clone https://android.googlesource.com/platform/tools/base 取其中的annotations、common、ddmlib 建立Intelij IDEA專案 使用Intelij IDEA開一新的Java Project,GroupId、ArtifictedId、Version隨便,並使用graddle wrapper方式建立專案: GroupId 'com.android.tools.ddms' ArtifictedId = 'ddmlib' Version '1.0-SNAPSHOT' 刪除IDE建立的src資料夾,建立base資料夾,將annotations、common、ddmlib複製進來 參考Android Studio建立的專案,修改build.gradle為: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenCentral() } } allprojects { repositories { mavenCentral() } } task clean(type: Delete) { delete rootProject.buildDir } 修改settings.gradle,加入annotations、common、ddmlib為include rootProject.name = 'ddmlib' include ':base:annotations' include ':base:common' include ':base:ddmlib' 修改annotations、common、ddmlib內的b...