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

WIP: add initial support for ESP32-S3 #3937

Open
wants to merge 2 commits into
base: release
Choose a base branch
from

Conversation

denysvitali
Copy link

These are the first steps towards fixing #3442.

At the moment, the following TinyGo program doesn't print anything to stdout, but at least it seems like the main is reached:

package main

import "machine"

func main() {
	machine.InitSerial()

	for {
		machine.Serial.Write([]byte("Hello world :)\r\n"))
	}
}

Here is the full boot log:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd0108,len:0x1710
load:0x403b6000,len:0x8c8
load:0x403ba000,len:0x2eb4
SHA-256 comparison failed:
Calculated: 94284163cda84609f6d502e80255fb42297565c0c3c1795798a0c2beda02fced
Expected: ab492d70a98095a7841c7bfbf1d6d0b6161e082227abfb2028c51ce7cbe6144a
Attempting to boot anyway...
entry 0x403b61c0
I (43) boot: ESP-IDF v4.4-dev-3540-g4e03a9c34c 2nd stage bootloader
I (43) boot: compile time 09:24:35
I (44) boot: chip revision: 0
I (47) boot.esp32s3: Boot SPI Speed : 80MHz
I (51) boot.esp32s3: SPI Mode       : DIO
I (56) boot.esp32s3: SPI Flash Size : 8MB
I (61) boot: Enabling RNG early entropy source...
W (66) bootloader_random: RNG for ESP32-S3 not currently supported
I (73) boot: Partition Table:
I (77) boot: ## Label            Usage          Type ST Offset   Length
I (84) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (91) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (99) boot:  2 factory          factory app      00 00 00010000 007f0000
I (106) boot: End of partition table
I (111) esp_image: segment 0: paddr=00010020 vaddr=3fc89000 size=00088h (   136) load
I (119) esp_image: segment 1: paddr=000100b0 vaddr=40370000 size=009dch (  2524) load
I (129) boot: Loaded app from partition at offset 0x10000
I (134) boot: Disabling RNG early entropy source...
W (139) bootloader_random: RNG for ESP32-S3 not currently supported

I have based my changes on v0.29.0, because I can't run Tinygo with Xtensa and LLVM 16. For whatever reason I get some errors while running tinygo build when the target is esp32 (or like in my case esp32s3):

unknown tool: -o
failed to run tool: clang

Much of my work here is copy & paste from the ESP32 code base, with a few adaptations. Hopefully it's a good start for someone else to continue my work :)

@denysvitali denysvitali marked this pull request as draft October 2, 2023 22:52
@denysvitali
Copy link
Author

FYI, the chip sort of works now (I get UART outputs with a simple Go program) :)

@denysvitali denysvitali marked this pull request as ready for review December 13, 2023 01:20
@denysvitali
Copy link
Author

FYI: I talked about the experience of porting TinyGo to the ESP32-S3 today at the Go Meetup @ AWS.
You can find the resources here.

@deadprogram
Copy link
Member

Hello @denysvitali just looking at this PR thanks for working on it.

There have been several changes since it was first created, including that we are now using the official versions of the SVD files in the submodule. You perhaps no longer need that file?

Another suggestion would be to put the .S file into the targets directory instead of device/esp since generally those device directories are only used for generated file.

Hopefully you have some time to make some of these changes, as it would be great to get this into the next version of TinyGo.

Thank you!

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, just one extra test that's needed and a few code cleanliness comments.
Can you rebase this PR on top of the current dev branch, so we can see how well it works there?

// The following definitions were copied from:
// esp-idf/components/xtensa/include/xtensa/corebits.h
#define PS_WOE_MASK 0x00040000
#define PS_OWB_MASK 0x00000F01
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is exactly identical to src/device/esp/esp32.S, can you reuse that file but adjust this #define using a preprocessor macro? Something like:

#ifdef ESP32S3
#define PS_OWB_MASK                0x00000F01
#else
#define PS_OWB_MASK                0x00000F00
#endif

And then you can add it as a define in the "cflags" key in esp32s3.json ("-DESP32S3").

Comment on lines +45 to +54
// // Change CPU frequency from 20MHz to 80MHz, by switching from the XTAL to
// // the PLL clock source (see table "CPU Clock Frequency" in the reference
// // manual).
// esp.SYSTEM.SYSCLK_CONF.Set(1 << esp.SYSTEM_SYSCLK_CONF_SOC_CLK_SEL_Pos)

// // Change CPU frequency from 80MHz to 160MHz by setting SYSTEM_CPUPERIOD_SEL
// // to 1 (see table "CPU Clock Frequency" in the reference manual).
// // Note: we might not want to set SYSTEM_CPU_WAIT_MODE_FORCE_ON to save
// // power. It is set here to keep the default on reset.
// esp.SYSTEM.CPU_PER_CONF.Set(esp.SYSTEM_CPU_PER_CONF_CPU_WAIT_MODE_FORCE_ON | esp.SYSTEM_CPU_PER_CONF_PLL_FREQ_SEL | 1<<esp.SYSTEM_CPU_PER_CONF_CPUPERIOD_SEL_Pos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: replace this with a TODO instead. There's not much to be gained from having this commented code here: the same code is already present in the runtime support for the esp32c3.

Comment on lines +3 to +4
"cpu": "esp32s3",
"features": "+atomctl,+bool,+coprocessor,+debug,+density,+dfpaccel,+div32,+exception,+fp,+highpriinterrupts,+interrupt,+loop,+mac16,+memctl,+miscsr,+mul32,+mul32high,+nsa,+prid,+regprotect,+rvector,+s32c1i,+sext,+threadptr,+timerint,+windowed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the esp32s3 to the list in builder/builder_test.go to ensure this list is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants