プログラミング言語RustをNucleo-F103RBボードで動かす(STM32F1xx)
2020/5/11
Rust STM32F1xx
Rust STM32F1xx
概要
プログラミング言語Rustを以下のNucleo-F103RBボードで動かす。 (ホストPCとしてはubuntuを想定している)
STM32 Nucleo Board STM32F103RB
関連ツールのインストール
以下で必要なツールをインスールする:
(0)rustツールのインストール
curl https://sh.rustup.rs -sSf | sh
(1)書き込みツール(st-flash)のインストール
sudo apt install cmake
sudo apt install libusb-1.0
git clone https://github.com/texane/stlink.git
cd stlink
make
cd build/Release
sudo make install
sudo ldconfig
(2)Cコンパイラのバージョンアップ
binを作成するのに、これに含まれるツールを使用するのでインストールする
以下でインストールしたコンパイラが古くてビルドエラーが出たのでバージョンアップする。
sudo apt-get install gcc-arm-none-eabi
(1)以下のurlから最新版をダウンロードする:
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
解凍したものを以下のフォルダに置く:
$HOME/Downloads/gcc-arm-none-eabi-8-2019-q3-update
(2)パス設定
#古いコンパイラを削除する
sudo apt-get remove gcc-arm-none-eabi
#パスを設定する
export PATH=$PATH:$HOME/Downloads/gcc-arm-none-eabi-8-2019-q3-update/bin
exportは、.bashrcに登録する
(3)その他の必要ツールのインストール
sudo apt-get install openocd
sudo apt-get install picocom
sample#0(blinky)を実行する
最初の設定のターゲットボードがblue-pillになっているので、Nucleo-F103RBの設定に変更して動かす。
(1)rust関連の設定
git clone https://github.com/stm32-rs/stm32f1xx-hal.git
cd stm32f1xx-hal
rustup default nightly
rustup target add thumbv7m-none-eabi
(2)memory.xの変更
以下のように変更する:
(Flash容量を64Kから128Kに変更する)
cat memory.x
/* Linker script for the NUCLEO-F103RB */
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 128K
RAM : ORIGIN = 0x20000000, LENGTH = 20K
}
(3)examples/blinky.rsの変更
(オンボードのLEDのポートをpc13からpa5に変更する)
37行付近:
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
→
let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
40行付近:
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
→
let mut led = gpioa.pa5.into_push_pull_output(&mut gpioa.crl);
点滅周期を変更したい場合、以下のような変更を行なう:
42行付近:
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz());
→
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(10.hz());
(4)ビルド
cargo clean
cargo build --example blinky --release --features=stm32f103
(5)elfをbinに変換する
arm-none-eabi-objcopy -O binary target/thumbv7m-none-eabi/release/examples/blinky F103_blinky.bin
(6)書き込む
#ボートとホストPCをUSBで接続する
st-flash write F103_blinky.bin 0x8000000
ボードのグリーンLED(LD2)が点滅すれば動作としてはOKとなる。
その他のサンプル
以下に、その他のサンプルがあるのでボードに依存するポートなどを変更すれば、Nucleo-F103RBで動作すると思われる。
$ ls examples
adc-dma-circ.rs itm.rs serial-dma-peek.rs
adc-dma-rx.rs led.rs serial-dma-rx.rs
adc.rs mfrc522.rs serial-dma-tx.rs
adc_temperature.rs motor.rs.disabled serial-fmt.rs
blinky.rs mpu9250.rs.disabled serial.rs
blinky_generic.rs nojtag.rs serial_config.rs
blinky_rtc.rs panics.rs spi-dma.rs
blinky_timer_irq.rs pwm.rs timer-interrupt-rtfm.rs
delay.rs pwm_custom.rs usb_serial.rs
enc28j60-coap.rs.disabled pwm_input.rs usb_serial_interrupt.rs
enc28j60.rs.disabled qei.rs usb_serial_rtfm.rs
exti.rs rtc.rs
hello.rs serial-dma-circ.rs
ターゲット情報
Cortex-Mプロセッサとターゲットは以下の対応になっている:
thumbv6m-none-eabi - Cortex-M0 と M0+
thumbv7m-none-eabi - Cortex M3
thumbv7em-none-eabi - Cortex M4 と M7、FPU なし
thumbv7em-none-eabihf - Cortex M4 と M7、FPU あり
参照情報
STM32 Nucleo Board STM32F103RB
The Embedded Rust Book
The Embedded Rust Book - Semihosting
以上
| 固定リンク
« プログラミング言語Rustをmicro:bitボードで動かす | トップページ | 開発ツールPlatformIOでSipeed-RV(RISC-V)-Debuggerを使用する(Longan-Nano版) »
「linux」カテゴリの記事
- platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法(2021.03.10)
- micro:bit Yotta開発ツール(linux版)(2021.01.09)
- PlatformIOをRaspberryPi4で動かしてみる(実験)(2020.10.20)
- headless RaspberryPiインストール方法(v2)(2020.10.20)
- wio-terminalのファームウェア・アップデートについて(linux版)(2020.10.15)
「Nucleo」カテゴリの記事
- MicroPython/CircuitPython Performance Test(2021.02.07)
- MicroPython(F767ZI) Network Samples(2021.01.03)
- MicroPython(F767ZI)でStartwars(AsciiArt)を動かす(2020.12.29)
- NUCLEO-F767ZIにMicropythonをインストールする(v2)(2020.05.22)
- Nucleo-F303K8でADCの値をLCD(AQM0802)(i2c)に表示する(Arduino版)(2020.05.16)
「Rust」カテゴリの記事
- プログラミング言語RustをXIAOで動かす(v2)(2020.10.05)
- プログラミング言語RustをXIAOで動かす(2020.06.09)
- プログラミング言語RustをFeather-M4-Expressで動かす(2020.05.28)
- プログラミング言語RustをCircuit-Playground-Expressで動かす(2020.05.28)
- プログラミング言語RustをNucleo-F103RBボードで動かす(STM32F1xx)(2020.05.11)
コメント