Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support for esp32c3 supermini board #4212

Open
vaaski opened this issue Mar 28, 2024 · 3 comments
Open

feature: add support for esp32c3 supermini board #4212

vaaski opened this issue Mar 28, 2024 · 3 comments
Labels
enhancement New feature or request esp32

Comments

@vaaski
Copy link

vaaski commented Mar 28, 2024

Hey, I recently got into Go and loved the idea of using it for microcontrollers in a new project.
I have a bunch of ESP32-C3 superminis but I can't get tinygo to build for them.
I'm on a MacBook Pro M3 Pro on Sonoma with Tinygo and Esptool installed via Homebrew.
I've tried following the blinking LED example adjusted to work with the esp32c3

main.go
package main

import (
	"machine"
	"time"
)

func main() {
	led := machine.GPIO8
	led.Configure(machine.PinConfig{Mode: machine.PinOutput})
	for {
		led.Low()
		time.Sleep(time.Millisecond * 500)

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

But building fails with the following output:

❯ tinygo build -target=esp32c3
# machine
/opt/homebrew/Cellar/tinygo/0.31.2/src/machine/machine_esp32c3_i2c.go:38:16: undefined: SCL_PIN
/opt/homebrew/Cellar/tinygo/0.31.2/src/machine/machine_esp32c3_i2c.go:41:16: undefined: SDA_PIN

I guess it's something with the i2c implementation, but I'm not familiar enough with Go or this project to pinpoint the exact issue yet.
Since building with -target=esp32 works fine, I've tried flashing with that but it won't work either.

❯ tinygo flash -target=esp32  
esptool.py v4.7.0
Serial port /dev/cu.usbmodem1101
Connecting...

A fatal error occurred: This chip is ESP32-C3 not ESP32. Wrong --chip argument?
error: failed to flash /var/folders/93/m682qq_n5klc2btq3q_cb_0c0000gq/T/tinygo1642084370/main.bin: exit status 2

Thanks a lot for making all this in the first place, I can't wait to use Go for microcontrollers!

@vaaski
Copy link
Author

vaaski commented Apr 2, 2024

As a workaround, commenting out these lines makes it work as expected. My LED is blinking.

if config.SCL == 0 {
config.SCL = SCL_PIN
}
if config.SDA == 0 {
config.SDA = SDA_PIN
}

@deadprogram
Copy link
Member

@vaaski the issue here is that you need to use a target with an actual board file in order to have the correct mapping. An example is the Seeed XIAO ESP32C3 board.

For example, see target https://github.com/tinygo-org/tinygo/blob/release/targets/xiao-esp32c3.json with board file https://github.com/tinygo-org/tinygo/blob/release/src/machine/board_xiao-esp32c3.go

Note that the target "inherits" from the target esp32c3. That target is really meant to be used in this way, not as a target of its own.

Hope that helps!

@deadprogram deadprogram added the docs Documentation needed label Apr 22, 2024
@deadprogram
Copy link
Member

@vaaski if you wanted to create a PR that added the board definitions for the esp32c3 supermini we'd be happy to accept it. 😄

See https://forum.arduino.cc/t/esp32-c3-supermini-pinout/1189850/6 for the pin definitions.

See https://github.com/tinygo-org/tinygo/wiki/Adding-a-new-board#adding-a-new-board for instructions on how to go about doing this.

@deadprogram deadprogram changed the title Can't build for esp32c3, SCL_PIN & SDA_PIN are undefined feature: add support for esp32c3 supermini board May 1, 2024
@deadprogram deadprogram added enhancement New feature or request esp32 and removed docs Documentation needed labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request esp32
Projects
None yet
Development

No branches or pull requests

2 participants