根据这个大佬的视频
https://www.bilibili.com/video/BV1hi4y1m7g5?spm_id_from=333.788.top_right_bar_window_history.content.click
我尝试了很久,遇到了很多GO的坑(毕竟是go小白,很多东西都没搞懂)
最终终于烧录成功了
参考文档:
https://discretetom.github.io/posts/windows-vscode-tinygo-arduino/
https://github.com/tinygo-org/tinygo
烧录命令:
tinygo flash -target arduino
或
tinygo flash -target arduino <目标地址>
如:tinygo flash -target arduino examples/blinky1
TinyGo是一个Go编译器,用于微控制器、WebAssembly (Wasm)和命令行工具等小地方。
它重用Go语言工具在旁边LLVM提供另一种方法来编译用Go编程语言编写的程序。
下面是一个示例程序,当直接在任何带有板载LED的受支持主板上运行时,该程序会闪烁内置LED:
package main
import (
"machine"
"time"
)
func main() {
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
for {
led.Low()
time.Sleep(time.Millisecond * 1000)
led.High()
time.Sleep(time.Millisecond * 1000)
}
}
只要设置正确的TinyGo编译器目标,上述程序无需修改即可在Arduino Uno、Adafruit ItsyBitsy M0或任何具有内置led的受支持电路板上编译和运行。例如,这将编译并刷新一个Arduino Uno:
tinygo flash -target arduino examples/blinky1
go.mod:
module demo
go 1.18
settings.json配置
{
"go.toolsEnvVars": {
"GOROOT": "C:\\Users\\73968\\AppData\\Local\\tinygo\\goroot-7b4c5b78c095ffb5578c8619666712b02015dbd3e648685cfb1c35f1effd4fda",
"GOFLAGS": "-tags=avr,baremetal,linux,arm,atmega328p,atmega,avr5,arduino,tinygo,math_big_pure_go,gc.conservative,scheduler.none,serial.uart"
}
}