如何在Mac用JLink燒錄nRF52程式到device

Tony Yeh
5 min readApr 28, 2017

我在台灣遇到的每一個firmware engineer都告訴我必須要用Windows系統才行(我本人試過Macbook上面裝Windows也可以)。直到我在大陸出差時遇到一位美國同事M君。M君是非常資深的Firmware Engineer已經在Broadcomm幹了10多年,擺在他桌上的是一台Macbook pro。這也讓我確信一定有方法可以用MacOS做到。

參考文章1: https://devzone.nordicsemi.com/blogs/22/getting-started-with-nrf51-development-on-mac-os-x/

參考文章2: https://devzone.nordicsemi.com/tutorials/7/development-with-gcc-and-eclipse/

環境

  • 系統:MacOS Sierra 10.12.4
  • Device: nRF52 晶片
  • Firmware code: Nordic SDK 13

安裝工具

  • Nordic nRF52 SDK: /nRF5_SDK/nRF5_SDK_v13.x.x/nRF5_SDK_13.0.0_04a0bfd.zip
  • softdevice: 在上面那個zip解開之後,在$(NRFSDK)/components/softdevice/s140/hex 裡面 (注意 nRF SDK 13.0.0 需搭配 softdevice s140)
  • ToolChain: GCC Arm Embedded: 在右邊的download區域找到最新版的for mac的壓縮檔
  • Jlink software on mac: 拜訪segger網站,找J-Link / J-Trace Download -> J-Link Software and Documentation Pack for MacOSX
  • nRF Command Line Tool for OSX: 抓最新版9.4.0。包含nrfjprog(把hex燒進device)以及mergehex(把bootloader, softdevice, application, settings包在一起的工具),為了使用方便,建議把這兩個tool加進你bash的path裡面。

編譯程式

  1. 把ToolChain解開之後,放在電腦任何一個目錄下都可以。
  2. 修改$(NRFSDK)/components/toolchain/gcc/Makefile.posix
GNU_INSTALL_ROOT := /Users/tony/Projects/Nordic/gcc-arm-none-eabi-5_4-2016q3 <-- Change to your toolchain location 
GNU_VERSION := 5.4.3
GNU_PREFIX := arm-none-eabi

3. 找一個example來make。

$ cd examples/ble_peripheral/experimental_ble_app_blinky/pca10040/s132/armgcc
$ make
mkdir _build
Compiling file: nrf_log_backend_serial.c
Compiling file: nrf_log_frontend.c
Compiling file: app_button.c
Compiling file: app_error.c
Compiling file: app_error_weak.c
Compiling file: app_scheduler.c
Compiling file: app_timer.c
Compiling file: app_util_platform.c
Compiling file: hardfault_implementation.c
Compiling file: nrf_assert.c
Compiling file: nrf_strerror.c
Compiling file: boards.c
Compiling file: nrf_drv_clock.c
Compiling file: nrf_drv_common.c
Compiling file: nrf_drv_gpiote.c
Compiling file: nrf_drv_uart.c
Compiling file: main.c
Compiling file: RTT_Syscalls_GCC.c
Compiling file: SEGGER_RTT.c
Compiling file: SEGGER_RTT_printf.c
Compiling file: ble_advdata.c
Compiling file: ble_conn_params.c
Compiling file: ble_srv_common.c
Compiling file: nrf_ble_gatt.c
Assembling file: gcc_startup_nrf52.S
Compiling file: system_nrf52.c
Compiling file: ble_lbs.c
Compiling file: softdevice_handler.c
Linking target: _build/nrf52832_xxaa.out
text data bss dec hex filename
21200 500 2088 23788 5cec _build/nrf52832_xxaa.out Preparing: _build/nrf52832_xxaa.hex
Preparing: _build/nrf52832_xxaa.bin

燒錄程式

$ nrfj prog -f NRF52 --program file.hex --chiperase --verify

Debug程式

  1. 打開Terminal輸入 $ JLinkExe -device nRF51422 -speed 4000 -if SWD 保持開啟
  2. 打開另一個Terminal視窗輸入 $ JLinkRTTClient

--

--