Adafruit nrf52 Bootloader の機器向けに Segger Embedded Studio で開発して書き込む

機器

www.switch-science.com

ソフトウェア

  • Segger Embedded Studio
  • uf2conv.py
  • nRF SDK

やったこと

設定画面

Segger Embedded Studioで Project>Options を開く。多くの項目がCommonで設定されている。

ボード定義

nRF52840ボードがP0_13にLEDを搭載していることが多い中, MDBT50Q開発用USBドングルはP1_13のみにLEDを搭載しているため, ボード定義を作成する。

ボード定義の作成

(SDK_TOP)/components/boards/mdbt50q_dongle.h

#ifndef MDBT50Q_DONGLE_H
#define MDBT50Q_DONGLE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "nrf_gpio.h"

// LEDs definitions for DONGLE
#define LEDS_NUMBER    1

#define LED_1          NRF_GPIO_PIN_MAP(1,13)
#define LED_START      LED_1
#define LED_STOP       LED_1

#define LEDS_ACTIVE_STATE 0

#define LEDS_LIST { LED_1 }

#define LEDS_INV_MASK  LEDS_MASK

#define BSP_LED_0      NRF_GPIO_PIN_MAP(1,13)

#define BUTTONS_NUMBER 1

#define BUTTON_1      NRF_GPIO_PIN_MAP(0,15)
#define BUTTON_PULL    NRF_GPIO_PIN_PULLUP

#define BUTTONS_ACTIVE_STATE 0

#define BUTTONS_LIST { BUTTON_1 }

#define BSP_BUTTON_0   BUTTON_1

#ifdef __cplusplus
}
#endif
#endif // MDBT50Q_DONGLE_H
マクロの変更

(SDK_TOP)/components/boards/boards.h

ボード指定マクロによる分岐が書き連ねられているところの#elseの前に書き加える。

#elif defined(BOARD_MDBT50Q_DONGLE)
  #include "mdbt50q_dongle.h"

作成後, 設定画面の Preprocessor>Preprocessor Definitionsで BOARD_ から始まるボード指定マクロを変更する。

メモリマップ定義

Linker>Memory Segmentsを編集する。

FLASH_STARTを0x26000にすると動いた。0x27000では動かなかった。

uf2conv

Linker>Additional Output Format で bin を指定する。

uf2/uf2conv.py at master · microsoft/uf2 · GitHub の1ファイルのみをダウンロードしたら動いた。

chmod +x uf2conv.py
uf2conv.py blinky.bin -c -b 0x26000 -f 0xADA52840

自動変換設定

User Build Step>Post-Build Command に uf2conv.py $(SolutionDir)/$(OutDir)/$(ProjectName).bin -c -b 0x26000 -f 0xADA52840 -o $(OutDir)/$(ProjectName).uf2 を指定すると, ビルド時に自動でuf2ファイルが生成されるようになる。