-
Notifications
You must be signed in to change notification settings - Fork 972
Description
Hello!
I'm trying to make a simple 4 switch keypad with a Seeed Studio XIAO RP2040. I can successfully compile with no errors or warnings, and then also (seemingly) successfully flash the device with the resulting uf2. The issue is, more often than not, the device after flashing fails to enumerate in Windows 10. I get the most success when I start with the device unplugged, boot, and then flash. It tends to work under those circumstances. If I reset the device using the reset button, it tends to fail. I can reproduce this with both v0.29 and v0.30, I haven't tried other versions of tinygo.
I've also tried adding println statements to debug over serial. When the device is in the failure state, the tinygo monitor is unable to locate the COM port. I'm happy to try other troubleshooting or debug steps, but I'm not versed enough with tinygo to know what would be useful here. In my perusing of the issues list, it seems like this could be related to this: #3012
Here's what device manager looks like when the device is in the failure state:
Here's the code being compiled:
package main
import (
"machine"
"machine/usb"
"machine/usb/hid/keyboard"
"time"
)
func main() {
button1 := machine.D0
button1.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
button2 := machine.D1
button2.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
button3 := machine.D2
button3.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
button4 := machine.D3
button4.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
kb := keyboard.Port()
for {
if !button1.Get() {
kb.Down(keyboard.KeyW)
} else {
kb.Up(keyboard.KeyW)
}
if !button2.Get() {
kb.Down(keyboard.KeyD)
} else {
kb.Up(keyboard.KeyD)
}
if !button3.Get() {
kb.Down(keyboard.KeyS)
} else {
kb.Up(keyboard.KeyS)
}
if !button4.Get() {
kb.Down(keyboard.KeyA)
} else {
kb.Up(keyboard.KeyA)
}
time.Sleep(25 * time.Millisecond)
}
}
Here's the command I'm using to compile:
tinygo build -target=xiao-rp2040 -o firmware.uf2 main.go