nanoFrameworkのファームウェアビルド

.NET Micro Framework後継の一つ、nanoFramework。

https://www.slideshare.net/TakashiMatsuoka2/tinyclr-os-on-wio-lte/9

何気なくドキュメントを見たら、ファームウェアのビルド手順が書かれていて、わたしでも出来るかも?と思い、やってみました。

参考にするドキュメントはこちら。

How to Build, Flash and Debug the STM32 nanoBooter and nanoCLR on Windows using Visual Studio Code | nanoFramework Documentation

ターゲットボードは、手元に有るSTM32F4DISCOVERYとします。

ビルド環境のセットアップ

Setting up the build environment for STM32

ディレクトリを作成

C:\>mkdir C:\nanoFramework
C:\>mkdir C:\nanoFramework_Tools

Visual Studio Codeをインストール

既にインストールされていました。

CMakeをコピー

CMakeサイトからcmake-3.13.1-win64-x64.zipをダウンロードして、C:\nanoFramework_Tools\CMakeに解凍します。

f:id:matsujirushix:20181208194914p:plain

Ninjaをコピー

ninjaのReleaseからv1.8.2のninja-win.zipをダウンロードして、C:\nanoFramework_Tools\Ninjaに解凍します。

f:id:matsujirushix:20181208195150p:plain

GNU ARM Embedded Toolchainをコピー

GNU-RM Downloadsからgcc-arm-none-eabi-7-2018-q2-update-win32.zipをダウンロードして、C:\nanoFramework_Tools\GNU_ARM_Toolchainに解凍します。

f:id:matsujirushix:20181208195939p:plain

ChibiOSをコピー

ChibiOSのSourceForgeからChibiOS_18.2.1.zipだと、nf-interpreterが想定しているものより古いバージョンのためコンパイルエラーになりました。(-.-) githubから取りましょう。

ChibiOSのstable_18.2.xブランチをzipダウンロードして、

f:id:matsujirushix:20181208200453p:plain

C:\nanoFramework_Tools\ChibiOS-stable_18.2.xに解凍します。

f:id:matsujirushix:20181208201046p:plain

nf-interpreterをクローン

デフォルトのdevelopブランチだと、UART周辺でコンパイルエラーになりました。(-.-) masterブランチを明示的に指定しましょう。

githubのnanoframework/nf-interpreterをクローンします。

C:\>cd C:\nanoFramework
C:\nanoFramework>git clone -b master https://github.com/nanoframework/nf-interpreter.git

Visual Studio Codeのセットアップ

Visual Studio Code拡張をインストール

下記URL先のInstallをクリックして、Visual Studio Code拡張をインストールします。

CMake-variants.jsonを設定

C:\nanoFramework\nf-interpreter\cmake-variants.jsonを作成します。

{
  "buildType": {
    "default": "MinSizeRel",
      "choices": { 
        "debug": {
          "short": "Debug",
          "long": "Emit debug information without performing optimizations",
          "buildType": "Debug"
        },
        "release": {
          "short": "Release",
          "long": "Enable optimizations, omit debug info",
          "buildType": "Release"
        },
        "minsize": {
          "short": "MinSizeRel",
          "long": "Optimize for smallest binary size",
          "buildType": "MinSizeRel"
        },
        "reldeb": {
          "short": "RelWithDebInfo",
          "long": "Perform optimizations AND include debugging information",
          "buildType": "RelWithDebInfo"
        }    
      }
  },

  "linkage": {
    "default": "",
    "choices": {
      "ST_STM32F4_DISCOVERY": {
        "short": "ST_STM32F4_DISCOVERY",
        "settings": {
          "BUILD_VERSION" : "0.9.99.999",
          "TOOLCHAIN_PREFIX" : "C:/nanoFramework_Tools/GNU_ARM_Toolchain",
          "TARGET_SERIES" : "STM32F4xx",
          "CHIBIOS_SOURCE" : "C:/nanoFramework_Tools/ChibiOS-stable_18.2.x",
          "CHIBIOS_BOARD" : "ST_STM32F4_DISCOVERY",
          "SWO_OUTPUT" : "ON",
          "USE_RNG" : "ON",
          "NF_FEATURE_DEBUGGER" : "ON",
          "NF_FEATURE_RTC" : "ON",
          "API_Windows.Devices.Adc" : "ON",
          "API_Windows.Devices.Gpio" : "ON",
          "API_Windows.Devices.Spi" : "ON",
          "API_Windows.Devices.I2c" : "ON",
          "API_Windows.Devices.Pwm" : "ON",
          "API_Windows.Devices.SerialCommunication" : "ON"
        }
      }
    }
  }
}

settings.jsonを設定

C:\nanoFramework\nf-interpreter\.vscode\settings.jsonを作成します。

{
    "cmake.generator": "Ninja",
    "cmake.configureSettings": {
        "CMAKE_MAKE_PROGRAM":"C:/nanoFramework_Tools/ninja/ninja.exe"
    },
    "cmake.cmakePath": "C:/nanoFramework_Tools/CMake/bin/cmake.exe"
}

nanoBooterとnanoCLRをビルド

Visual Studio Codeを起動して、ファイル -> フォルダを開く、でC:\nanoFramework\nf-interpreterを開きます。

Would you like to configure this project?というメッセージウィンドウが表示されたら、Not nowをクリックします。

Never configure projects on opening?というメッセージウィンドウが表示されたら、For this Workspaceをクリックします。

メッセージが何も表示されなくなったら、ステータスバーのNo Kit Selectedをクリックして、

f:id:matsujirushix:20181208203150p:plain

[Unspecified]を選択します。

f:id:matsujirushix:20181208203312p:plain

ステータスバーのBuildをクリックします。

f:id:matsujirushix:20181208211555p:plain

2分ちょっとでビルド完了。

f:id:matsujirushix:20181208211937p:plain

nanoBooter.hexnanoCLR.hexが出来上がりました。

f:id:matsujirushix:20181208212108p:plain