mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c54e3dd88 | |||
| 47c0debe4b | |||
| 9a1cde40a8 | |||
| 20fc814635 | |||
| 64d8a04308 | |||
| b95effbdd7 | |||
| 92c130c7be | |||
| 31c4bc1151 | |||
| 42f5e55ed5 | |||
| 81da7bb4c1 | |||
| 209754493b | |||
| b0aef96340 | |||
| 056394e24b | |||
| 1545659817 |
@@ -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
|
0.35.0
|
||||||
---
|
---
|
||||||
* **general**
|
* **general**
|
||||||
|
|||||||
+10
-8
@@ -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
|
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
|
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
|
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:
|
tinygo-baremetal:
|
||||||
# Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest.
|
# 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
|
@$(MD5SUM) test.hex
|
||||||
# test simulated boards on play.tinygo.org
|
# test simulated boards on play.tinygo.org
|
||||||
ifneq ($(WASM), 0)
|
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
|
@$(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
|
@$(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
|
@$(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
|
@$(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
|
@$(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
|
@$(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
|
@$(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
|
@$(MD5SUM) test.wasm
|
||||||
endif
|
endif
|
||||||
# test all targets/boards
|
# test all targets/boards
|
||||||
|
|||||||
@@ -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.
|
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
|
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.
|
LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
|||||||
@@ -48,20 +48,22 @@ Here is a small TinyGo program for use by a WASI host application:
|
|||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
//go:wasm-module yourmodulename
|
//go:wasmexport add
|
||||||
//export add
|
|
||||||
func add(x, y uint32) uint32 {
|
func add(x, y uint32) uint32 {
|
||||||
return x + y
|
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
|
```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
|
## Installation
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ func TestClangAttributes(t *testing.T) {
|
|||||||
{GOOS: "darwin", GOARCH: "arm64"},
|
{GOOS: "darwin", GOARCH: "arm64"},
|
||||||
{GOOS: "windows", GOARCH: "amd64"},
|
{GOOS: "windows", GOARCH: "amd64"},
|
||||||
{GOOS: "windows", GOARCH: "arm64"},
|
{GOOS: "windows", GOARCH: "arm64"},
|
||||||
{GOOS: "wasip1", GOARCH: "wasm"},
|
|
||||||
} {
|
} {
|
||||||
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
||||||
if options.GOARCH == "arm" {
|
if options.GOARCH == "arm" {
|
||||||
|
|||||||
+3
-28
@@ -356,17 +356,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
||||||
}
|
}
|
||||||
case "wasm":
|
case "wasm":
|
||||||
llvmarch = "wasm32"
|
return nil, fmt.Errorf("GOARCH=wasm but GOOS is unset. Please set GOOS to wasm, wasip1, or wasip2.")
|
||||||
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",
|
|
||||||
)
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
||||||
}
|
}
|
||||||
@@ -446,23 +436,8 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
"--no-insert-timestamp",
|
"--no-insert-timestamp",
|
||||||
"--no-dynamicbase",
|
"--no-dynamicbase",
|
||||||
)
|
)
|
||||||
case "wasip1":
|
case "wasm", "wasip1", "wasip2":
|
||||||
spec.GC = "" // use default GC
|
return nil, fmt.Errorf("GOOS=%s but GOARCH is unset. Please set GOARCH to wasm", options.GOOS)
|
||||||
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"
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// Version of TinyGo.
|
// Version of TinyGo.
|
||||||
// Update this value before release of new version of software.
|
// 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
|
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
||||||
// (like 0.30.0-dev-abcd012).
|
// (like 0.30.0-dev-abcd012).
|
||||||
|
|||||||
@@ -269,6 +269,8 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
|
|||||||
|
|
||||||
if needsSyscallPackage {
|
if needsSyscallPackage {
|
||||||
paths["syscall/"] = true // include syscall/js
|
paths["syscall/"] = true // include syscall/js
|
||||||
|
paths["internal/syscall/"] = true
|
||||||
|
paths["internal/syscall/unix/"] = false
|
||||||
}
|
}
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1684,8 +1684,24 @@ func main() {
|
|||||||
usage(command)
|
usage(command)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if options.Target == "" && filepath.Ext(outpath) == ".wasm" {
|
if options.Target == "" {
|
||||||
options.Target = "wasm"
|
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)
|
err := Build(pkgName, outpath, options)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package unix
|
||||||
|
|
||||||
|
const (
|
||||||
|
R_OK = 0x4
|
||||||
|
W_OK = 0x2
|
||||||
|
X_OK = 0x1
|
||||||
|
)
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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")
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
cpuFreq = 125 * MHz
|
||||||
_NUMBANK0_GPIOS = 30
|
_NUMBANK0_GPIOS = 30
|
||||||
_NUMBANK0_IRQS = 4
|
_NUMBANK0_IRQS = 4
|
||||||
_NUMIRQ = 32
|
_NUMIRQ = 32
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
cpuFreq = 150 * MHz
|
||||||
_NUMBANK0_GPIOS = 48
|
_NUMBANK0_GPIOS = 48
|
||||||
_NUMBANK0_IRQS = 6
|
_NUMBANK0_IRQS = 6
|
||||||
rp2350ExtraReg = 1
|
rp2350ExtraReg = 1
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CPUFrequency() uint32 {
|
func CPUFrequency() uint32 {
|
||||||
return 125 * MHz
|
return cpuFreq
|
||||||
}
|
}
|
||||||
|
|
||||||
// clockIndex identifies a hardware clock
|
// 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.
|
// init initializes the clock hardware.
|
||||||
//
|
//
|
||||||
@@ -165,7 +177,7 @@ func (clks *clocksType) init() {
|
|||||||
// REF FBDIV VCO POSTDIV
|
// REF FBDIV VCO POSTDIV
|
||||||
// pllSys: 12 / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
|
// pllSys: 12 / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
|
||||||
// pllUSB: 12 / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz
|
// 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)
|
pllUSB.init(1, 40, 5, 2)
|
||||||
|
|
||||||
// Configure clocks
|
// Configure clocks
|
||||||
@@ -173,15 +185,15 @@ func (clks *clocksType) init() {
|
|||||||
cref := clks.clock(clkRef)
|
cref := clks.clock(clkRef)
|
||||||
cref.configure(rp.CLOCKS_CLK_REF_CTRL_SRC_XOSC_CLKSRC,
|
cref.configure(rp.CLOCKS_CLK_REF_CTRL_SRC_XOSC_CLKSRC,
|
||||||
0, // No aux mux
|
0, // No aux mux
|
||||||
12*MHz,
|
xoscFreq,
|
||||||
12*MHz)
|
xoscFreq)
|
||||||
|
|
||||||
// clkSys = pllSys (125MHz) / 1 = 125MHz
|
// clkSys = pllSys (125MHz) / 1 = 125MHz
|
||||||
csys := clks.clock(clkSys)
|
csys := clks.clock(clkSys)
|
||||||
csys.configure(rp.CLOCKS_CLK_SYS_CTRL_SRC_CLKSRC_CLK_SYS_AUX,
|
csys.configure(rp.CLOCKS_CLK_SYS_CTRL_SRC_CLKSRC_CLK_SYS_AUX,
|
||||||
rp.CLOCKS_CLK_SYS_CTRL_AUXSRC_CLKSRC_PLL_SYS,
|
rp.CLOCKS_CLK_SYS_CTRL_AUXSRC_CLKSRC_PLL_SYS,
|
||||||
125*MHz,
|
cpuFreq,
|
||||||
125*MHz)
|
cpuFreq)
|
||||||
|
|
||||||
// clkUSB = pllUSB (48MHz) / 1 = 48MHz
|
// clkUSB = pllUSB (48MHz) / 1 = 48MHz
|
||||||
cusb := clks.clock(clkUSB)
|
cusb := clks.clock(clkUSB)
|
||||||
@@ -205,8 +217,8 @@ func (clks *clocksType) init() {
|
|||||||
cperi := clks.clock(clkPeri)
|
cperi := clks.clock(clkPeri)
|
||||||
cperi.configure(0,
|
cperi.configure(0,
|
||||||
rp.CLOCKS_CLK_PERI_CTRL_AUXSRC_CLK_SYS,
|
rp.CLOCKS_CLK_PERI_CTRL_AUXSRC_CLK_SYS,
|
||||||
125*MHz,
|
cpuFreq,
|
||||||
125*MHz)
|
cpuFreq)
|
||||||
|
|
||||||
clks.initTicks()
|
clks.initTicks()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ var errVCOOverflow = errors.New("VCO calculation overflow; use lower MHz")
|
|||||||
//
|
//
|
||||||
// Example for 12MHz crystal and RP2350:
|
// 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 {
|
type pllSearch struct {
|
||||||
LowerVCO bool
|
LowerVCO bool
|
||||||
LockRefDiv uint8
|
LockRefDiv uint8
|
||||||
|
|||||||
@@ -104,13 +104,13 @@ func (spi SPI) Transfer(w byte) (byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) SetBaudRate(br uint32) 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.
|
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
|
// Find smallest prescale value which puts output frequency in range of
|
||||||
// post-divide. Prescale is an even number from 2 to 254 inclusive.
|
// post-divide. Prescale is an even number from 2 to 254 inclusive.
|
||||||
var prescale, postdiv uint32
|
var prescale, postdiv uint32
|
||||||
|
freq := CPUFrequency()
|
||||||
for prescale = 2; prescale < 255; prescale += 2 {
|
for prescale = 2; prescale < 255; prescale += 2 {
|
||||||
if freqin < (prescale+2)*256*br {
|
if freq < (prescale+2)*256*br {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ func (spi SPI) SetBaudRate(br uint32) error {
|
|||||||
// Find largest post-divide which makes output <= baudrate. Post-divide is
|
// Find largest post-divide which makes output <= baudrate. Post-divide is
|
||||||
// an integer in the range 1 to 256 inclusive.
|
// an integer in the range 1 to 256 inclusive.
|
||||||
for postdiv = 256; postdiv > 1; postdiv-- {
|
for postdiv = 256; postdiv > 1; postdiv-- {
|
||||||
if freqin/(prescale*(postdiv-1)) > br {
|
if freq/(prescale*(postdiv-1)) > br {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (uart *UART) Configure(config UARTConfig) error {
|
|||||||
|
|
||||||
// SetBaudRate sets the baudrate to be used for the UART.
|
// SetBaudRate sets the baudrate to be used for the UART.
|
||||||
func (uart *UART) SetBaudRate(br uint32) {
|
func (uart *UART) SetBaudRate(br uint32) {
|
||||||
div := 8 * 125 * MHz / br
|
div := 8 * CPUFrequency() / br
|
||||||
|
|
||||||
ibrd := div >> 7
|
ibrd := div >> 7
|
||||||
var fbrd uint32
|
var fbrd uint32
|
||||||
|
|||||||
+75
-1
@@ -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 {
|
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 {
|
func (v Value) Addr() Value {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"inherits": ["pico2"],
|
||||||
|
"build-tags": ["pico2-w", "cyw43439"]
|
||||||
|
}
|
||||||
@@ -321,6 +321,7 @@
|
|||||||
|
|
||||||
// func stringVal(value string) ref
|
// func stringVal(value string) ref
|
||||||
"syscall/js.stringVal": (value_ptr, value_len) => {
|
"syscall/js.stringVal": (value_ptr, value_len) => {
|
||||||
|
value_ptr >>>= 0;
|
||||||
const s = loadString(value_ptr, value_len);
|
const s = loadString(value_ptr, value_len);
|
||||||
return boxValue(s);
|
return boxValue(s);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user