Compare commits

...

14 Commits

Author SHA1 Message Date
deadprogram 8c54e3dd88 release: update version to 0.36.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-03-03 13:02:59 -08:00
deadprogram 47c0debe4b docs: update CHANGELOG for 0.36.0 release
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-03-03 13:02:59 -08:00
Randy Reddig 9a1cde40a8 src/reflect: implement Value.Equal
Implementation copied from Go.
2025-03-03 12:14:30 -08:00
Elias Naur 20fc814635 machine: replace hard-coded cpu frequencies on rp2xxx (#4767)
Missed from the earlier change that bumped the rp2350 frequency.
2025-03-02 08:38:29 -03:00
Egawa Takashi 64d8a04308 convert offset as signed int into unsigned int in syscall/js.stringVal in wasm_exec.js 2025-03-01 09:14:57 -08:00
Elias Naur b95effbdd7 machine: bump rp2350 CPUFrequency to 150 MHz (#4766)
Leave rp2040 speed bump to 200 MHz for a future change, because it
requires bumping the core voltage as well[0].

[0] https://github.com/raspberrypi/pico-sdk/releases/tag/2.1.1
2025-03-01 10:09:53 -03:00
Elias Naur 92c130c7be machine: compute rp2 clock dividers from crystal and target frequency (#4747)
Follow-up to #4728 which implemented the algorithm for finding the
dividers.

The calculation is computed at compile time by interp, as verified by
building example/blinky1 for -target pico.
2025-02-28 19:05:27 -03:00
deadprogram 31c4bc1151 license: update for 2025
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-02-28 20:56:22 +01:00
deadprogram 42f5e55ed5 docs: small corrections for README regarding wasm
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-02-28 20:56:22 +01:00
deadprogram 81da7bb4c1 targets: add target for pico2-w board
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-02-28 20:02:35 +01:00
deadprogram 209754493b make: use GOOS and GOARCH for building wasm simulated boards
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-02-28 18:02:21 +01:00
deadprogram b0aef96340 fix: only infer target for wasm when GOOS and GOARCH are set correctly, not just based on file extension
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-02-28 18:02:21 +01:00
Ayke van Laethem 056394e24b make: add test-corpus-wasip2
I wanted to run the test corpus with WASIp2 so I added these lines.
2025-02-28 16:16:12 +01:00
Ayke van Laethem 1545659817 internal/syscall/unix: use our own version of this package
The upstream one assumes it's running on a Unix system (which makes
sense), but this package is also used on baremetal. So replace it on
systems that need a replaced syscall package.
2025-02-27 15:45:23 +01:00
21 changed files with 251 additions and 64 deletions
+69
View File
@@ -1,3 +1,72 @@
0.36.0
---
* **general**
- add initial Go 1.24 support
- add support for LLVM 19
- update license for 2025
- make small corrections for README regarding wasm
- use GOOS and GOARCH for building wasm simulated boards
- only infer target for wasm when GOOS and GOARCH are set correctly, not just based on file extension
- add test-corpus-wasip2
- use older image for cross-compiling builds
- update Linux builds to run on ubuntu-latest since 20.04 is being retired
- ensure build output directory is created
- add NoSandbox flag to chrome headless that is run during WASM tests, since this is now required for Ubuntu 23+ and we are using Ubuntu 24+ when running Github Actions
- update wasmtime used for CI to 29.0.1 to fix issue with install during CI tests
- update to use `Get-CimInstance` as `wmic` is being deprecated on WIndows
- remove unnecessary executable permissions
- `goenv`: update to new v0.36.0 development version
* **compiler**
- `builder`: fix parsing of external ld.lld error messages
- `cgo`: mangle identifier names
- `interp`: correctly mark functions as modifying memory
- add buildmode=wasi-legacy to support existing base of users who expected the older behavior for wasi modules to not return an exit code as if they were reactors
* **standard library**
- `crypto/tls`: add Dialer.DialContext() to fix websocket client
- `crypto/tls`: add VersionTLS constants and VersionName(version uint16) method that turns it into a string, copied from big go
- `internal/syscall/unix`: use our own version of this package
- `machine`: replace hard-coded cpu frequencies on rp2xxx
- `machine`: bump rp2350 CPUFrequency to 150 MHz
- `machine`: compute rp2 clock dividers from crystal and target frequency
- `machine`: remove bytes package dependency in flash code
- `machine/usb/descriptor`: avoid bytes package
- `net`: update to latest submodule with httptest subpackage and ResolveIPAddress implementation
- `os`: add File.Chdir support
- `os`: implement stub Chdir for non-OS systems
- `os/file`: add file.Chmod
- `reflect`: implement Value.Equal
- `runtime`: add FIPS helper functions
- `runtime`: manually initialize xorshift state
- `sync`: move Mutex to internal/task
- `syscall`: add wasip1 RandomGet
- `testing`: add Chdir
- `wasip2`: add stubs to get internal/syscall/unix to work
* **fixes**
- correctly handle calls for GetRNG() when being made from nrf devices with SoftDevice enabled
- fix stm32f103 ADC
- `wasm`: correctly handle id lookup for finalizeRef call
- `wasm`: avoid total failure on wasm finalizer call
- `wasm`: convert offset as signed int into unsigned int in syscall/js.stringVal in wasm_exec.js
* **targets**
- rp2350: add pll generalized solution; fix ADC handles; pwm period fix
- rp2350: extending support to include the rp2350b
- rp2350: cleanup: unexport internal USB and clock package variable, consts and types
- nrf: make ADC resolution changeable
- turn on GC for TKey1 device, since it does in fact work
- match Pico2 stack size to Pico
* **boards**
- add support for Pimoroni Pico Plus2
- add target for pico2-w board
- add comboat_fw tag for elecrow W5 boards with Combo-AT Wifi firmware
- add support for Elecrow Pico rp2350 W5 boards
- add support for Elecrow Pico rp2040 W5 boards
- add support for NRF51 HW-651
- add support for esp32c3-supermini
- add support for waveshare-rp2040-tiny
* **examples**
- add naive debouncing for pininterrupt example
0.35.0
---
* **general**
+10 -8
View File
@@ -491,6 +491,8 @@ test-corpus-fast:
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml
test-corpus-wasi: wasi-libc
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip1
test-corpus-wasip2: wasi-libc
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip2
tinygo-baremetal:
# Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest.
@@ -567,21 +569,21 @@ smoketest: testchdir
@$(MD5SUM) test.hex
# test simulated boards on play.tinygo.org
ifneq ($(WASM), 0)
$(TINYGO) build -size short -o test.wasm -tags=arduino examples/blinky1
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=arduino examples/blinky1
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=hifive1b examples/blinky1
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=hifive1b examples/blinky1
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=reelboard examples/blinky1
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=reelboard examples/blinky1
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=microbit examples/microbit-blink
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=microbit examples/microbit-blink
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=circuitplay_express examples/blinky1
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=circuitplay_express examples/blinky1
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/machinetest
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/machinetest
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
@$(MD5SUM) test.wasm
endif
# test all targets/boards
+2 -2
View File
@@ -1,7 +1,7 @@
Copyright (c) 2018-2023 The TinyGo Authors. All rights reserved.
Copyright (c) 2018-2025 The TinyGo Authors. All rights reserved.
TinyGo includes portions of the Go standard library.
Copyright (c) 2009-2023 The Go Authors. All rights reserved.
Copyright (c) 2009-2024 The Go Authors. All rights reserved.
TinyGo includes portions of LLVM, which is under the Apache License v2.0 with
LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
+9 -7
View File
@@ -48,20 +48,22 @@ Here is a small TinyGo program for use by a WASI host application:
```go
package main
//go:wasm-module yourmodulename
//export add
//go:wasmexport add
func add(x, y uint32) uint32 {
return x + y
}
// main is required for the `wasip1` target, even if it isn't used.
func main() {}
```
This compiles the above TinyGo program for use on any WASI runtime:
This compiles the above TinyGo program for use on any WASI Preview 1 runtime:
```shell
tinygo build -o main.wasm -target=wasip1 main.go
tinygo build -buildmode=c-shared -o add.wasm -target=wasip1 add.go
```
You can also use the same syntax as Go 1.24+:
```shell
GOARCH=wasip1 GOOS=wasm tinygo build -buildmode=c-shared -o add.wasm add.go
```
## Installation
-1
View File
@@ -69,7 +69,6 @@ func TestClangAttributes(t *testing.T) {
{GOOS: "darwin", GOARCH: "arm64"},
{GOOS: "windows", GOARCH: "amd64"},
{GOOS: "windows", GOARCH: "arm64"},
{GOOS: "wasip1", GOARCH: "wasm"},
} {
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
if options.GOARCH == "arm" {
+3 -28
View File
@@ -356,17 +356,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
}
case "wasm":
llvmarch = "wasm32"
spec.CPU = "generic"
spec.Features = "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types"
spec.BuildTags = append(spec.BuildTags, "tinygo.wasm")
spec.CFlags = append(spec.CFlags,
"-mbulk-memory",
"-mnontrapping-fptoint",
"-mno-multivalue",
"-mno-reference-types",
"-msign-ext",
)
return nil, fmt.Errorf("GOARCH=wasm but GOOS is unset. Please set GOOS to wasm, wasip1, or wasip2.")
default:
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
}
@@ -446,23 +436,8 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
"--no-insert-timestamp",
"--no-dynamicbase",
)
case "wasip1":
spec.GC = "" // use default GC
spec.Scheduler = "asyncify"
spec.Linker = "wasm-ld"
spec.RTLib = "compiler-rt"
spec.Libc = "wasi-libc"
spec.DefaultStackSize = 1024 * 64 // 64kB
spec.LDFlags = append(spec.LDFlags,
"--stack-first",
"--no-demangle",
)
spec.Emulator = "wasmtime run --dir={tmpDir}::/tmp {}"
spec.ExtraFiles = append(spec.ExtraFiles,
"src/runtime/asm_tinygowasm.S",
"src/internal/task/task_asyncify_wasm.S",
)
llvmos = "wasi"
case "wasm", "wasip1", "wasip2":
return nil, fmt.Errorf("GOOS=%s but GOARCH is unset. Please set GOARCH to wasm", options.GOOS)
default:
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
// Version of TinyGo.
// Update this value before release of new version of software.
const version = "0.36.0-dev"
const version = "0.36.0"
// Return TinyGo version, either in the form 0.30.0 or as a development version
// (like 0.30.0-dev-abcd012).
+2
View File
@@ -269,6 +269,8 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
if needsSyscallPackage {
paths["syscall/"] = true // include syscall/js
paths["internal/syscall/"] = true
paths["internal/syscall/unix/"] = false
}
return paths
}
+18 -2
View File
@@ -1684,8 +1684,24 @@ func main() {
usage(command)
os.Exit(1)
}
if options.Target == "" && filepath.Ext(outpath) == ".wasm" {
options.Target = "wasm"
if options.Target == "" {
switch {
case options.GOARCH == "wasm":
switch options.GOOS {
case "js":
options.Target = "wasm"
case "wasip1":
options.Target = "wasip1"
case "wasip2":
options.Target = "wasip2"
default:
fmt.Fprintln(os.Stderr, "GOARCH=wasm but GOOS is not set correctly. Please set GOOS to wasm, wasip1, or wasip2.")
os.Exit(1)
}
case filepath.Ext(outpath) == ".wasm":
fmt.Fprintln(os.Stderr, "you appear to want to build a wasm file, but have not specified either a target flag, or the GOARCH/GOOS to use.")
os.Exit(1)
}
}
err := Build(pkgName, outpath, options)
+7
View File
@@ -0,0 +1,7 @@
package unix
const (
R_OK = 0x4
W_OK = 0x2
X_OK = 0x1
)
+10
View File
@@ -0,0 +1,10 @@
package unix
import "syscall"
func Eaccess(path string, mode uint32) error {
// We don't support this syscall on baremetal or wasm.
// Callers are generally able to deal with this since unix.Eaccess also
// isn't available on Android.
return syscall.ENOSYS
}
+12
View File
@@ -0,0 +1,12 @@
package unix
type GetRandomFlag uintptr
const (
GRND_NONBLOCK GetRandomFlag = 0x0001
GRND_RANDOM GetRandomFlag = 0x0002
)
func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
panic("todo: unix.GetRandom")
}
+1
View File
@@ -9,6 +9,7 @@ import (
)
const (
cpuFreq = 125 * MHz
_NUMBANK0_GPIOS = 30
_NUMBANK0_IRQS = 4
_NUMIRQ = 32
+1
View File
@@ -9,6 +9,7 @@ import (
)
const (
cpuFreq = 150 * MHz
_NUMBANK0_GPIOS = 48
_NUMBANK0_IRQS = 6
rp2350ExtraReg = 1
+21 -9
View File
@@ -10,7 +10,7 @@ import (
)
func CPUFrequency() uint32 {
return 125 * MHz
return cpuFreq
}
// clockIndex identifies a hardware clock
@@ -137,7 +137,19 @@ func (clk *clock) configure(src, auxsrc, srcFreq, freq uint32) {
}
const pllsysFB, pllsysPD1, pllsysPD2 uint32 = 125, 6, 2 // RP2040 running 125MHz with 1500MHz VCO.
var pllsysFB, pllsysPD1, pllsysPD2 uint32
// Compute clock dividers.
//
// Note that the entire init function is computed at compile time
// by interp.
func init() {
fb, _, pd1, pd2, err := pllSearch{LockRefDiv: 1}.CalcDivs(xoscFreq*MHz, cpuFreq, MHz)
if err != nil {
panic(err)
}
pllsysFB, pllsysPD1, pllsysPD2 = uint32(fb), uint32(pd1), uint32(pd2)
}
// init initializes the clock hardware.
//
@@ -165,7 +177,7 @@ func (clks *clocksType) init() {
// REF FBDIV VCO POSTDIV
// pllSys: 12 / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
// pllUSB: 12 / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz
pllSys.init(1, uint32(pllsysFB), uint32(pllsysPD1), uint32(pllsysPD2))
pllSys.init(1, pllsysFB, pllsysPD1, pllsysPD2)
pllUSB.init(1, 40, 5, 2)
// Configure clocks
@@ -173,15 +185,15 @@ func (clks *clocksType) init() {
cref := clks.clock(clkRef)
cref.configure(rp.CLOCKS_CLK_REF_CTRL_SRC_XOSC_CLKSRC,
0, // No aux mux
12*MHz,
12*MHz)
xoscFreq,
xoscFreq)
// clkSys = pllSys (125MHz) / 1 = 125MHz
csys := clks.clock(clkSys)
csys.configure(rp.CLOCKS_CLK_SYS_CTRL_SRC_CLKSRC_CLK_SYS_AUX,
rp.CLOCKS_CLK_SYS_CTRL_AUXSRC_CLKSRC_PLL_SYS,
125*MHz,
125*MHz)
cpuFreq,
cpuFreq)
// clkUSB = pllUSB (48MHz) / 1 = 48MHz
cusb := clks.clock(clkUSB)
@@ -205,8 +217,8 @@ func (clks *clocksType) init() {
cperi := clks.clock(clkPeri)
cperi.configure(0,
rp.CLOCKS_CLK_PERI_CTRL_AUXSRC_CLK_SYS,
125*MHz,
125*MHz)
cpuFreq,
cpuFreq)
clks.initTicks()
}
+1 -1
View File
@@ -111,7 +111,7 @@ var errVCOOverflow = errors.New("VCO calculation overflow; use lower MHz")
//
// Example for 12MHz crystal and RP2350:
//
// fbdiv, refdiv, pd1, pd2, _ := pllSearch{LockRefDiv:1}.CalcDivs(12*MHz, 133*MHz, MHz)
// fbdiv, refdiv, pd1, pd2, _ := pllSearch{LockRefDiv:1}.CalcDivs(12*MHz, 150*MHz, MHz)
type pllSearch struct {
LowerVCO bool
LockRefDiv uint8
+3 -3
View File
@@ -104,13 +104,13 @@ func (spi SPI) Transfer(w byte) (byte, error) {
}
func (spi SPI) SetBaudRate(br uint32) error {
const freqin uint32 = 125 * MHz
const maxBaud uint32 = 66.5 * MHz // max output frequency is 66.5MHz on rp2040. see Note page 527.
// Find smallest prescale value which puts output frequency in range of
// post-divide. Prescale is an even number from 2 to 254 inclusive.
var prescale, postdiv uint32
freq := CPUFrequency()
for prescale = 2; prescale < 255; prescale += 2 {
if freqin < (prescale+2)*256*br {
if freq < (prescale+2)*256*br {
break
}
}
@@ -120,7 +120,7 @@ func (spi SPI) SetBaudRate(br uint32) error {
// Find largest post-divide which makes output <= baudrate. Post-divide is
// an integer in the range 1 to 256 inclusive.
for postdiv = 256; postdiv > 1; postdiv-- {
if freqin/(prescale*(postdiv-1)) > br {
if freq/(prescale*(postdiv-1)) > br {
break
}
}
+1 -1
View File
@@ -75,7 +75,7 @@ func (uart *UART) Configure(config UARTConfig) error {
// SetBaudRate sets the baudrate to be used for the UART.
func (uart *UART) SetBaudRate(br uint32) {
div := 8 * 125 * MHz / br
div := 8 * CPUFrequency() / br
ibrd := div >> 7
var fbrd uint32
+75 -1
View File
@@ -271,8 +271,82 @@ func (v Value) Comparable() bool {
}
}
// Equal reports true if v is equal to u.
// For two invalid values, Equal will report true.
// For an interface value, Equal will compare the value within the interface.
// Otherwise, If the values have different types, Equal will report false.
// Otherwise, for arrays and structs Equal will compare each element in order,
// and report false if it finds non-equal elements.
// During all comparisons, if values of the same type are compared,
// and the type is not comparable, Equal will panic.
//
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
func (v Value) Equal(u Value) bool {
panic("unimplemented: reflect.Value.Equal")
if v.Kind() == Interface {
v = v.Elem()
}
if u.Kind() == Interface {
u = u.Elem()
}
if !v.IsValid() || !u.IsValid() {
return v.IsValid() == u.IsValid()
}
if v.Kind() != u.Kind() || v.Type() != u.Type() {
return false
}
// Handle each Kind directly rather than calling valueInterface
// to avoid allocating.
switch v.Kind() {
default:
panic("reflect.Value.Equal: invalid Kind")
case Bool:
return v.Bool() == u.Bool()
case Int, Int8, Int16, Int32, Int64:
return v.Int() == u.Int()
case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
return v.Uint() == u.Uint()
case Float32, Float64:
return v.Float() == u.Float()
case Complex64, Complex128:
return v.Complex() == u.Complex()
case String:
return v.String() == u.String()
case Chan, Pointer, UnsafePointer:
return v.Pointer() == u.Pointer()
case Array:
// u and v have the same type so they have the same length
vl := v.Len()
if vl == 0 {
// panic on [0]func()
if !v.Type().Elem().Comparable() {
break
}
return true
}
for i := 0; i < vl; i++ {
if !v.Index(i).Equal(u.Index(i)) {
return false
}
}
return true
case Struct:
// u and v have the same type so they have the same fields
nf := v.NumField()
for i := 0; i < nf; i++ {
if !v.Field(i).Equal(u.Field(i)) {
return false
}
}
return true
case Func, Map, Slice:
break
}
panic("reflect.Value.Equal: values of type " + v.Type().String() + " are not comparable")
}
func (v Value) Addr() Value {
+4
View File
@@ -0,0 +1,4 @@
{
"inherits": ["pico2"],
"build-tags": ["pico2-w", "cyw43439"]
}
+1
View File
@@ -321,6 +321,7 @@
// func stringVal(value string) ref
"syscall/js.stringVal": (value_ptr, value_len) => {
value_ptr >>>= 0;
const s = loadString(value_ptr, value_len);
return boxValue(s);
},