LoginSignup
9
4

More than 3 years have passed since last update.

STM32CubeIDEでTOPPERS/ASPカーネルを動かす - 準備編

Last updated at Posted at 2019-08-06

ここまでの記事では、STM32L4 Discovery kit IoT node(型番はB-L475E-IOT01A)にFreeRTOSを載せて遊んでおりました。

FreeRTOSというやつ、導入までが非常に簡単(この記事参照)でよろしいのですが、今回は、、、
別のRTOSを動かしてみたく、以下にチャレンジします!

  • TOPPERS/ASPカーネルを搭載する
  • デバッグ時に困るので、STM32CubeIDEでのビルド・デバッグを可能とする

本記事は準備編として前半部、すなわち
「ASPカーネルがコマンドラインビルドでき、焼けて、まともに動く」
ところまでを紹介します。

本編

1. 準備

1-1. 環境

  • Ubuntu 16.04 LTS

    ツールが必要な場合、apt install等での追加インストールをお願いします。
    過去の記事も参考になるかと。。。

    GCC ARM Toolchainのバージョンは以下です。

user@user-VirtualBox:~$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

1-2. ASPカーネルの準備

1-2-1. ダウンロード

以下の3つをダウンロードします。

TOPPERS/ASPカーネル ターゲット非依存部パッケージ
https://www.toppers.jp/download.cgi/asp-1.9.3.tar.gz

ARM Cortex-M4アーキテクチャ・GCC依存部パッケージ
https://www.toppers.jp/download.cgi/asp_arch_arm_m4_gcc-1.9.5.tar.gz

TOPPERS新世代カーネル用コンフィギュレータ
https://www.toppers.jp/download.cgi/cfg-linux-static-1_9_6.gz
(ビルドが超絶面倒くさいので、あえてビルド済みバイナリを使います)

これらを、同じディレクトリに配置しておきましょう。

user@user-VirtualBox:~/toppers$ ls
asp-1.9.3.tar.gz  asp_arch_arm_m4_gcc-1.9.5.tar.gz  cfg-linux-static-1_9_6.gz

1-2-2. 展開

以下コマンドで展開します。
cfgバイナリをasp/cfg/cfg/cfgとしておくのがポイントです。

user@user-VirtualBox:~/toppers$ tar zxf asp-1.9.3.tar.gz
user@user-VirtualBox:~/toppers$ tar zxf asp_arch_arm_m4_gcc-1.9.5.tar.gz
user@user-VirtualBox:~/toppers$ gzip -cd cfg-linux-static-1_9_6.gz > cfg
user@user-VirtualBox:~/toppers$ chmod 755 cfg
user@user-VirtualBox:~/toppers$ mkdir -p asp/cfg/cfg
user@user-VirtualBox:~/toppers$ mv cfg asp/cfg/cfg
user@user-VirtualBox:~/toppers$ ls
asp  asp-1.9.3.tar.gz  asp_arch_arm_m4_gcc-1.9.5.tar.gz  cfg-linux-static-1_9_6.gz

1-2-3. 文字コード・改行コード変更

文字コード・改行コードをそれぞれUTF-8/LFとしておきます。

方法は何でもよいと思いますが、私は以下の自作ツールを使いました。
https://github.com/imagou/QiitaSource/blob/master/tools/conv_char_code.sh

2. ビルド~書き込みまで

2-1. configure

ビルド用ディレクトリを作成し、configureを実行します。

ここではターゲットは「stm32l476discovery_gcc」としています。
また「-dROM」オプションは、ROM用ビルドという意味です。

user@user-VirtualBox:~/toppers$ mkdir -p asp/OBJ
user@user-VirtualBox:~/toppers$ cd asp/OBJ/
user@user-VirtualBox:~/toppers/asp/OBJ$ ../configure --help
configure: -T option is mandatory
Installed targets are:
        dve68k_gcc
        stm32e407_gcc
        stm32f401nucleo_gcc
        stm32f429board_gcc
        stm32f446nucleo144_gcc
        stm32f446nucleo64_gcc
        stm32f4discovery_gcc
        stm32l476discovery_gcc
        stm32l476nucleo64_gcc
        stm32l4r5nucleo144_gcc
user@user-VirtualBox:~/toppers/asp/OBJ$ ../configure -T stm32l476discovery_gcc -dROM
configure: Generating Makefile from ../sample/Makefile.
configure: Generating sample1.c from ../sample/sample1.c.
configure: Generating sample1.h from ../sample/sample1.h.
configure: Generating sample1.cfg from ../sample/sample1.cfg.
user@user-VirtualBox:~/toppers/asp/OBJ$ ls
Makefile  sample1.c  sample1.cfg  sample1.h

2-2. いったんmake

ひとまず、makeが通ることを確認します。

user@user-VirtualBox:~/toppers/asp/OBJ$ make depend
(略)
user@user-VirtualBox:~/toppers/asp/OBJ$ make
(略)

2-3. STM32L475向けに実装変更

この段階でのASPカーネルは、STM32L476 Discovery Kitがターゲットなので、STM32L475向けに改修してやります。

2-3-1. ログ出力ポートの書き換え

以下「Makefile.target」のシリアルポートIDを「2」に書き換えてください。

(以下フォルダに移動し)
user@user-VirtualBox:~/toppers/asp/target/stm32l476discovery_gcc$ grep SIO_PORTID Makefile.target
COPTS := $(COPTS) -DSIO_PORTID=1

USART1を使うので、一見「1」のままでよさそうですが、意図的に内部で逆転しているようです。
(STM32L476ではUSART2を使用するため「1」となっています、多少わかりにくいですね)

2-3-2. コンソール入力ポートの書き換え

以下「sample1.h」のタスクポートIDを「2」に書き換えてください。

(以下フォルダに移動し)
user@user-VirtualBox:~/toppers/asp/OBJ$ grep -e "define\sTASK_PORTID" sample1.h
#define TASK_PORTID             1                       /* 文字入力するシリアルポートID */

変更の理屈は前述の通り。

2-4. 再度make

(OBJフォルダに移動し)
user@user-VirtualBox:~/toppers/asp/OBJ$ make clean
(略)
user@user-VirtualBox:~/toppers/asp/OBJ$ make
(略)

2-5. ボードへの書き込み

2-5-1. バイナリ作成

「asp」バイナリはELF形式のファイルです。こいつからbinを作成します。

user@user-VirtualBox:~/toppers/asp/OBJ$ arm-none-eabi-objcopy -O binary asp asp.bin

2-5-2. 書き込み

以下コマンドを投入。

user@user-VirtualBox:~/toppers/asp/OBJ$ st-flash write asp.bin 0x08000000
(略)

3. 動作確認

以下を確認してください。

  • シリアルポートに起動時のログ、タスクの動作ログが出力されていること
  • 「Q」入力(大文字。また改行は不要)で終了すること

私はgtkermを用いました。

SnapCrab_Ubuntu (TOPPERS環境構築中) [実行中] - Oracle VM VirtualBox_2019-8-6_13-38-16_No-00.png

おわりに

ポート番号の修正のみで、実にあっさりと移植できました。
(実際には、調査諸々にて、結構な時間を掛けていますが・・・)

次回投稿は後半部、IDEでのビルド・デバッグを紹介します!
投稿しました。

STM32CubeIDEでTOPPERS/ASPカーネルを動かす - 本編 - Qiita
https://qiita.com/imagou/items/1a09d9afecc3f62e22d1

参考

(特になし)

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4