From 95d1d90d8641fb5408d39a4ab8d1966f73d9459a Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 1 Oct 2023 17:31:51 +0200 Subject: [PATCH 1/6] guides: LLVM 16 is now the default, so adjust the docs --- content/docs/guides/build.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/docs/guides/build.md b/content/docs/guides/build.md index b4950cb9..2ef1cbc4 100644 --- a/content/docs/guides/build.md +++ b/content/docs/guides/build.md @@ -49,7 +49,7 @@ For **Debian** or **Ubuntu** you can install LLVM by adding a new apt repository | Debian | sid | `unstable`| ```shell -echo 'deb http://apt.llvm.org/xxxxx/ llvm-toolchain-xxxxx-15 main' | sudo tee /etc/apt/sources.list.d/llvm.list +echo 'deb http://apt.llvm.org/xxxxx/ llvm-toolchain-xxxxx-16 main' | sudo tee /etc/apt/sources.list.d/llvm.list ``` After adding the apt repository for your distribution you may install the LLVM toolchain packages: @@ -63,7 +63,7 @@ sudo apt-get install clang-16 llvm-16-dev lld-16 libclang-16-dev For **MacOS**, you can install LLVM through [Homebrew](https://formulae.brew.sh/formula/llvm). The Clang/LLVM version from Apple is not supported by TinyGo. ```shell -brew install llvm +brew install llvm@16 ``` For **Fedora** users you can install LLVM from the repository. Note that the version of LLVM [varies by Fedora version](https://packages.fedoraproject.org/pkgs/llvm/llvm-libs/), for example Fedora 37 has LLVM 15. From 58b8efc8a6f80c31a7144c1405331e1303ced954 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 1 Oct 2023 17:32:14 +0200 Subject: [PATCH 2/6] guides: LLVM 14 will soon be removed, so update the example to use LLVM 15 --- content/docs/guides/build.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/guides/build.md b/content/docs/guides/build.md index 2ef1cbc4..7e62aeea 100644 --- a/content/docs/guides/build.md +++ b/content/docs/guides/build.md @@ -90,7 +90,7 @@ If you are getting a build error like this, LLVM is not installed as expected: 1 error generated. ``` -This can often be fixed by specifying the LLVM version as a build tag, for example `-tags=llvm14` if you have LLVM 14 instead of LLVM 16. +This can often be fixed by specifying the LLVM version as a build tag, for example `-tags=llvm15` if you have LLVM 15 instead of LLVM 16. Note that you should not use `make` when you want to build using a system-installed LLVM, just use the Go toolchain. `make` is used when you want to use a self-built LLVM, as in the next section. From 725851b0fb605d0fd2cfe6f9a05dd29fee9507b1 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 1 Oct 2023 17:32:33 +0200 Subject: [PATCH 3/6] guides: lld-libs isn't needed on Fedora, but clang-libs is Tested on Fedora 39. --- content/docs/guides/build.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/guides/build.md b/content/docs/guides/build.md index 7e62aeea..d245d032 100644 --- a/content/docs/guides/build.md +++ b/content/docs/guides/build.md @@ -69,7 +69,7 @@ brew install llvm@16 For **Fedora** users you can install LLVM from the repository. Note that the version of LLVM [varies by Fedora version](https://packages.fedoraproject.org/pkgs/llvm/llvm-libs/), for example Fedora 37 has LLVM 15. ```shell -sudo dnf install llvm-devel lld-libs lld +sudo dnf install llvm-devel clang-libs lld ``` After LLVM has been installed, installing TinyGo should be as easy as running the following command: From 54bf7c4a28ff580bef4809659cf6119e380eaa9d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 11 Jun 2023 19:02:40 +0200 Subject: [PATCH 4/6] imports: always run tests on linux/amd64 This makes test outputs more consistent, even though it is a lot slower on my arm64 laptop (running the tests in QEMU). --- imports/main.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/imports/main.go b/imports/main.go index 7097b552..455d9117 100644 --- a/imports/main.go +++ b/imports/main.go @@ -12,8 +12,13 @@ import ( "text/template" ) +const ( + testGOOS = "linux" + testGOARCH = "amd64" +) + // The environment to pass to `go` commands when they are invoked. -var commandEnv = []string{"GOPATH=/does-not-exist", "GO111MODULE=off"} +var commandEnv = []string{"GOPATH=/does-not-exist", "GO111MODULE=off", "GOOS=" + testGOOS, "GOARCH=" + testGOARCH} var markdownTemplate = template.Must(template.New("markdown").Parse(` --- @@ -24,11 +29,13 @@ The following table shows all Go standard library packages and whether they can Note that the fact they can be imported, does not mean that all functions and types in the program can be used. For example, sometimes using some functions or types of the package will still trigger compiler errors. +Test results are for {{.goos}}/{{.goarch}}. + Package | Importable | Passes tests ---- | --- | --- |{{ range .}} +--- | --- | --- |{{ range .pkgs}} {{.Path}} | {{if .CanBeCompiled}} yes {{else}} [ no](#{{.Link}}) {{end}} | {{if .PassesTests}} yes {{else if .CanBeCompiled}} [ no](#{{.Link}}) {{else}} no {{end}} | {{ end }} -{{range .}} +{{range .pkgs}} {{if not .PassesTests }} ## {{.Path}} @@ -234,7 +241,11 @@ func checkPackages(goroot string) error { } // Print the output to stdout. - return markdownTemplate.Execute(os.Stdout, pkgMap) + return markdownTemplate.Execute(os.Stdout, map[string]interface{}{ + "pkgs": pkgMap, + "goos": testGOOS, + "goarch": testGOARCH, + }) } func (pkg *Package) runTest() (result testResult) { @@ -252,6 +263,7 @@ func (pkg *Package) runTest() (result testResult) { // Run the compile test. cmd := exec.Command("tinygo", "build", "-o", temporaryExecutableFile, temporaryGoFile) + cmd.Env = append(cmd.Environ(), "GOOS="+testGOOS, "GOARCH="+testGOARCH) buf := new(bytes.Buffer) cmd.Stdout = buf cmd.Stderr = buf @@ -261,6 +273,7 @@ func (pkg *Package) runTest() (result testResult) { // Run the actual test. if result.compiles { cmd := exec.Command("tinygo", "test", pkg.Path) + cmd.Env = append(cmd.Environ(), "GOOS="+testGOOS, "GOARCH="+testGOARCH) buf := new(bytes.Buffer) cmd.Stdout = buf cmd.Stderr = buf From df4b869d8a60dc98fcb6c2fa388479bcafa68e4a Mon Sep 17 00:00:00 2001 From: Kenneth Bell Date: Fri, 20 Oct 2023 11:58:42 +0100 Subject: [PATCH 5/6] Document machine.HardwareID --- content/docs/reference/machine.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/content/docs/reference/machine.md b/content/docs/reference/machine.md index 91992ef3..d126b150 100644 --- a/content/docs/reference/machine.md +++ b/content/docs/reference/machine.md @@ -365,6 +365,14 @@ CPUReset performs a hard system reset. Not all chips support CPUReset. +```go +func DeviceID() []byte +``` + +DeviceID returns a byte array containing a unique id (aka Serial Number) specific to this chip. In some architectures (notably RP2040) the device ID is actually the ID of the flash chip. The device ID can be useful for identifying specific devices within a family. There is no guarantee the ID is globally unique. The size of the ID is chip-family specific with 8 bytes (64 bits) and 16 bytes (128 bits) being common. + +Not all chips have a hardware ID. + ```go func GetRNG() uint32 ``` From 9f630d94775a0f72ae1a55010a2533206eab8638 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 8 Apr 2023 14:46:13 +0200 Subject: [PATCH 6/6] reference/machine: add SPI DMA support --- content/docs/reference/machine.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/content/docs/reference/machine.md b/content/docs/reference/machine.md index d126b150..35a89600 100644 --- a/content/docs/reference/machine.md +++ b/content/docs/reference/machine.md @@ -148,6 +148,30 @@ The `Tx` performs the actual SPI transaction, and return an error if there was a Some chips may also support mismatched lengths of `w` and `r`, in which case they will behave like above for the remaining bytes in the byte slice that's the longest of the two. +```go +func (spi SPI) IsAsync() bool +``` + +Return whether the SPI supports asynchronous operation (usually using [DMA](https://en.wikipedia.org/wiki/Direct_memory_access)). Asynchronous operation may be supported for some or all transfers, for example it may only be supported for send-only transfers. + +```go +func (spi SPI) StartTx(w, r []byte) error +``` + +Start a SPI transmission in the background (usually, using DMA). This has the same effect as running `Tx` in a goroutine, but doesn't spawn a new goroutine. The `w` and `r` byte slices must not be used while the transmission is in progress, but must be stored somewhere outside the `StartTx` function to avoid garbage collecting them. + +It is allowed to start multiple transactions without waiting for the first to finish. They will have the effect as if `Tx` was called multiple times in sequence. Lots of hardware won't support this however and will simply wait for the first to finish before starting a new transmission. + +If `IsAsync` returns false, this is an alias for `Tx`. + +```go +func (spi SPI) Wait() error +``` + +Wait until all active transactions (started by `StartTx`) have finished. The buffers provided in `StartTx` will be available after calling `Wait`. + +If `IsAsync` returns false, this is a no-op. + ## I2C