エスリル NISSE ファームウェア改造ガイド (1)

エスリル ニューキーボード − NISSE の Fn キーの位置が使いにくい。設定では Fn キーの位置は変更できないので、ファームウェアを自分用に改造する。開発環境は Windows 7 (64 bit)。

1. 開発環境のセットアップ

Microchip 社の MPLAB X IDE と MPLAB XC8 Compiler を使う。あと Microchip Libraries for Applications も必要。

罠注意!

インストール作業はディスプレイのスケーリングを 100% にして行うこと! 高解像度ディスプレイ利用者は特に注意。

これを忘れるとインストーラが固まる。うちの環境でディスプレイスケーリングの問題が起きたのは XC8 Compiler だけだったが、この会社のインストーラは信用できないので、最初から最後までディスプレイスケーリング 100% の環境でインストールした方がよさそう。

MPLAB X IDE
  1. https://www.microchip.com/pagehandler/en-us/family/mplabx/ の Downloads タブから MPLAB® X IDE v3.20 をダウンロード。
  2. MPLABX-v3.20-windows-installer.exe を実行。
  3. C:\Program Files (x86)\Microchip\MPLABX\v3.20\ にインストール。
MPLAB XC8 Compiler
  1. https://www.microchip.com/pagehandler/en-us/devtools/mplabxc/ の Downloads Archive タブから MPLAB XC8 Compiler v1.34 をダウンロード。
    • 執筆時点では最新版 v1.35 が最新版だが、v1.35 を使うと問題がある(後述)。今のところ v1.34 を使っておいた方が無難。
  2. xc8-v1.34-full-install-windows-installer.exe を実行。
  3. インストール先は C:\Program Files (x86)\Microchip\xc8\v1.34 で OK。
  4. Compiler Settings で Update MPLAB IDE to use the XC8 compiler for all existing C18 (mcc18) projects と Use XC8 for the C18 Linker, Librarian and Assembler にチェック。
    • Compiler Settings 画面で文字がちらついてたらアウト! ディスプレイのスケーリングを 100% にすること。このまま進めると次の Installing 画面でインストーラが固まる。
  5. PRO ライセンスは不要。Next をクリック。
Microchip Libraries for Applications
  1. http://www.microchip.com/pagehandler/en-us/devtools/mla/ の Current MLA タブから Microchip Libraries for Applications をダウンロード。
  2. mla_v2015_08_10_windows_installer.exe を実行。
  3. インストール先は C:\Program Files (x86)\Microchip\mla\v2015_08_10 で OK。
設定確認
  1. MPLAB X IDE を起動。
  2. Tools - Options - Embedded - Build Tools に XC8 が登録されてることを確認。
XC8 Compiler v1.35 を使う場合

XC8 v1.35 から Peripheral Libraries (plib) が同梱されなくなった*1ので、これを別途インストールする必要がある。

  1. https://www.microchip.com/pagehandler/en-us/devtools/mplabxc/ の Downloads タブの下の方から PIC18F Legacy Peripheral Libraries v1.0 をダウンロード。
  2. peripheral-libraries-for-pic18-v2.00rc3-windows-installer.exe を実行。
  3. インストール先を C:\Program Files (x86)\Microchip\xc8\v1.35 に修正してインストール。

2. ソースコードの取得とコンパイル

ファームウェアソースコードhttps://github.com/esrille/new-keyboard にある。

  1. GitHub にログインしてソースコードを Fork する。GitHub のアカウントを作りたくない人は Zip でダウンロードしてもいいけど。
  2. MPLAB X IDE を起動。
  3. File - Open Project で、ダウンロードしたソースツリーの firmware\third_party\mla_v2013_12_20\apps\usb\device\hid_keyboard\firmware\MPLAB.X を開く。
  4. 通常型とポインティングデバイス内蔵型は、同じプロジェクトだが異なるコンフィグレーションになっている。コンフィグレーションの切り替えはツールバーのドロップダウンリストで行う。ビルドはコンフィグレーション別に行う必要がある。
  5. Projects ツリーの USB Device - HID - Keyboard を右クリック → Build でビルドする。
  6. BUILD SUCCESSFUL (total time: 43s) とか表示されたら成功。ソースツリーの次の場所にファームウェアの .hex ファイルが生成されている。
    • 通常型は firmware\third_party\mla_v2013_12_20\apps\usb\device\hid_keyboard\firmware\MPLAB.X\dist\Esrille_New_Keyboard\production\MPLAB.X.production.hex
    • ポインティングデバイス内蔵型は firmware\third_party\mla_v2013_12_20\apps\usb\device\hid_keyboard\firmware\MPLAB.X\dist\Esrille_New_Keyboard_with_Mouse\production\MPLAB.X.production.hex
XC8 Compiler v1.35 を使った場合
  • ビルド時に ../src/system_config/esrille_new_keyboard/system.c:57: error: (141) can't open include file "plib/usart.h": No such file or directory というエラーが出て失敗したら、Legacy Peripheral Libraries をインストールし忘れている。C:\Program Files (x86)\Microchip\xc8\v1.34\include\plib フォルダの中に .h ファイルが存在することを確認。あと一応、File - Project Properties の XC8 linker の Link in Peripheral Library にチェックが入っていることも確認。
  • なんか Warning が出てるのが気になる。特に後者は気になる。
../../../../../../../../src/KeyboardUS.c:115: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardUS.c:130: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardJP.c:397: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardJP.c:401: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardJP.c:405: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardJP.c:420: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardJP.c:434: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardJP.c:448: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/Mouse.c:85: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/Mouse.c:103: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:181: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:184: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:187: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:190: warning: (1404) unsupported: The Read_b_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:207: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:221: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:235: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
../../../../../../../../src/KeyboardCommon.c:249: warning: (1404) unsupported: The Busy_eep routine is no longer supported. Please use the MPLAB X MCC.
Warning: firmware/third_party/mla_v2013_12_20/apps/usb/device/hid_keyboard/firmware/MPLAB.X/dist/Esrille_New_Keyboard_with_Mouse/debug/MPLAB.X.debug.elf contains code that is located at addresses that do not exist on the PIC18F4550.
Code incompletely loaded.
  • .hex ファイルの中身も v1.34 でビルドしたものとは異なる。NISSE キーボードにロードしてみたら、とりあえず動いているようだけど…?

3. ファームウェアの書き込み

https://www.esrille.com/keyboard/ja-jp/support.html の一番下に書いてあるとおり。

  1. NISSE キーボードの USB ケーブルを抜き、Esc キーを押しながらケーブルを挿し直す。赤ランプが点滅する。
    • USB ハブを介するとダメみたい。PC 本体の USB ポートに直結すること。
  2. C:\Program Files (x86)\Microchip\mla\v2015_08_10\apps\usb\device\bootloaders\utilities\bin\win\HIDBootloader.exe を実行。
    • Device not detected. Verify device is attached and in firmware update mode. と表示されたらダメ。NISSE キーボードを接続し直す。
  3. File - Import Firmware Image で、さっきビルドしたファームウェアの .hex ファイルを開く。
  4. Program - Erase/Program/Verify Device でファームウェアを NISSE キーボードに書き込む。
  5. Program - Reset Device で NISSE キーボードをリセットする。


これでようやくスタートラインに立った。次回からいよいよソースコードをいじるよ。