在 Windows 环境下使用 VSCode 和 TinyGo 开发 ESP8266(NodeMcu) or STM32

支持的型号

https://tinygo.org/docs/reference/microcontrollers/

 

1. 安装Go

2. 安装TinyGo,并添加环境变量

https://github.com/tinygo-org/tinygo/releases

 3. VSCode配置,安装插件,选择设备

 

package main

import (
    "machine"
    "time"
)

func main() {
    led := machine.LED
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})

    for {
        println("Hello, World")

        led.Low()
        time.Sleep(time.Millisecond * 500)

        led.High()
        time.Sleep(time.Millisecond * 500)
    }
}

烧入代码

tinygo flash -target=nodemcu -port=COM8

 效果:ESP8266LED闪烁,串口信息输出

编译bin

tinygo build -o firmware.bin -target=bluepill

 

STM32烧入

1. 安装STLink V2

2. 安装openocd

tinygo flash -target=stm32f4disco

 

已验证(用tinygo编译,stlinkv2烧入)

tinygo build -o test.hex -target=stm32f4disco

 

posted @ 2025-03-27 10:06  CHHC  阅读(89)  评论(0)    收藏  举报