AE-TYBLE16でnRF5 SDKのサンプルを動かす

バイナリを生成する

12.3.0nRF5 SDKをダウンロードした。

pca10028/s130/config/sdk_config.hで CLOCK_CONFIG_XTAL_FREQ 255->0, CLOCK_CONFIG_LF_SRC 1 -> 0と書き換える(変えなくても動いていたが念のため)

各サンプルのmain.cのble_stack_init( )の冒頭にあるclock_lf_cfgを次のように書き換える。(これは書き換えないと全く動かなかった。)

nrf_clock_lf_cfg_t clock_lf_cfg; clock_lf_cfg.rc_ctiv = 16; clock_lf_cfg.rc_temp_ctiv = 2; clock_lf_cfg.source = NRF_CLOCK_LF_SRC_RC; clock_lf_cfg.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_250_PPM;

$(SDKROOT)/components/toolchain/{system_nrf51.c,system_nrf51422.c}の2つのファイルの冒頭 __SYSTEM_CLOCK (16000000UL) を (32000000UL) に書き換える。

これでコンパイルしてできたバイナリがAE-TYBLE16でで動くはず。

書き込む

書き込みはRaspberry Pi Zero W上で走らせたopenocdで行った。openocd.cfgは下記の通りだった。set WORKAREASIZE 0がないとエラーが出て書き込めなかった。swclk = 25, swdio = 24になるので適当に接続する。

source [find interface/raspberrypi-native.cfg] transport select swd bcm2835gpio_swd_nums 25 24 bcm2835gpio_trst_num 7 bcm2835gpio_srst_num 18 set WORKAREASIZE 0 source [find target/nrf51.cfg]

s130-201.hexは$(SDKROOT)\components\softdevice\s130\hex\s130_nrf51_2.0.1_softdevice.hexで、blinky.hexが先ほどコンパイルして生成されたhexになる。適当な方法でRasPiに転送する。今回はpscpを使った。

ケーブルが接続されていることを確認して、RasPiのlocalhost:4444に telnetで 接続した。下記のコマンドを入力する。

reset halt halt; nrf51 mass_erase; flash write_image s130-201.hex 0; flash write_image blinky.hex mww 0x4001e504 1 ; mww 0x10001000 0x0001C000; mww 0x10001008 0xffffff00; mww 0x4001e504 0; reset run

ちなみに、openocdを実行するとシェルにはこんな出力が出る。

pi@raspberrypizero:~ $ sudo openocd Open On-Chip Debugger 0.10.0+dev-00232-g6f5e9941 (2018-01-10-08:50) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html BCM2835 GPIO config: tck = 11, tms = 25, tdi = 10, tdo = 9 BCM2835 GPIO nums: swclk = 25, swdio = 24 BCM2835 GPIO config: trst = 7 BCM2835 GPIO config: srst = 18 cortex_m reset_config sysresetreq adapter speed: 1000 kHz Info : BCM2835 GPIO JTAG/SWD bitbang driver Info : JTAG and SWD modes enabled Info : clock speed 1006 kHz Info : SWD DPIDR 0x0bb11477 Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints Info : accepting 'telnet' connection on tcp/4444

port 4444にtelnetした方は次のような感じになる

Open On-Chip Debugger > reset halt target halted due to debug-request, current mode: Thread xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0 > halt; nrf51 mass_erase; flash write_image s130-201.hex 0; flash write_image blinky.hex nRF51822-CFAC(build code: A0) 256kB Flash Padding image section 0 with 2112 bytes not enough working area available(requested 32) no working area available, falling back to slow memory writes wrote 110560 bytes from file s130-201.hex in 7.748491s (13.934 KiB/s) not enough working area available(requested 32) no working area available, falling back to slow memory writes wrote 48232 bytes from file blinky.hex in 3.481749s (13.528 KiB/s) > mww 0x4001e504 1 ; mww 0x10001000 0x0001C000; mww 0x10001008 0xffffff00; mww 0x4001e504 0; > reset run

1/7追記:

mww 0x10001000 0x0001C000;は間違っていた。mww 0x10001000 0x0001b000;だった( pca10028/s130/ble_app_template_gcc_nrf51.ld )とかを見るとFLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000とか書いてあるので、ORIGINを参考にして設定する。適切に設定すれば2回目以降はmass_eraseが不要になる。そうするとsoftdeviceを書き込みしなおさなくて済むので時間が節約できる。sudo openocd -f openocd.cfg -c 'init; reset halt; flash write_image erase blinky.hex; reset run; exit' でやっている。さらに言えば、openocd.cfgの一番最後にadapter_khz 4000を付けると速くなった。

No comments yet