1

在 Windows 环境下使用 VSCode 和 Go 语言开发 STM32

 2 years ago
source link: https://discretetom.github.io/posts/windows-vscode-tinygo-stm32/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在 Windows 环境下使用 VSCode 和 Go 语言开发 STM32

STM32和Arduino相比,要配置的东西多一些

  • 安装 Go 语言编译器、TinyGo 编译器、配置 VSCode:参考此文
  • 买一个STLink v2
    • 需要安装驱动,安装完毕后连接 STLink 和电脑,LED 应该常亮
  • 安装 MSYS2,然后安装 OpenOCD
    • 需要执行两次pacman -Syu

我的开发板是 STM32F103 ,对应 TinyGo 里面的 bluepill

根据开发板的文档,开发板上有一个 RGB LED RGB 对应的引脚分别是 PB5 PB0 PB1

package main

import (
	"machine"
	"time"
)

func main() {
	red := machine.PB5
	green := machine.PB0
	blue := machine.PB1
	red.Configure(machine.PinConfig{Mode: machine.PinOutput})
	green.Configure(machine.PinConfig{Mode: machine.PinOutput})
	blue.Configure(machine.PinConfig{Mode: machine.PinOutput})

	red.High()
	blue.High()
	green.High()
	for {
		green.High()
		red.Low()
		time.Sleep(time.Millisecond * 500)

		red.High()
		blue.Low()
		time.Sleep(time.Millisecond * 500)

		blue.High()
		green.Low()
		time.Sleep(time.Millisecond * 500)
	}
}
tinygo flash -target=bluepill

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK