在Windows平台下使用armgcc的方法(配合nRFSDK5)

首先要安裝armgcc這套工具, 可以到GNU-RM Downloads頁面下載。

接著, 因為要使用Makefile, 所以在Windows平台要安裝Gnu make for windows

若要配合nRF SDK使用, 必須讓nRF SDK知道armgcc工具安裝在那裡, 所以要在nRF5_SDK安裝目錄下的\components\toolchain\gcc目錄下找到Makefile.windows檔案, 打開它:

GNU_INSTALL_ROOT := C:/Program Files (x86)/GNU Tools ARM Embedded/8 2019-q3-update/bin/
GNU_VERSION := 8.3.1
GNU_PREFIX := arm-none-eabi

將工具安裝的位置修改成正確的後, 就可以在nRF5_SDK_15.3.0_59ac345\examples\peripheral\blinky_systick\pca10059\blank\armgcc的目錄下, 於命令提示字元下, 直接下make指令來進行編譯了。

現在Windows平台上也有Linux的環境, WSL bash, 或者MinGW等,
使用這些環境, 也是可以的, 先安裝armgcc工具和make工具:
$ sudo apt-get install gcc-arm-none-eabi
$ sudo apt-get install make
這個方式安裝的版本比較舊, 但看來還是可以用!
用這個方式的話, 也要告訴nRF SDK我們把armgcc工具安裝在那裡, 同樣在nRF5_SDK安裝目錄下的\components\toolchain\gcc目錄下找到Makefile.posix檔案, 打開它:

GNU_INSTALL_ROOT ?= /usr/bin/
GNU_VERSION ?= 6.3.1
GNU_PREFIX ?= arm-none-eabi

同樣要修改安裝的位置和版本, 然後同樣直接下make指令就可以了。

$ make
Assembling file: gcc_startup_nrf52840.S
Compiling file: nrf_log_frontend.c
Compiling file: nrf_log_str_formatter.c
Compiling file: boards.c
Compiling file: app_error.c
Compiling file: app_error_handler_gcc.c
Compiling file: app_error_weak.c
Compiling file: app_util_platform.c
Compiling file: nrf_assert.c
Compiling file: nrf_atomic.c
Compiling file: nrf_balloc.c
Compiling file: nrf_fprintf.c
Compiling file: nrf_fprintf_format.c
Compiling file: nrf_memobj.c
Compiling file: nrf_ringbuf.c
Compiling file: nrf_strerror.c
Compiling file: nrfx_atomic.c
Compiling file: nrfx_systick.c
Compiling file: main.c
Compiling file: system_nrf52840.c
Linking target: _build/nrf52840_xxaa.out
   text    data     bss     dec     hex filename
   2544     116     172    2832     b10 _build/nrf52840_xxaa.out
Preparing: _build/nrf52840_xxaa.hex
Preparing: _build/nrf52840_xxaa.bin
DONE nrf52840_xxaa

可以看到在_build子目錄下, 成功產生了nrf52840_xxaa.hex檔, 這個檔之後用燒錄工具燒到板子去, 就可以看執行結果了。

因為針對armgcc工具, 在Windows平台下可以使用Windows版的工具, 也可以用bash等工具, 所以自己要注意, 最好只擇一而用, 如果交互使用, 因為檔案的格式仍有不同, 會有錯誤產生! 但這不是程式寫錯, 而是工具問題, 只要把_build子目錄下的編譯中間檔案都刪除, 再重新編譯, 就會成功。

留言

這個網誌中的熱門文章

D-BUS學習筆記

關於藍牙裝置找尋(inquiry, scan)兩三事

Cisco Switch學習筆記: EtherChannel