はじめに
tinygoを作ったので、BluePillで動かしてみる。
ここの手順を参考にする。
テストを実行
このコマンドはどこのディレクトリでも実行可能。
$ tinygo run examples/test
デバイスターゲットの生成
これは最初にやっておく必要があるらしい。
$ cd $GOPATH/src/github.com/tinygo-org/tinygo $ make gen-device
BluePillとST-Link V2の接続
次のように接続する。
ST-Link V2 | Pin | ターゲット |
---|---|---|
GND | 20 | GND |
TCK | 9 | CLK |
TMS | 7 | IO |
TVCC | 1 | 3.3V |
ST-Link V2とPCをUSBケーブルで接続する。
次にBluePillのマイクロUSBのポートとPCをUSBで接続し、ボードに電源を供給する。
サンプルプログラムを書き込む
次のコマンドでBluePillにLチカプログラムを書き込む。
$ tinygo flash -target=bluepill examples/blinky1 Open On-Chip Debugger 0.10.0+dev-00664-g8417a569 (2019-01-27-16:38) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 1000 kHz adapter_nsrst_delay: 100 none separate Info : clock speed 1000 kHz Info : STLINK V2J14S3 (API v2) VID:PID 0483:3748 Info : Target voltage: 3.217323 Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints Info : Listening on port 3333 for gdb connections target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08000130 msp: 0x20000d50 ** Programming Started ** auto erase enabled Info : device id = 0x20036410 Info : flash size = 64kbytes target halted due to breakpoint, current mode: Thread xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000d50 wrote 3072 bytes from file /tmp/tinygo866341559/main.hex in 0.231905s (12.936 KiB/s) ** Programming Finished ** ** Resetting Target ** shutdown command invoked
LEDがチカチカしたら成功。
Blinky1のソース
ちなみに、書き込んだBlinky1のソースは$GOPATH/src/github.com/tinygo-org/tinygo/src/examples/blinky1
にある。
package main // This is the most minimal blinky example and should run almost everywhere. import ( "machine" "time" ) func main() { led := machine.GPIO{machine.LED} led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) for { led.Low() time.Sleep(time.Millisecond * 500) led.High() time.Sleep(time.Millisecond * 500) } }
まとめ
tinygoが正しく作られてさえいれば難しいところはない。