Compare commits

..

1 Commits

Author SHA1 Message Date
Ayke van Laethem c9f1b71ab3 machine: use native WriteRegister/ReadRegister functions on mimxrt1062
This seems better than adding extra WriteRegisterEx/ReadRegisterEx
methods that do the same thing but use hardware features instead of
implementing it in software.
2024-02-14 20:14:37 +01:00
227 changed files with 1021 additions and 2697 deletions
+20 -11
View File
@@ -5,17 +5,17 @@ commands:
steps: steps:
- run: - run:
name: "Pull submodules" name: "Pull submodules"
command: git submodule update --init command: git submodule update --init --recursive
llvm-source-linux: llvm-source-linux:
steps: steps:
- restore_cache: - restore_cache:
keys: keys:
- llvm-source-18-v1 - llvm-source-17-v1
- run: - run:
name: "Fetch LLVM source" name: "Fetch LLVM source"
command: make llvm-source command: make llvm-source
- save_cache: - save_cache:
key: llvm-source-18-v1 key: llvm-source-17-v1
paths: paths:
- llvm-project/clang/lib/Headers - llvm-project/clang/lib/Headers
- llvm-project/clang/include - llvm-project/clang/include
@@ -33,13 +33,13 @@ commands:
steps: steps:
- restore_cache: - restore_cache:
keys: keys:
- binaryen-linux-v3 - binaryen-linux-v2
- run: - run:
name: "Build Binaryen" name: "Build Binaryen"
command: | command: |
make binaryen make binaryen
- save_cache: - save_cache:
key: binaryen-linux-v3 key: binaryen-linux-v2
paths: paths:
- build/wasm-opt - build/wasm-opt
test-linux: test-linux:
@@ -88,7 +88,7 @@ commands:
# Do this before gen-device so that it doesn't check the # Do this before gen-device so that it doesn't check the
# formatting of generated files. # formatting of generated files.
name: Check Go code formatting name: Check Go code formatting
command: make fmt-check lint command: make fmt-check
- run: make gen-device -j4 - run: make gen-device -j4
- run: make smoketest XTENSA=0 - run: make smoketest XTENSA=0
- save_cache: - save_cache:
@@ -105,12 +105,19 @@ jobs:
- test-linux: - test-linux:
llvm: "15" llvm: "15"
resource_class: large resource_class: large
test-llvm18-go122: test-llvm16-go122:
docker: docker:
- image: golang:1.22-bullseye - image: golang:1.22-rc-bullseye
steps: steps:
- test-linux: - test-linux:
llvm: "18" llvm: "16"
resource_class: large
test-llvm17-go121:
docker:
- image: golang:1.21-bullseye
steps:
- test-linux:
llvm: "17"
resource_class: large resource_class: large
workflows: workflows:
@@ -119,5 +126,7 @@ workflows:
# This tests our lowest supported versions of Go and LLVM, to make sure at # This tests our lowest supported versions of Go and LLVM, to make sure at
# least the smoke tests still pass. # least the smoke tests still pass.
- test-llvm15-go118 - test-llvm15-go118
# This tests LLVM 18 support when linking against system libraries. # This tests the upcoming Go 1.22 support.
- test-llvm18-go122 - test-llvm16-go122
# This tests LLVM 17 support when linking against system libraries.
- test-llvm17-go121
+7 -7
View File
@@ -37,13 +37,13 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Restore LLVM source cache - name: Restore LLVM source cache
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-${{ matrix.os }}-v2 key: llvm-source-17-${{ matrix.os }}-v1
path: | path: |
llvm-project/clang/lib/Headers llvm-project/clang/lib/Headers
llvm-project/clang/include llvm-project/clang/include
@@ -68,7 +68,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-18-${{ matrix.os }}-v2 key: llvm-build-17-${{ matrix.os }}-v1
path: llvm-build path: llvm-build
- name: Build LLVM - name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true' if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -128,7 +128,7 @@ jobs:
runs-on: macos-latest runs-on: macos-latest
strategy: strategy:
matrix: matrix:
version: [16, 17, 18] version: [16, 17]
steps: steps:
- name: Set up Homebrew - name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master uses: Homebrew/actions/setup-homebrew@master
@@ -145,15 +145,15 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Build TinyGo (LLVM ${{ matrix.version }}) - name: Build TinyGo (LLVM ${{ matrix.version }})
run: go install -tags=llvm${{ matrix.version }} run: go install -tags=llvm${{ matrix.version }}
- name: Check binary - name: Check binary
run: tinygo version run: tinygo version
- name: Build TinyGo (default LLVM) - name: Build TinyGo (default LLVM)
if: matrix.version == 18 if: matrix.version == 17
run: go install run: go install
- name: Check binary - name: Check binary
if: matrix.version == 18 if: matrix.version == 17
run: tinygo version run: tinygo version
+1
View File
@@ -64,6 +64,7 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-contexts: tinygo-llvm-build=docker-image://tinygo/llvm-17
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
- name: Trigger Drivers repo build on Github Actions - name: Trigger Drivers repo build on Github Actions
+13 -15
View File
@@ -18,13 +18,13 @@ jobs:
# statically linked binary. # statically linked binary.
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: golang:1.22-alpine image: golang:1.21-alpine
steps: steps:
- name: Install apk dependencies - name: Install apk dependencies
# tar: needed for actions/cache@v4 # tar: needed for actions/cache@v4
# git+openssh: needed for checkout (I think?) # git+openssh: needed for checkout (I think?)
# ruby: needed to install fpm # ruby: needed to install fpm
run: apk add tar git openssh make g++ ruby-dev run: apk add tar git openssh make g++ ruby
- name: Work around CVE-2022-24765 - name: Work around CVE-2022-24765
# We're not on a multi-user machine, so this is safe. # We're not on a multi-user machine, so this is safe.
run: git config --global --add safe.directory "$GITHUB_WORKSPACE" run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
@@ -43,7 +43,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-linux-alpine-v1 key: llvm-source-17-linux-alpine-v1
path: | path: |
llvm-project/clang/lib/Headers llvm-project/clang/lib/Headers
llvm-project/clang/include llvm-project/clang/include
@@ -68,7 +68,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-18-linux-alpine-v1 key: llvm-build-17-linux-alpine-v1
path: llvm-build path: llvm-build
- name: Build LLVM - name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true' if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -113,8 +113,6 @@ jobs:
gem install --version 4.0.7 public_suffix gem install --version 4.0.7 public_suffix
gem install --version 2.7.6 dotenv gem install --version 2.7.6 dotenv
gem install --no-document fpm gem install --no-document fpm
- name: Run linter
run: make lint
- name: Build TinyGo release - name: Build TinyGo release
run: | run: |
make release deb -j3 STATIC=1 make release deb -j3 STATIC=1
@@ -137,7 +135,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Install wasmtime - name: Install wasmtime
run: | run: |
@@ -180,7 +178,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
@@ -196,7 +194,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-linux-asserts-v1 key: llvm-source-17-linux-asserts-v1
path: | path: |
llvm-project/clang/lib/Headers llvm-project/clang/lib/Headers
llvm-project/clang/include llvm-project/clang/include
@@ -221,7 +219,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-18-linux-asserts-v1 key: llvm-build-17-linux-asserts-v1
path: llvm-build path: llvm-build
- name: Build LLVM - name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true' if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -303,13 +301,13 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Restore LLVM source cache - name: Restore LLVM source cache
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-linux-v1 key: llvm-source-17-linux-v1
path: | path: |
llvm-project/clang/lib/Headers llvm-project/clang/lib/Headers
llvm-project/clang/include llvm-project/clang/include
@@ -334,7 +332,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-18-linux-${{ matrix.goarch }}-v1 key: llvm-build-17-linux-${{ matrix.goarch }}-v1
path: llvm-build path: llvm-build
- name: Build LLVM - name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true' if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -358,13 +356,13 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
id: cache-binaryen id: cache-binaryen
with: with:
key: binaryen-linux-${{ matrix.goarch }}-v4 key: binaryen-linux-${{ matrix.goarch }}-v3
path: build/wasm-opt path: build/wasm-opt
- name: Build Binaryen - name: Build Binaryen
if: steps.cache-binaryen.outputs.cache-hit != 'true' if: steps.cache-binaryen.outputs.cache-hit != 'true'
run: | run: |
sudo apt-get install --no-install-recommends ninja-build sudo apt-get install --no-install-recommends ninja-build
git submodule update --init lib/binaryen git submodule update --init --recursive lib/binaryen
make CROSS=${{ matrix.toolchain }} binaryen make CROSS=${{ matrix.toolchain }} binaryen
- name: Install fpm - name: Install fpm
run: | run: |
+2 -2
View File
@@ -35,8 +35,8 @@ jobs:
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: | images: |
tinygo/llvm-18 tinygo/llvm-17
ghcr.io/${{ github.repository_owner }}/llvm-18 ghcr.io/${{ github.repository_owner }}/llvm-17
tags: | tags: |
type=sha,format=long type=sha,format=long
type=raw,value=latest type=raw,value=latest
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-linux-nix-v1 key: llvm-source-17-linux-nix-v1
path: | path: |
llvm-project/compiler-rt llvm-project/compiler-rt
- name: Download LLVM source - name: Download LLVM source
+5 -5
View File
@@ -2,11 +2,11 @@
# still works after checking out the dev branch (that is, when going from LLVM # still works after checking out the dev branch (that is, when going from LLVM
# 16 to LLVM 17 for example, both Clang 16 and Clang 17 are installed). # 16 to LLVM 17 for example, both Clang 16 and Clang 17 are installed).
echo 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' | sudo tee /etc/apt/sources.list.d/llvm.list echo 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update sudo apt-get update
sudo apt-get install --no-install-recommends -y \ sudo apt-get install --no-install-recommends -y \
llvm-18-dev \ llvm-17-dev \
clang-18 \ clang-17 \
libclang-18-dev \ libclang-17-dev \
lld-18 lld-17
+2 -2
View File
@@ -28,7 +28,7 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-sizediff-v1 key: llvm-source-17-sizediff-v1
path: | path: |
llvm-project/compiler-rt llvm-project/compiler-rt
- name: Download LLVM source - name: Download LLVM source
@@ -37,7 +37,7 @@ jobs:
- name: Cache Go - name: Cache Go
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
key: go-cache-linux-sizediff-v2-${{ hashFiles('go.mod') }} key: go-cache-linux-sizediff-v1-${{ hashFiles('go.mod') }}
path: | path: |
~/.cache/go-build ~/.cache/go-build
~/go/pkg/mod ~/go/pkg/mod
+6 -6
View File
@@ -35,13 +35,13 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Restore cached LLVM source - name: Restore cached LLVM source
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-18-windows-v1 key: llvm-source-17-windows-v1
path: | path: |
llvm-project/clang/lib/Headers llvm-project/clang/lib/Headers
llvm-project/clang/include llvm-project/clang/include
@@ -66,7 +66,7 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-18-windows-v1 key: llvm-build-17-windows-v1
path: llvm-build path: llvm-build
- name: Build LLVM - name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true' if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -143,7 +143,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Download TinyGo build - name: Download TinyGo build
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -173,7 +173,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Download TinyGo build - name: Download TinyGo build
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -209,7 +209,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.22' go-version: '1.21'
cache: true cache: true
- name: Download TinyGo build - name: Download TinyGo build
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
+1 -1
View File
@@ -85,7 +85,7 @@ Now that we have a working static build, it's time to make a release tarball:
If you did not clone the repository with the `--recursive` option, you will get errors until you initialize the project submodules: If you did not clone the repository with the `--recursive` option, you will get errors until you initialize the project submodules:
git submodule update --init git submodule update --init --recursive
The release tarball is stored in build/release.tar.gz, and can be extracted with The release tarball is stored in build/release.tar.gz, and can be extracted with
the following command (for example in ~/lib): the following command (for example in ~/lib):
-102
View File
@@ -1,105 +1,3 @@
0.31.2
---
* **general**
* update the `net` submodule to updated version with `Buffers` implementation
* **compiler**
* `syscall`: add wasm_unknown tag to some additional files so it can compile more code
* **standard library**
* `runtime`: add Frame.Entry field
0.31.1
---
* **general**
* fix Binaryen build in make task
* update final build stage of Docker `dev` image to go1.22
* only use GHA cache for building Docker `dev` image
* update the `net` submodule to latest version
* **compiler**
* `interp`: make getelementptr offsets signed
* `interp`: return a proper error message when indexing out of range
0.31.0
---
* **general**
* remove LLVM 14 support
* add LLVM 17 support, and use it by default
* add Nix flake support
* update bundled Binaryen to version 116
* add `ports` subcommand that lists available serial ports for `-port` and `-monitor`
* support wasmtime version 14
* add `-serial=rtt` for serial output over SWD
* add Go 1.22 support and use it by default
* change minimum Node.js version from 16 to 18
* **compiler**
* use the new LLVM pass manager
* allow systems with more stack space to allocate larger values on the stack
* `build`: fix a crash due to sharing GlobalValues between build instances
* `cgo`: add `C._Bool` type
* `cgo`: fix calling CGo callback inside generic function
* `compileopts`: set `purego` build tag by default so that more packages can be built
* `compileopts`: force-enable CGo to avoid build issues
* `compiler`: fix crash on type assert on interfaces with no methods
* `interp`: print LLVM instruction in traceback
* `interp`: support runtime times by running them at runtime
* `loader`: enforce Go language version in the type checker (this may break existing programs with an incorrect Go version in go.mod)
* `transform`: fix bug in StringToBytes optimization pass
* **standard library**
* `crypto/tls`: stub out a lot of functions
* `internal/task`, `machine`: make TinyGo code usable with "big Go" CGo
* `machine`: implement `I2C.SetBaudRate` consistently across chips
* `machine`: implement `SPI.Configure` consistently across chips
* `machine`: add `DeviceID` for nrf, rp2040, sam, stm32
* `machine`: use smaller UART buffer size on atmega chips
* `machine/usb`: allow setting a serial number using a linker flag
* `math`: support more math functions on baremetal (picolibc) systems
* `net`: replace entire net package with a new one based on the netdev driver
* `os/user`: add bare-bones implementation of this package
* `reflect`: stub `CallSlice` and `FuncOf`
* `reflect`: add `TypeFor[T]`
* `reflect`: update `IsZero` to Go 1.22 semantics
* `reflect`: move indirect values into interface when setting interfaces
* `runtime`: stub `Breakpoint`
* `sync`: implement trylock
* **targets**
* `atmega`: use UART double speed mode for fewer errors and higher throughput
* `atmega328pb`: refactor to enable extra uart
* `avr`: don't compile large parts of picolibc (math, stdio) for LLVM 17 support
* `esp32`: switch over to the official SVD file
* `esp32c3`: implement USB_SERIAL for USBCDC communication
* `esp32c3`: implement I2C
* `esp32c3`: implement RNG
* `esp32c3`: add more ROM functions and update linker script for the in-progress wifi support
* `esp32c3`: update to newer SVD files
* `rp2040`: add support for UART hardware flow control
* `rp2040`: add definition for `machine.PinToggle`
* `rp2040`: set XOSC startup delay multiplier
* `samd21`: add support for UART hardware flow control
* `samd51`: add support for UART hardware flow control
* `wasm`: increase default stack size to 64k for wasi/wasm targets
* `wasm`: bump wasi-libc version to SDK 20
* `wasm`: remove line of dead code in wasm_exec.js
* **new targets/boards**
* `qtpy-esp32c3`: add Adafruit QT Py ESP32-C3 board
* `mksnanov3`: add support for the MKS Robin Nano V3.x
* `nrf52840-generic`: add generic nrf52840 chip support
* `thumby`: add support for Thumby
* `wasm`: add new `wasm-unknown` target that doesn't depend on WASI or a browser
* **boards**
* `arduino-mkrwifi1010`, `arduino-nano33`, `nano-rp2040`, `matrixportal-m4`, `metro-m4-airlift`, `pybadge`, `pyportal`: add `ninafw` build tag and some constants for BLE support
* `gopher-badge`: fix typo in USB product name
* `nano-rp2040`: add UART1 and correct mappings for NINA via UART
* `pico`: bump default stack size from 2kB to 8kB
* `wioterminal`: expose UART4
0.30.0 0.30.0
--- ---
+17 -15
View File
@@ -1,5 +1,5 @@
# tinygo-llvm stage obtains the llvm source for TinyGo # tinygo-llvm stage obtains the llvm source for TinyGo
FROM golang:1.22 AS tinygo-llvm FROM golang:1.21 AS tinygo-llvm
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y apt-utils make cmake clang-15 ninja-build && \ apt-get install -y apt-utils make cmake clang-15 ninja-build && \
@@ -20,24 +20,26 @@ FROM tinygo-llvm AS tinygo-llvm-build
RUN cd /tinygo/ && \ RUN cd /tinygo/ && \
make llvm-build make llvm-build
# tinygo-compiler-build stage builds the compiler itself # tinygo-compiler stage builds the compiler itself
FROM tinygo-llvm-build AS tinygo-compiler-build FROM tinygo-llvm-build AS tinygo-compiler
COPY . /tinygo COPY . /tinygo
# build the compiler and tools # update submodules
RUN cd /tinygo/ && \ RUN cd /tinygo/ && \
git submodule update --init && \ rm -rf ./lib/*/ && \
git submodule sync && \
git submodule update --init --recursive --force
RUN cd /tinygo/ && \
make
# tinygo-tools stage installs the needed dependencies to compile TinyGo programs for all platforms.
FROM tinygo-compiler AS tinygo-tools
RUN cd /tinygo/ && \
make wasi-libc binaryen && \
make gen-device -j4 && \ make gen-device -j4 && \
make build/release cp build/* $GOPATH/bin/
# tinygo-compiler copies the compiler build over to a base Go container (without
# all the build tools etc).
FROM golang:1.22 AS tinygo-compiler
# Copy tinygo build.
COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo
# Configure the container.
ENV PATH="${PATH}:/tinygo/bin"
CMD ["tinygo"] CMD ["tinygo"]
+16 -52
View File
@@ -10,7 +10,7 @@ LLD_SRC ?= $(LLVM_PROJECTDIR)/lld
# Try to autodetect LLVM build tools. # Try to autodetect LLVM build tools.
# Versions are listed here in descending priority order. # Versions are listed here in descending priority order.
LLVM_VERSIONS = 18 17 16 15 LLVM_VERSIONS = 17 16 15
errifempty = $(if $(1),$(1),$(error $(2))) errifempty = $(if $(1),$(1),$(error $(2)))
detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2))) detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2)))
toolSearchPathsVersion = $(1)-$(2) toolSearchPathsVersion = $(1)-$(2)
@@ -31,7 +31,6 @@ export GOROOT = $(shell $(GO) env GOROOT)
# Flags to pass to go test. # Flags to pass to go test.
GOTESTFLAGS ?= GOTESTFLAGS ?=
GOTESTPKGS ?= ./builder ./cgo ./compileopts ./compiler ./interp ./transform .
# tinygo binary for tests # tinygo binary for tests
TINYGO ?= $(call detect,tinygo,tinygo $(CURDIR)/build/tinygo) TINYGO ?= $(call detect,tinygo,tinygo $(CURDIR)/build/tinygo)
@@ -111,7 +110,7 @@ endif
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp .PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontenddriver frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
EXE = .exe EXE = .exe
@@ -147,7 +146,7 @@ endif
MD5SUM ?= md5sum MD5SUM ?= md5sum
# Libraries that should be linked in for the statically linked Clang. # Libraries that should be linked in for the statically linked Clang.
CLANG_LIB_NAMES = clangAnalysis clangAPINotes clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions
CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++ CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++
# Libraries that should be linked in for the statically linked LLD. # Libraries that should be linked in for the statically linked LLD.
@@ -166,7 +165,7 @@ LIB_NAMES = clang $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES)
# library path (for ninja). # library path (for ninja).
# This list also includes a few tools that are necessary as part of the full # This list also includes a few tools that are necessary as part of the full
# TinyGo build. # TinyGo build.
NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm lld $(addprefix lib/lib,$(addsuffix .a,$(LIB_NAMES))) NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(addsuffix .a,$(LIB_NAMES)))
# For static linking. # For static linking.
ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","") ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","")
@@ -191,7 +190,7 @@ gen-device: gen-device-stm32
endif endif
gen-device-avr: gen-device-avr:
@if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi @if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init --recursive"; exit 1; fi
$(GO) build -o ./build/gen-device-avr ./tools/gen-device-avr/ $(GO) build -o ./build/gen-device-avr ./tools/gen-device-avr/
./build/gen-device-avr lib/avr/packs/atmega src/device/avr/ ./build/gen-device-avr lib/avr/packs/atmega src/device/avr/
./build/gen-device-avr lib/avr/packs/tiny src/device/avr/ ./build/gen-device-avr lib/avr/packs/tiny src/device/avr/
@@ -239,7 +238,7 @@ gen-device-renesas: build/gen-device-svd
# Get LLVM sources. # Get LLVM sources.
$(LLVM_PROJECTDIR)/llvm: $(LLVM_PROJECTDIR)/llvm:
git clone -b tinygo_xtensa_release_18.1.2 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) git clone -b xtensa_release_17.0.1 --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR)
llvm-source: $(LLVM_PROJECTDIR)/llvm llvm-source: $(LLVM_PROJECTDIR)/llvm
# Configure LLVM. # Configure LLVM.
@@ -257,7 +256,7 @@ ifneq ($(USE_SYSTEM_BINARYEN),1)
binaryen: build/wasm-opt$(EXE) binaryen: build/wasm-opt$(EXE)
build/wasm-opt$(EXE): build/wasm-opt$(EXE):
mkdir -p build mkdir -p build
cd lib/binaryen && cmake -G Ninja . -DBUILD_STATIC_LIB=ON -DBUILD_TESTS=OFF $(BINARYEN_OPTION) && ninja bin/wasm-opt$(EXE) cd lib/binaryen && cmake -G Ninja . -DBUILD_STATIC_LIB=ON $(BINARYEN_OPTION) && ninja bin/wasm-opt$(EXE)
cp lib/binaryen/bin/wasm-opt$(EXE) build/wasm-opt$(EXE) cp lib/binaryen/bin/wasm-opt$(EXE) build/wasm-opt$(EXE)
endif endif
@@ -265,7 +264,7 @@ endif
.PHONY: wasi-libc .PHONY: wasi-libc
wasi-libc: lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a wasi-libc: lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a
lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a: lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a:
@if [ ! -e lib/wasi-libc/Makefile ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi @if [ ! -e lib/wasi-libc/Makefile ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init --recursive"; exit 1; fi
cd lib/wasi-libc && $(MAKE) -j4 EXTRA_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC="$(CLANG)" AR=$(LLVM_AR) NM=$(LLVM_NM) cd lib/wasi-libc && $(MAKE) -j4 EXTRA_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC="$(CLANG)" AR=$(LLVM_AR) NM=$(LLVM_NM)
# Check for Node.js used during WASM tests. # Check for Node.js used during WASM tests.
@@ -284,7 +283,7 @@ tinygo:
@if [ ! -f "$(LLVM_BUILDDIR)/bin/llvm-config" ]; then echo "Fetch and build LLVM first by running:"; echo " $(MAKE) llvm-source"; echo " $(MAKE) $(LLVM_BUILDDIR)"; exit 1; fi @if [ ! -f "$(LLVM_BUILDDIR)/bin/llvm-config" ]; then echo "Fetch and build LLVM first by running:"; echo " $(MAKE) llvm-source"; echo " $(MAKE) $(LLVM_BUILDDIR)"; exit 1; fi
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GOENVFLAGS) $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags "byollvm osusergo" -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" . CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GOENVFLAGS) $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags "byollvm osusergo" -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" .
test: wasi-libc check-nodejs-version test: wasi-libc check-nodejs-version
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=20m -buildmode exe -tags "byollvm osusergo" $(GOTESTPKGS) CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=20m -buildmode exe -tags "byollvm osusergo" ./builder ./cgo ./compileopts ./compiler ./interp ./transform .
# Standard library packages that pass tests on darwin, linux, wasi, and windows, but take over a minute in wasi # Standard library packages that pass tests on darwin, linux, wasi, and windows, but take over a minute in wasi
TEST_PACKAGES_SLOW = \ TEST_PACKAGES_SLOW = \
@@ -427,17 +426,17 @@ tinygo-bench-fast:
# Same thing, except for wasi rather than the current platform. # Same thing, except for wasi rather than the current platform.
tinygo-test-wasi: tinygo-test-wasi:
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi $(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
tinygo-test-wasip1: tinygo-test-wasip1:
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
tinygo-test-wasi-fast: tinygo-test-wasi-fast:
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi $(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
tinygo-test-wasip1-fast: tinygo-test-wasip1-fast:
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) ./tests/runtime_wasi GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
tinygo-bench-wasi: tinygo-bench-wasi:
$(TINYGO) test -target wasip1 -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) $(TINYGO) test -target wasi -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW)
tinygo-bench-wasi-fast: tinygo-bench-wasi-fast:
$(TINYGO) test -target wasip1 -bench . $(TEST_PACKAGES_FAST) $(TINYGO) test -target wasi -bench . $(TEST_PACKAGES_FAST)
# Test external packages in a large corpus. # Test external packages in a large corpus.
test-corpus: test-corpus:
@@ -445,7 +444,7 @@ test-corpus:
test-corpus-fast: 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=wasi
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.
@@ -525,8 +524,6 @@ ifneq ($(WASM), 0)
@$(MD5SUM) test.wasm @$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/serial $(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/serial
@$(MD5SUM) test.wasm @$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
@$(MD5SUM) test.wasm
endif endif
# test all targets/boards # test all targets/boards
$(TINYGO) build -size short -o test.hex -target=pca10040-s132v6 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=pca10040-s132v6 examples/blinky1
@@ -601,8 +598,6 @@ endif
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10056-s140v7 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=pca10056-s140v7 examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10059-s140v7 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=reelboard-s140v7 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=reelboard-s140v7 examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=wioterminal examples/blinky1 $(TINYGO) build -size short -o test.hex -target=wioterminal examples/blinky1
@@ -659,8 +654,6 @@ endif
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=badger2040 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=badger2040 examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=badger2040-w examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=tufty2040 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=tufty2040 examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=thingplus-rp2040 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=thingplus-rp2040 examples/blinky1
@@ -677,8 +670,6 @@ endif
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=ae-rp2040 examples/echo $(TINYGO) build -size short -o test.hex -target=ae-rp2040 examples/echo
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=thumby examples/echo
@$(MD5SUM) test.hex
# test pwm # test pwm
$(TINYGO) build -size short -o test.hex -target=itsybitsy-m0 examples/pwm $(TINYGO) build -size short -o test.hex -target=itsybitsy-m0 examples/pwm
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
@@ -710,8 +701,6 @@ ifneq ($(STM32), 0)
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=nucleo-l432kc examples/blinky1 $(TINYGO) build -size short -o test.hex -target=nucleo-l432kc examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=nucleo-l476rg examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=nucleo-l552ze examples/blinky1 $(TINYGO) build -size short -o test.hex -target=nucleo-l552ze examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=nucleo-wl55jc examples/blinky1 $(TINYGO) build -size short -o test.hex -target=nucleo-wl55jc examples/blinky1
@@ -768,8 +757,6 @@ ifneq ($(XTENSA), 0)
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
$(TINYGO) build -size short -o test.bin -target m5stick-c examples/serial $(TINYGO) build -size short -o test.bin -target m5stick-c examples/serial
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
$(TINYGO) build -size short -o test.bin -target m5paper examples/serial
@$(MD5SUM) test.bin
$(TINYGO) build -size short -o test.bin -target mch2022 examples/serial $(TINYGO) build -size short -o test.bin -target mch2022 examples/serial
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
endif endif
@@ -786,7 +773,6 @@ endif
ifneq ($(WASM), 0) ifneq ($(WASM), 0)
$(TINYGO) build -size short -o wasm.wasm -target=wasm examples/wasm/export $(TINYGO) build -size short -o wasm.wasm -target=wasm examples/wasm/export
$(TINYGO) build -size short -o wasm.wasm -target=wasm examples/wasm/main $(TINYGO) build -size short -o wasm.wasm -target=wasm examples/wasm/main
$(TINYGO) build -size short -o wasm.wasm -target=wasm-unknown examples/hello-wasm-unknown
endif endif
# test various compiler flags # test various compiler flags
$(TINYGO) build -size short -o test.hex -target=pca10040 -gc=none -scheduler=none examples/blinky1 $(TINYGO) build -size short -o test.hex -target=pca10040 -gc=none -scheduler=none examples/blinky1
@@ -829,9 +815,7 @@ build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN
@mkdir -p build/release/tinygo/lib/nrfx @mkdir -p build/release/tinygo/lib/nrfx
@mkdir -p build/release/tinygo/lib/picolibc/newlib/libc @mkdir -p build/release/tinygo/lib/picolibc/newlib/libc
@mkdir -p build/release/tinygo/lib/picolibc/newlib/libm @mkdir -p build/release/tinygo/lib/picolibc/newlib/libm
@mkdir -p build/release/tinygo/lib/wasi-libc/libc-bottom-half/headers @mkdir -p build/release/tinygo/lib/wasi-libc
@mkdir -p build/release/tinygo/lib/wasi-libc/libc-top-half/musl/arch
@mkdir -p build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
@mkdir -p build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0 @mkdir -p build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0
@mkdir -p build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus @mkdir -p build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0plus
@mkdir -p build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4 @mkdir -p build/release/tinygo/pkg/thumbv7em-unknown-unknown-eabi-cortex-m4
@@ -882,15 +866,7 @@ endif
@cp -rp lib/picolibc/newlib/libm/common build/release/tinygo/lib/picolibc/newlib/libm @cp -rp lib/picolibc/newlib/libm/common build/release/tinygo/lib/picolibc/newlib/libm
@cp -rp lib/picolibc/newlib/libm/math build/release/tinygo/lib/picolibc/newlib/libm @cp -rp lib/picolibc/newlib/libm/math build/release/tinygo/lib/picolibc/newlib/libm
@cp -rp lib/picolibc-stdio.c build/release/tinygo/lib @cp -rp lib/picolibc-stdio.c build/release/tinygo/lib
@cp -rp lib/wasi-libc/libc-bottom-half/headers/public build/release/tinygo/lib/wasi-libc/libc-bottom-half/headers @cp -rp lib/wasi-libc/sysroot build/release/tinygo/lib/wasi-libc/sysroot
@cp -rp lib/wasi-libc/libc-top-half/musl/arch/generic build/release/tinygo/lib/wasi-libc/libc-top-half/musl/arch
@cp -rp lib/wasi-libc/libc-top-half/musl/arch/wasm32 build/release/tinygo/lib/wasi-libc/libc-top-half/musl/arch
@cp -rp lib/wasi-libc/libc-top-half/musl/src/include build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
@cp -rp lib/wasi-libc/libc-top-half/musl/src/internal build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
@cp -rp lib/wasi-libc/libc-top-half/musl/src/math build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
@cp -rp lib/wasi-libc/libc-top-half/musl/src/string build/release/tinygo/lib/wasi-libc/libc-top-half/musl/src
@cp -rp lib/wasi-libc/libc-top-half/musl/include build/release/tinygo/lib/wasi-libc/libc-top-half/musl
@cp -rp lib/wasi-libc/sysroot build/release/tinygo/lib/wasi-libc/sysroot
@cp -rp llvm-project/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt-builtins @cp -rp llvm-project/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt-builtins
@cp -rp llvm-project/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt-builtins @cp -rp llvm-project/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt-builtins
@cp -rp src build/release/tinygo/src @cp -rp src build/release/tinygo/src
@@ -917,15 +893,3 @@ ifneq ($(RELEASEONLY), 1)
release: build/release release: build/release
deb: build/release deb: build/release
endif endif
lint:
go run github.com/mgechev/revive -version
# TODO: lint more directories!
# revive.toml isn't flexible enough to filter out just one kind of error from a checker, so do it with grep here.
# Can't use grep with friendly formatter. Plain output isn't too bad, though.
# Use 'grep .' to get rid of stray blank line
go run github.com/mgechev/revive -config revive.toml compiler/... src/{os,reflect}/*.go | grep -v "should have comment or be unexported" | grep '.' | awk '{print}; END {exit NR>0}'
spell:
# Check for typos in comments. Skip git submodules etc.
go run github.com/client9/misspell/cmd/misspell -i 'ackward,devided,extint,inbetween,programmmer,rela' $$( find . -depth 1 -type d | egrep -w -v 'lib|llvm|src/net' )
+3 -3
View File
@@ -41,7 +41,7 @@ tinygo flash -target arduino examples/blinky1
TinyGo is very useful for compiling programs both for use in browsers (WASM) as well as for use on servers and other edge devices (WASI). TinyGo is very useful for compiling programs both for use in browsers (WASM) as well as for use on servers and other edge devices (WASI).
TinyGo programs can run in [Fastly Compute](https://www.fastly.com/documentation/guides/compute/go/), [Fermyon Spin](https://developer.fermyon.com/spin/go-components), [wazero](https://wazero.io/languages/tinygo/) and many other WebAssembly runtimes. TinyGo programs can run in Fastly Compute@Edge (https://developer.fastly.com/learning/compute/go/), Fermyon Spin (https://developer.fermyon.com/spin/go-components), wazero (https://wazero.io/languages/tinygo/) and many other WebAssembly runtimes.
Here is a small TinyGo program for use by a WASI host application: Here is a small TinyGo program for use by a WASI host application:
@@ -54,14 +54,14 @@ 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. // main is required for the `wasi` target, even if it isn't used.
func main() {} 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 runtime:
```shell ```shell
tinygo build -o main.wasm -target=wasip1 main.go tinygo build -o main.wasm -target=wasi main.go
``` ```
## Installation ## Installation
+6 -16
View File
@@ -78,27 +78,17 @@ func makeArchive(arfile *os.File, objs []string) error {
} else if dbg, err := wasm.Parse(objfile); err == nil { } else if dbg, err := wasm.Parse(objfile); err == nil {
for _, s := range dbg.Sections { for _, s := range dbg.Sections {
switch section := s.(type) { switch section := s.(type) {
case *wasm.SectionLinking: case *wasm.SectionImport:
for _, symbol := range section.Symbols { for _, ln := range section.Entries {
if symbol.Flags&wasm.LinkingSymbolFlagUndefined != 0 {
// Don't list undefined functions. if ln.Kind != wasm.ExtKindFunction {
// Not a function
continue continue
} }
if symbol.Flags&wasm.LinkingSymbolFlagBindingLocal != 0 {
// Don't include local symbols.
continue
}
if symbol.Kind != wasm.LinkingSymbolKindFunction && symbol.Kind != wasm.LinkingSymbolKindData {
// Link functions and data symbols.
// Some data symbols need to be included, such as
// __log_data.
continue
}
// Include in the archive.
symbolTable = append(symbolTable, struct { symbolTable = append(symbolTable, struct {
name string name string
fileIndex int fileIndex int
}{symbol.Name, i}) }{ln.Field, i})
} }
} }
} }
+5 -33
View File
@@ -168,13 +168,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
return BuildResult{}, errors.New("could not find wasi-libc, perhaps you need to run `make wasi-libc`?") return BuildResult{}, errors.New("could not find wasi-libc, perhaps you need to run `make wasi-libc`?")
} }
libcDependencies = append(libcDependencies, dummyCompileJob(path)) libcDependencies = append(libcDependencies, dummyCompileJob(path))
case "wasmbuiltins":
libcJob, unlock, err := WasmBuiltins.load(config, tmpdir)
if err != nil {
return BuildResult{}, err
}
defer unlock()
libcDependencies = append(libcDependencies, libcJob)
case "mingw-w64": case "mingw-w64":
_, unlock, err := MinGW.load(config, tmpdir) _, unlock, err := MinGW.load(config, tmpdir)
if err != nil { if err != nil {
@@ -207,7 +200,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
MaxStackAlloc: config.MaxStackAlloc(), MaxStackAlloc: config.MaxStackAlloc(),
NeedsStackObjects: config.NeedsStackObjects(), NeedsStackObjects: config.NeedsStackObjects(),
Debug: !config.Options.SkipDWARF, // emit DWARF except when -internal-nodwarf is passed Debug: !config.Options.SkipDWARF, // emit DWARF except when -internal-nodwarf is passed
PanicStrategy: config.PanicStrategy(),
} }
// Load the target machine, which is the LLVM object that contains all // Load the target machine, which is the LLVM object that contains all
@@ -243,7 +235,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
// Create the *ssa.Program. This does not yet build the entire SSA of the // Create the *ssa.Program. This does not yet build the entire SSA of the
// program so it's pretty fast and doesn't need to be parallelized. // program so it's pretty fast and doesn't need to be parallelized.
program := lprogram.LoadSSA() program := lprogram.LoadSSA()
program.Build()
// Add jobs to compile each package. // Add jobs to compile each package.
// Packages that have a cache hit will not be compiled again. // Packages that have a cache hit will not be compiled again.
@@ -355,8 +346,8 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
packageActionIDJobs[pkg.ImportPath] = packageActionIDJob packageActionIDJobs[pkg.ImportPath] = packageActionIDJob
// Build the SSA for the given package. // Build the SSA for the given package.
//ssaPkg := program.Package(pkg.Pkg) ssaPkg := program.Package(pkg.Pkg)
//ssaPkg.Build() ssaPkg.Build()
// Now create the job to actually build the package. It will exit early // Now create the job to actually build the package. It will exit early
// if the package is already compiled. // if the package is already compiled.
@@ -371,12 +362,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
if _, err := os.Stat(job.result); err == nil { if _, err := os.Stat(job.result); err == nil {
// Already cached, don't recreate this package. // Already cached, don't recreate this package.
switch pkg.ImportPath { return nil
case "context": // seems to be needed
case "time": // often crashes in this package, so probably needed
default:
return nil
}
} }
// Compile AST to IR. The compiler.CompilePackage function will // Compile AST to IR. The compiler.CompilePackage function will
@@ -523,8 +509,6 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
run: func(*compileJob) error { run: func(*compileJob) error {
// Load and link all the bitcode files. This does not yet optimize // Load and link all the bitcode files. This does not yet optimize
// anything, it only links the bitcode files together. // anything, it only links the bitcode files together.
println("exit")
os.Exit(0)
ctx := llvm.NewContext() ctx := llvm.NewContext()
mod = ctx.NewModule("main") mod = ctx.NewModule("main")
for _, pkgJob := range packageJobs { for _, pkgJob := range packageJobs {
@@ -781,7 +765,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
if sizeLevel >= 2 { if sizeLevel >= 2 {
// Workaround with roughly the same effect as // Workaround with roughly the same effect as
// https://reviews.llvm.org/D119342. // https://reviews.llvm.org/D119342.
// Can hopefully be removed in LLVM 19. // Can hopefully be removed in LLVM 18.
ldflags = append(ldflags, ldflags = append(ldflags,
"-mllvm", "--rotation-max-header-size=0") "-mllvm", "--rotation-max-header-size=0")
} }
@@ -833,25 +817,13 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
args = append(args, "--asyncify") args = append(args, "--asyncify")
} }
exeunopt := result.Executable
if config.Options.Work {
// Keep the work direction around => don't overwrite the .wasm binary with the optimized version
exeunopt += ".pre-wasm-opt"
os.Rename(result.Executable, exeunopt)
}
args = append(args, args = append(args,
opt, opt,
"-g", "-g",
exeunopt, result.Executable,
"--output", result.Executable, "--output", result.Executable,
) )
if config.Options.PrintCommands != nil {
config.Options.PrintCommands(goenv.Get("WASMOPT"), args...)
}
cmd := exec.Command(goenv.Get("WASMOPT"), args...) cmd := exec.Command(goenv.Get("WASMOPT"), args...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
+1 -2
View File
@@ -33,9 +33,8 @@ func TestClangAttributes(t *testing.T) {
"k210", "k210",
"nintendoswitch", "nintendoswitch",
"riscv-qemu", "riscv-qemu",
"wasip1", "wasi",
"wasm", "wasm",
"wasm-unknown",
} }
if hasBuiltinTools { if hasBuiltinTools {
// hasBuiltinTools is set when TinyGo is statically linked with LLVM, // hasBuiltinTools is set when TinyGo is statically linked with LLVM,
+7 -5
View File
@@ -8,14 +8,14 @@ import (
"github.com/tinygo-org/tinygo/goenv" "github.com/tinygo-org/tinygo/goenv"
) )
// These are the GENERIC_SOURCES according to CMakeList.txt except for // These are the GENERIC_SOURCES according to CMakeList.txt.
// divmodsi4.c and udivmodsi4.c.
var genericBuiltins = []string{ var genericBuiltins = []string{
"absvdi2.c", "absvdi2.c",
"absvsi2.c", "absvsi2.c",
"absvti2.c", "absvti2.c",
"adddf3.c", "adddf3.c",
"addsf3.c", "addsf3.c",
"addtf3.c",
"addvdi3.c", "addvdi3.c",
"addvsi3.c", "addvsi3.c",
"addvti3.c", "addvti3.c",
@@ -40,12 +40,12 @@ var genericBuiltins = []string{
"divdf3.c", "divdf3.c",
"divdi3.c", "divdi3.c",
"divmoddi4.c", "divmoddi4.c",
//"divmodsi4.c",
"divmodti4.c",
"divsc3.c", "divsc3.c",
"divsf3.c", "divsf3.c",
"divsi3.c", "divsi3.c",
"divtc3.c",
"divti3.c", "divti3.c",
"divtf3.c",
"extendsfdf2.c", "extendsfdf2.c",
"extendhfsf2.c", "extendhfsf2.c",
"ffsdi2.c", "ffsdi2.c",
@@ -91,6 +91,7 @@ var genericBuiltins = []string{
"mulsc3.c", "mulsc3.c",
"mulsf3.c", "mulsf3.c",
"multi3.c", "multi3.c",
"multf3.c",
"mulvdi3.c", "mulvdi3.c",
"mulvsi3.c", "mulvsi3.c",
"mulvti3.c", "mulvti3.c",
@@ -110,11 +111,13 @@ var genericBuiltins = []string{
"popcountti2.c", "popcountti2.c",
"powidf2.c", "powidf2.c",
"powisf2.c", "powisf2.c",
"powitf2.c",
"subdf3.c", "subdf3.c",
"subsf3.c", "subsf3.c",
"subvdi3.c", "subvdi3.c",
"subvsi3.c", "subvsi3.c",
"subvti3.c", "subvti3.c",
"subtf3.c",
"trampoline_setup.c", "trampoline_setup.c",
"truncdfhf2.c", "truncdfhf2.c",
"truncdfsf2.c", "truncdfsf2.c",
@@ -123,7 +126,6 @@ var genericBuiltins = []string{
"ucmpti2.c", "ucmpti2.c",
"udivdi3.c", "udivdi3.c",
"udivmoddi4.c", "udivmoddi4.c",
//"udivmodsi4.c",
"udivmodti4.c", "udivmodti4.c",
"udivsi3.c", "udivsi3.c",
"udivti3.c", "udivti3.c",
+7 -8
View File
@@ -82,10 +82,10 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
// Parse the arguments. // Parse the arguments.
const OptTable &OptTbl = getDriverOptTable(); const OptTable &OptTbl = getDriverOptTable();
llvm::opt::Visibility VisibilityMask(options::CC1AsOption); const unsigned IncludedFlagsBitmask = options::CC1AsOption;
unsigned MissingArgIndex, MissingArgCount; unsigned MissingArgIndex, MissingArgCount;
InputArgList Args = InputArgList Args = OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount,
OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount, VisibilityMask); IncludedFlagsBitmask);
// Check for missing argument error. // Check for missing argument error.
if (MissingArgCount) { if (MissingArgCount) {
@@ -98,7 +98,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) { for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
auto ArgString = A->getAsString(Args); auto ArgString = A->getAsString(Args);
std::string Nearest; std::string Nearest;
if (OptTbl.findNearest(ArgString, Nearest, VisibilityMask) > 1) if (OptTbl.findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
Diags.Report(diag::err_drv_unknown_argument) << ArgString; Diags.Report(diag::err_drv_unknown_argument) << ArgString;
else else
Diags.Report(diag::err_drv_unknown_argument_with_suggestion) Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
@@ -521,10 +521,9 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
if (Asm.ShowHelp) { if (Asm.ShowHelp) {
getDriverOptTable().printHelp( getDriverOptTable().printHelp(
llvm::outs(), "clang -cc1as [options] file...", llvm::outs(), "clang -cc1as [options] file...",
"Clang Integrated Assembler", /*ShowHidden=*/false, "Clang Integrated Assembler",
/*ShowAllAliases=*/false, /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
llvm::opt::Visibility(driver::options::CC1AsOption)); /*ShowAllAliases=*/false);
return 0; return 0;
} }
+3 -3
View File
@@ -41,9 +41,9 @@ func TestBinarySize(t *testing.T) {
// This is a small number of very diverse targets that we want to test. // This is a small number of very diverse targets that we want to test.
tests := []sizeTest{ tests := []sizeTest{
// microcontrollers // microcontrollers
{"hifive1b", "examples/echo", 4484, 280, 0, 2252}, {"hifive1b", "examples/echo", 4476, 280, 0, 2252},
{"microbit", "examples/serial", 2732, 388, 8, 2256}, {"microbit", "examples/serial", 2724, 388, 8, 2256},
{"wioterminal", "examples/pininterrupt", 6016, 1484, 116, 6816}, {"wioterminal", "examples/pininterrupt", 5996, 1484, 116, 6816},
// TODO: also check wasm. Right now this is difficult, because // TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the // wasm binaries are run through wasm-opt and therefore the
-81
View File
@@ -1,81 +0,0 @@
package builder
import (
"os"
"path/filepath"
"github.com/tinygo-org/tinygo/goenv"
)
var WasmBuiltins = Library{
name: "wasmbuiltins",
makeHeaders: func(target, includeDir string) error {
if err := os.Mkdir(includeDir+"/bits", 0o777); err != nil {
return err
}
f, err := os.Create(includeDir + "/bits/alltypes.h")
if err != nil {
return err
}
if _, err := f.Write([]byte(wasmAllTypes)); err != nil {
return err
}
return f.Close()
},
cflags: func(target, headerPath string) []string {
libcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/wasi-libc")
return []string{
"-Werror",
"-Wall",
"-std=gnu11",
"-nostdlibinc",
"-isystem", libcDir + "/libc-top-half/musl/arch/wasm32",
"-isystem", libcDir + "/libc-top-half/musl/arch/generic",
"-isystem", libcDir + "/libc-top-half/musl/src/internal",
"-isystem", libcDir + "/libc-top-half/musl/src/include",
"-isystem", libcDir + "/libc-top-half/musl/include",
"-isystem", libcDir + "/libc-bottom-half/headers/public",
"-I" + headerPath,
}
},
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/wasi-libc") },
librarySources: func(target string) ([]string, error) {
return []string{
// memory builtins needed for llvm.memcpy.*, llvm.memmove.*, and
// llvm.memset.* LLVM intrinsics.
"libc-top-half/musl/src/string/memcpy.c",
"libc-top-half/musl/src/string/memmove.c",
"libc-top-half/musl/src/string/memset.c",
// exp, exp2, and log are needed for LLVM math builtin functions
// like llvm.exp.*.
"libc-top-half/musl/src/math/__math_divzero.c",
"libc-top-half/musl/src/math/__math_invalid.c",
"libc-top-half/musl/src/math/__math_oflow.c",
"libc-top-half/musl/src/math/__math_uflow.c",
"libc-top-half/musl/src/math/__math_xflow.c",
"libc-top-half/musl/src/math/exp.c",
"libc-top-half/musl/src/math/exp_data.c",
"libc-top-half/musl/src/math/exp2.c",
"libc-top-half/musl/src/math/log.c",
"libc-top-half/musl/src/math/log_data.c",
}, nil
},
}
// alltypes.h for wasm-libc, using the types as defined inside Clang.
const wasmAllTypes = `
typedef __SIZE_TYPE__ size_t;
typedef __INT8_TYPE__ int8_t;
typedef __INT16_TYPE__ int16_t;
typedef __INT32_TYPE__ int32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __UINTPTR_TYPE__ uintptr_t;
// This type is used internally in wasi-libc.
typedef double double_t;
`
+1 -1
View File
@@ -216,7 +216,7 @@ func (i simpleImporter) Import(path string) (*types.Package, error) {
} }
} }
// formatDiagnostic formats the error message to be an indented comment. It // formatDiagnostics formats the error message to be an indented comment. It
// also fixes Windows path name issues (backward slashes). // also fixes Windows path name issues (backward slashes).
func formatDiagnostic(err error) string { func formatDiagnostic(err error) string {
msg := err.Error() msg := err.Error()
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !byollvm && llvm17 //go:build !byollvm && !llvm15 && !llvm16
package cgo package cgo
-15
View File
@@ -1,15 +0,0 @@
//go:build !byollvm && !llvm15 && !llvm16 && !llvm17
package cgo
/*
#cgo linux CFLAGS: -I/usr/include/llvm-18 -I/usr/include/llvm-c-18 -I/usr/lib/llvm-18/include
#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@18/include
#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@18/include
#cgo freebsd CFLAGS: -I/usr/local/llvm18/include
#cgo linux LDFLAGS: -L/usr/lib/llvm-18/lib -lclang
#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@18/lib -lclang
#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@18/lib -lclang
#cgo freebsd LDFLAGS: -L/usr/local/llvm18/lib -lclang
*/
import "C"
+15 -10
View File
@@ -74,8 +74,7 @@ func (c *Config) GOARM() string {
// BuildTags returns the complete list of build tags used during this build. // BuildTags returns the complete list of build tags used during this build.
func (c *Config) BuildTags() []string { func (c *Config) BuildTags() []string {
tags := append([]string(nil), c.Target.BuildTags...) // copy slice (avoid a race) tags := append(c.Target.BuildTags, []string{
tags = append(tags, []string{
"tinygo", // that's the compiler "tinygo", // that's the compiler
"purego", // to get various crypto packages to work "purego", // to get various crypto packages to work
"math_big_pure_go", // to get math/big to work "math_big_pure_go", // to get math/big to work
@@ -88,6 +87,12 @@ func (c *Config) BuildTags() []string {
return tags return tags
} }
// CgoEnabled returns true if (and only if) CGo is enabled. It is true by
// default and false if CGO_ENABLED is set to "0".
func (c *Config) CgoEnabled() bool {
return goenv.Get("CGO_ENABLED") == "1"
}
// GC returns the garbage collection strategy in use on this platform. Valid // GC returns the garbage collection strategy in use on this platform. Valid
// values are "none", "leaking", "conservative" and "precise". // values are "none", "leaking", "conservative" and "precise".
func (c *Config) GC() string { func (c *Config) GC() string {
@@ -281,6 +286,10 @@ func (c *Config) CFlags(libclang bool) []string {
cflags = append(cflags, cflags = append(cflags,
"-resource-dir="+resourceDir, "-resource-dir="+resourceDir,
) )
if strings.HasPrefix(c.Triple(), "xtensa") {
// workaround needed in LLVM 16, see: https://github.com/espressif/llvm-project/issues/83
cflags = append(cflags, "-isystem", filepath.Join(resourceDir, "include"))
}
} }
switch c.Target.Libc { switch c.Target.Libc {
case "darwin-libSystem": case "darwin-libSystem":
@@ -311,11 +320,7 @@ func (c *Config) CFlags(libclang bool) []string {
) )
case "wasi-libc": case "wasi-libc":
root := goenv.Get("TINYGOROOT") root := goenv.Get("TINYGOROOT")
cflags = append(cflags, cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot")
"-nostdlibinc",
"-isystem", root+"/lib/wasi-libc/sysroot/include")
case "wasmbuiltins":
// nothing to add (library is purely for builtins)
case "mingw-w64": case "mingw-w64":
root := goenv.Get("TINYGOROOT") root := goenv.Get("TINYGOROOT")
path, _ := c.LibcPath("mingw-w64") path, _ := c.LibcPath("mingw-w64")
@@ -480,6 +485,9 @@ func (c *Config) OpenOCDConfiguration() (args []string, err error) {
return nil, fmt.Errorf("unknown OpenOCD transport: %#v", c.Target.OpenOCDTransport) return nil, fmt.Errorf("unknown OpenOCD transport: %#v", c.Target.OpenOCDTransport)
} }
args = []string{"-f", "interface/" + openocdInterface + ".cfg"} args = []string{"-f", "interface/" + openocdInterface + ".cfg"}
for _, cmd := range c.Target.OpenOCDCommands {
args = append(args, "-c", cmd)
}
if c.Target.OpenOCDTransport != "" { if c.Target.OpenOCDTransport != "" {
transport := c.Target.OpenOCDTransport transport := c.Target.OpenOCDTransport
if transport == "swd" { if transport == "swd" {
@@ -491,9 +499,6 @@ func (c *Config) OpenOCDConfiguration() (args []string, err error) {
args = append(args, "-c", "transport select "+transport) args = append(args, "-c", "transport select "+transport)
} }
args = append(args, "-f", "target/"+c.Target.OpenOCDTarget+".cfg") args = append(args, "-f", "target/"+c.Target.OpenOCDTarget+".cfg")
for _, cmd := range c.Target.OpenOCDCommands {
args = append(args, "-c", cmd)
}
return args, nil return args, nil
} }
+4 -4
View File
@@ -26,7 +26,7 @@ type TargetSpec struct {
Inherits []string `json:"inherits,omitempty"` Inherits []string `json:"inherits,omitempty"`
Triple string `json:"llvm-target,omitempty"` Triple string `json:"llvm-target,omitempty"`
CPU string `json:"cpu,omitempty"` CPU string `json:"cpu,omitempty"`
ABI string `json:"target-abi,omitempty"` // roughly equivalent to -mabi= flag ABI string `json:"target-abi,omitempty"` // rougly equivalent to -mabi= flag
Features string `json:"features,omitempty"` Features string `json:"features,omitempty"`
GOOS string `json:"goos,omitempty"` GOOS string `json:"goos,omitempty"`
GOARCH string `json:"goarch,omitempty"` GOARCH string `json:"goarch,omitempty"`
@@ -319,11 +319,11 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
case "arm64": case "arm64":
spec.CPU = "generic" spec.CPU = "generic"
if goos == "darwin" { if goos == "darwin" {
spec.Features = "+fp-armv8,+neon" spec.Features = "+neon"
} else if goos == "windows" { } else if goos == "windows" {
spec.Features = "+fp-armv8,+neon,-fmv" spec.Features = "+neon,-fmv"
} else { // linux } else { // linux
spec.Features = "+fp-armv8,+neon,-fmv,-outline-atomics" spec.Features = "+neon,-fmv,-outline-atomics"
} }
case "wasm": case "wasm":
spec.CPU = "generic" spec.CPU = "generic"
+2 -6
View File
@@ -16,18 +16,14 @@ import "tinygo.org/x/go-llvm"
var stdlibAliases = map[string]string{ var stdlibAliases = map[string]string{
// crypto packages // crypto packages
"crypto/ed25519/internal/edwards25519/field.feMul": "crypto/ed25519/internal/edwards25519/field.feMulGeneric", "crypto/ed25519/internal/edwards25519/field.feMul": "crypto/ed25519/internal/edwards25519/field.feMulGeneric",
"crypto/internal/edwards25519/field.feSquare": "crypto/ed25519/internal/edwards25519/field.feSquareGeneric", "crypto/ed25519/internal/edwards25519/field.feSquare": "crypto/ed25519/internal/edwards25519/field.feSquareGeneric",
"crypto/md5.block": "crypto/md5.blockGeneric", "crypto/md5.block": "crypto/md5.blockGeneric",
"crypto/sha1.block": "crypto/sha1.blockGeneric", "crypto/sha1.block": "crypto/sha1.blockGeneric",
"crypto/sha1.blockAMD64": "crypto/sha1.blockGeneric", "crypto/sha1.blockAMD64": "crypto/sha1.blockGeneric",
"crypto/sha256.block": "crypto/sha256.blockGeneric", "crypto/sha256.block": "crypto/sha256.blockGeneric",
"crypto/sha512.blockAMD64": "crypto/sha512.blockGeneric", "crypto/sha512.blockAMD64": "crypto/sha512.blockGeneric",
// AES
"crypto/aes.decryptBlockAsm": "crypto/aes.decryptBlock",
"crypto/aes.encryptBlockAsm": "crypto/aes.encryptBlock",
// math package // math package
"math.archHypot": "math.hypot", "math.archHypot": "math.hypot",
"math.archMax": "math.max", "math.archMax": "math.max",
+2 -2
View File
@@ -135,7 +135,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value,
// Calculate (^uintptr(0)) >> 1, which is the max value that fits in an // Calculate (^uintptr(0)) >> 1, which is the max value that fits in an
// uintptr if uintptrs were signed. // uintptr if uintptrs were signed.
maxBufSize := b.CreateLShr(llvm.ConstNot(llvm.ConstInt(b.uintptrType, 0, false)), llvm.ConstInt(b.uintptrType, 1, false), "") maxBufSize := llvm.ConstLShr(llvm.ConstNot(llvm.ConstInt(b.uintptrType, 0, false)), llvm.ConstInt(b.uintptrType, 1, false))
if elementSize > maxBufSize.ZExtValue() { if elementSize > maxBufSize.ZExtValue() {
b.addError(pos, fmt.Sprintf("channel element type is too big (%v bytes)", elementSize)) b.addError(pos, fmt.Sprintf("channel element type is too big (%v bytes)", elementSize))
return return
@@ -150,7 +150,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value,
// Make sure maxBufSize has the same type as bufSize. // Make sure maxBufSize has the same type as bufSize.
if maxBufSize.Type() != bufSize.Type() { if maxBufSize.Type() != bufSize.Type() {
maxBufSize = b.CreateZExt(maxBufSize, bufSize.Type(), "") maxBufSize = llvm.ConstZExt(maxBufSize, bufSize.Type())
} }
// Do the check for a too large (or negative) buffer size. // Do the check for a too large (or negative) buffer size.
+2 -10
View File
@@ -56,7 +56,6 @@ type Config struct {
MaxStackAlloc uint64 MaxStackAlloc uint64
NeedsStackObjects bool NeedsStackObjects bool
Debug bool // Whether to emit debug information in the LLVM module. Debug bool // Whether to emit debug information in the LLVM module.
PanicStrategy string
} }
// compilerContext contains function-independent data that should still be // compilerContext contains function-independent data that should still be
@@ -1856,13 +1855,6 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
supportsRecover = 1 supportsRecover = 1
} }
return llvm.ConstInt(b.ctx.Int1Type(), supportsRecover, false), nil return llvm.ConstInt(b.ctx.Int1Type(), supportsRecover, false), nil
case name == "runtime.panicStrategy":
// These constants are defined in src/runtime/panic.go.
panicStrategy := map[string]uint64{
"print": 1, // panicStrategyPrint
"trap": 2, // panicStrategyTrap
}[b.Config.PanicStrategy]
return llvm.ConstInt(b.ctx.Int8Type(), panicStrategy, false), nil
case name == "runtime/interrupt.New": case name == "runtime/interrupt.New":
return b.createInterruptGlobal(instr) return b.createInterruptGlobal(instr)
} }
@@ -2181,7 +2173,7 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) {
return llvm.Value{}, b.makeError(expr.Pos(), "todo: indexaddr: "+ptrTyp.String()) return llvm.Value{}, b.makeError(expr.Pos(), "todo: indexaddr: "+ptrTyp.String())
} }
// Make sure index is at least the size of uintptr because getelementptr // Make sure index is at least the size of uintptr becuase getelementptr
// assumes index is a signed integer. // assumes index is a signed integer.
index = b.extendInteger(index, expr.Index.Type(), b.uintptrType) index = b.extendInteger(index, expr.Index.Type(), b.uintptrType)
@@ -2557,7 +2549,7 @@ func (b *builder) createBinOp(op token.Token, typ, ytyp types.Type, x, y llvm.Va
sizeY := b.targetData.TypeAllocSize(y.Type()) sizeY := b.targetData.TypeAllocSize(y.Type())
// Check if the shift is bigger than the bit-width of the shifted value. // Check if the shift is bigger than the bit-width of the shifted value.
// This is UB in LLVM, so it needs to be handled separately. // This is UB in LLVM, so it needs to be handled seperately.
// The Go spec indirectly defines the result as 0. // The Go spec indirectly defines the result as 0.
// Negative shifts are handled earlier, so we can treat y as unsigned. // Negative shifts are handled earlier, so we can treat y as unsigned.
overshifted := b.CreateICmp(llvm.IntUGE, y, llvm.ConstInt(y.Type(), 8*sizeX, false), "shift.overflow") overshifted := b.CreateICmp(llvm.IntUGE, y, llvm.ConstInt(y.Type(), 8*sizeX, false), "shift.overflow")
+6 -9
View File
@@ -124,19 +124,16 @@ func (c *compilerContext) pkgPathPtr(pkgpath string) llvm.Value {
func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value { func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
ms := c.program.MethodSets.MethodSet(typ) ms := c.program.MethodSets.MethodSet(typ)
hasMethodSet := ms.Len() != 0 hasMethodSet := ms.Len() != 0
_, isInterface := typ.Underlying().(*types.Interface) if _, ok := typ.Underlying().(*types.Interface); ok {
if isInterface {
hasMethodSet = false hasMethodSet = false
} }
// As defined in https://pkg.go.dev/reflect#Type:
// NumMethod returns the number of methods accessible using Method.
// For a non-interface type, it returns the number of exported methods.
// For an interface type, it returns the number of exported and unexported methods.
var numMethods int var numMethods int
for i := 0; i < ms.Len(); i++ { if hasMethodSet {
if isInterface || ms.At(i).Obj().Exported() { for i := 0; i < ms.Len(); i++ {
numMethods++ if ms.At(i).Obj().Exported() {
numMethods++
}
} }
} }
-10
View File
@@ -23,8 +23,6 @@ func (b *builder) defineIntrinsicFunction() {
b.createMemoryCopyImpl() b.createMemoryCopyImpl()
case name == "runtime.memzero": case name == "runtime.memzero":
b.createMemoryZeroImpl() b.createMemoryZeroImpl()
case name == "runtime.stacksave":
b.createStackSaveImpl()
case name == "runtime.KeepAlive": case name == "runtime.KeepAlive":
b.createKeepAliveImpl() b.createKeepAliveImpl()
case strings.HasPrefix(name, "runtime/volatile.Load"): case strings.HasPrefix(name, "runtime/volatile.Load"):
@@ -79,14 +77,6 @@ func (b *builder) createMemoryZeroImpl() {
b.CreateRetVoid() b.CreateRetVoid()
} }
// createStackSaveImpl creates a call to llvm.stacksave.p0 to read the current
// stack pointer.
func (b *builder) createStackSaveImpl() {
b.createFunctionStart(true)
sp := b.readStackPointer()
b.CreateRet(sp)
}
// Return the llvm.memset.p0.i8 function declaration. // Return the llvm.memset.p0.i8 function declaration.
func (c *compilerContext) getMemsetFunc() llvm.Value { func (c *compilerContext) getMemsetFunc() llvm.Value {
fnName := "llvm.memset.p0.i" + strconv.Itoa(c.uintptrType.IntTypeWidth()) fnName := "llvm.memset.p0.i" + strconv.Itoa(c.uintptrType.IntTypeWidth())
+2 -6
View File
@@ -451,14 +451,10 @@ func (c *compilerContext) isThumb() bool {
// readStackPointer emits a LLVM intrinsic call that returns the current stack // readStackPointer emits a LLVM intrinsic call that returns the current stack
// pointer as an *i8. // pointer as an *i8.
func (b *builder) readStackPointer() llvm.Value { func (b *builder) readStackPointer() llvm.Value {
name := "llvm.stacksave.p0" stacksave := b.mod.NamedFunction("llvm.stacksave")
if llvmutil.Version() < 18 {
name = "llvm.stacksave" // backwards compatibility with LLVM 17 and below
}
stacksave := b.mod.NamedFunction(name)
if stacksave.IsNil() { if stacksave.IsNil() {
fnType := llvm.FunctionType(b.dataPtrType, nil, false) fnType := llvm.FunctionType(b.dataPtrType, nil, false)
stacksave = llvm.AddFunction(b.mod, name, fnType) stacksave = llvm.AddFunction(b.mod, "llvm.stacksave", fnType)
} }
return b.CreateCall(stacksave.GlobalValueType(), stacksave, nil, "") return b.CreateCall(stacksave.GlobalValueType(), stacksave, nil, "")
} }
+3 -16
View File
@@ -1,5 +1,5 @@
// Package llvmutil contains utility functions used across multiple compiler // Package llvmutil contains utility functions used across multiple compiler
// packages. For example, they may be used by both the compiler package and // packages. For example, they may be used by both the compiler pacakge and
// transformation packages. // transformation packages.
// //
// Normally, utility packages are avoided. However, in this case, the utility // Normally, utility packages are avoided. However, in this case, the utility
@@ -8,9 +8,6 @@
package llvmutil package llvmutil
import ( import (
"strconv"
"strings"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
@@ -31,7 +28,7 @@ func CreateEntryBlockAlloca(builder llvm.Builder, t llvm.Type, name string) llvm
} }
// CreateTemporaryAlloca creates a new alloca in the entry block and adds // CreateTemporaryAlloca creates a new alloca in the entry block and adds
// lifetime start information in the IR signalling that the alloca won't be used // lifetime start infromation in the IR signalling that the alloca won't be used
// before this point. // before this point.
// //
// This is useful for creating temporary allocas for intrinsics. Don't forget to // This is useful for creating temporary allocas for intrinsics. Don't forget to
@@ -176,7 +173,7 @@ func SplitBasicBlock(builder llvm.Builder, afterInst llvm.Value, insertAfter llv
return newBlock return newBlock
} }
// AppendToGlobal appends the given values to a global array like llvm.used. The global might // Append the given values to a global array like llvm.used. The global might
// not exist yet. The values can be any pointer type, they will be cast to i8*. // not exist yet. The values can be any pointer type, they will be cast to i8*.
func AppendToGlobal(mod llvm.Module, globalName string, values ...llvm.Value) { func AppendToGlobal(mod llvm.Module, globalName string, values ...llvm.Value) {
// Read the existing values in the llvm.used array (if it exists). // Read the existing values in the llvm.used array (if it exists).
@@ -206,13 +203,3 @@ func AppendToGlobal(mod llvm.Module, globalName string, values ...llvm.Value) {
used.SetInitializer(usedInitializer) used.SetInitializer(usedInitializer)
used.SetLinkage(llvm.AppendingLinkage) used.SetLinkage(llvm.AppendingLinkage)
} }
// Return the LLVM major version.
func Version() int {
majorStr := strings.Split(llvm.Version, ".")[0]
major, err := strconv.Atoi(majorStr)
if err != nil {
panic("unexpected error while parsing LLVM version: " + err.Error()) // should not happen
}
return major
}
+2 -2
View File
@@ -81,11 +81,11 @@ entry:
%select.send.value = alloca i32, align 4 %select.send.value = alloca i32, align 4
store i32 1, ptr %select.send.value, align 4 store i32 1, ptr %select.send.value, align 4
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %select.states.alloca) call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %select.states.alloca)
store ptr %ch1, ptr %select.states.alloca, align 4 store ptr %ch1, ptr %select.states.alloca, align 8
%select.states.alloca.repack1 = getelementptr inbounds %runtime.chanSelectState, ptr %select.states.alloca, i32 0, i32 1 %select.states.alloca.repack1 = getelementptr inbounds %runtime.chanSelectState, ptr %select.states.alloca, i32 0, i32 1
store ptr %select.send.value, ptr %select.states.alloca.repack1, align 4 store ptr %select.send.value, ptr %select.states.alloca.repack1, align 4
%0 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1 %0 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1
store ptr %ch2, ptr %0, align 4 store ptr %ch2, ptr %0, align 8
%.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1, i32 1 %.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1, i32 1
store ptr null, ptr %.repack3, align 4 store ptr null, ptr %.repack3, align 4
%select.result = call { i32, i1 } @runtime.tryChanSelect(ptr undef, ptr nonnull %select.states.alloca, i32 2, i32 2, ptr undef) #4 %select.result = call { i32, i1 } @runtime.tryChanSelect(ptr undef, ptr nonnull %select.states.alloca, i32 2, i32 2, ptr undef) #4
+3 -3
View File
@@ -25,7 +25,7 @@ entry:
%deferPtr = alloca ptr, align 4 %deferPtr = alloca ptr, align 4
store ptr null, ptr %deferPtr, align 4 store ptr null, ptr %deferPtr, align 4
%deferframe.buf = alloca %runtime.deferFrame, align 4 %deferframe.buf = alloca %runtime.deferFrame, align 4
%0 = call ptr @llvm.stacksave.p0() %0 = call ptr @llvm.stacksave()
call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #4 call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #4
store i32 0, ptr %defer.alloca, align 4 store i32 0, ptr %defer.alloca, align 4
%defer.alloca.repack15 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1 %defer.alloca.repack15 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1
@@ -113,7 +113,7 @@ rundefers.end3: ; preds = %rundefers.loophead6
} }
; Function Attrs: nocallback nofree nosync nounwind willreturn ; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3 declare ptr @llvm.stacksave() #3
declare void @runtime.setupDeferFrame(ptr dereferenceable_or_null(24), ptr, ptr) #2 declare void @runtime.setupDeferFrame(ptr dereferenceable_or_null(24), ptr, ptr) #2
@@ -136,7 +136,7 @@ entry:
%deferPtr = alloca ptr, align 4 %deferPtr = alloca ptr, align 4
store ptr null, ptr %deferPtr, align 4 store ptr null, ptr %deferPtr, align 4
%deferframe.buf = alloca %runtime.deferFrame, align 4 %deferframe.buf = alloca %runtime.deferFrame, align 4
%0 = call ptr @llvm.stacksave.p0() %0 = call ptr @llvm.stacksave()
call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #4 call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #4
store i32 0, ptr %defer.alloca, align 4 store i32 0, ptr %defer.alloca, align 4
%defer.alloca.repack22 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1 %defer.alloca.repack22 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1
+9 -9
View File
@@ -16,9 +16,9 @@ target triple = "wasm32-unknown-wasi"
@main.struct2 = hidden global ptr null, align 4 @main.struct2 = hidden global ptr null, align 4
@main.struct3 = hidden global ptr null, align 4 @main.struct3 = hidden global ptr null, align 4
@main.struct4 = hidden global ptr null, align 4 @main.struct4 = hidden global ptr null, align 4
@main.slice1 = hidden global { ptr, i32, i32 } zeroinitializer, align 4 @main.slice1 = hidden global { ptr, i32, i32 } zeroinitializer, align 8
@main.slice2 = hidden global { ptr, i32, i32 } zeroinitializer, align 4 @main.slice2 = hidden global { ptr, i32, i32 } zeroinitializer, align 8
@main.slice3 = hidden global { ptr, i32, i32 } zeroinitializer, align 4 @main.slice3 = hidden global { ptr, i32, i32 } zeroinitializer, align 8
@"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00 " } @"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00 " }
@"runtime/gc.layout:62-0001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00\00" } @"runtime/gc.layout:62-0001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00\00" }
@"reflect/types.type:basic:complex128" = linkonce_odr constant { i8, ptr } { i8 80, ptr @"reflect/types.type:pointer:basic:complex128" }, align 4 @"reflect/types.type:basic:complex128" = linkonce_odr constant { i8, ptr } { i8 80, ptr @"reflect/types.type:pointer:basic:complex128" }, align 4
@@ -104,19 +104,19 @@ entry:
%stackalloc = alloca i8, align 1 %stackalloc = alloca i8, align 1
%makeslice = call dereferenceable(5) ptr @runtime.alloc(i32 5, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 %makeslice = call dereferenceable(5) ptr @runtime.alloc(i32 5, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3
call void @runtime.trackPointer(ptr nonnull %makeslice, ptr nonnull %stackalloc, ptr undef) #3 call void @runtime.trackPointer(ptr nonnull %makeslice, ptr nonnull %stackalloc, ptr undef) #3
store ptr %makeslice, ptr @main.slice1, align 4 store ptr %makeslice, ptr @main.slice1, align 8
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 1), align 4 store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 1), align 4
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 2), align 4 store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 2), align 8
%makeslice1 = call dereferenceable(20) ptr @runtime.alloc(i32 20, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #3 %makeslice1 = call dereferenceable(20) ptr @runtime.alloc(i32 20, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #3
call void @runtime.trackPointer(ptr nonnull %makeslice1, ptr nonnull %stackalloc, ptr undef) #3 call void @runtime.trackPointer(ptr nonnull %makeslice1, ptr nonnull %stackalloc, ptr undef) #3
store ptr %makeslice1, ptr @main.slice2, align 4 store ptr %makeslice1, ptr @main.slice2, align 8
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 1), align 4 store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 1), align 4
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 2), align 4 store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 2), align 8
%makeslice3 = call dereferenceable(60) ptr @runtime.alloc(i32 60, ptr nonnull inttoptr (i32 71 to ptr), ptr undef) #3 %makeslice3 = call dereferenceable(60) ptr @runtime.alloc(i32 60, ptr nonnull inttoptr (i32 71 to ptr), ptr undef) #3
call void @runtime.trackPointer(ptr nonnull %makeslice3, ptr nonnull %stackalloc, ptr undef) #3 call void @runtime.trackPointer(ptr nonnull %makeslice3, ptr nonnull %stackalloc, ptr undef) #3
store ptr %makeslice3, ptr @main.slice3, align 4 store ptr %makeslice3, ptr @main.slice3, align 8
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 1), align 4 store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 1), align 4
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 2), align 4 store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 2), align 8
ret void ret void
} }
+1 -1
View File
@@ -9,7 +9,7 @@ target triple = "wasm32-unknown-wasi"
@"reflect/types.type:basic:int" = linkonce_odr constant { i8, ptr } { i8 -62, ptr @"reflect/types.type:pointer:basic:int" }, align 4 @"reflect/types.type:basic:int" = linkonce_odr constant { i8, ptr } { i8 -62, ptr @"reflect/types.type:pointer:basic:int" }, align 4
@"reflect/types.type:pointer:basic:int" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:basic:int" }, align 4 @"reflect/types.type:pointer:basic:int" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:basic:int" }, align 4
@"reflect/types.type:pointer:named:error" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:named:error" }, align 4 @"reflect/types.type:pointer:named:error" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:named:error" }, align 4
@"reflect/types.type:named:error" = linkonce_odr constant { i8, i16, ptr, ptr, ptr, [7 x i8] } { i8 116, i16 1, ptr @"reflect/types.type:pointer:named:error", ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", ptr @"reflect/types.type.pkgpath.empty", [7 x i8] c".error\00" }, align 4 @"reflect/types.type:named:error" = linkonce_odr constant { i8, i16, ptr, ptr, ptr, [7 x i8] } { i8 116, i16 0, ptr @"reflect/types.type:pointer:named:error", ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", ptr @"reflect/types.type.pkgpath.empty", [7 x i8] c".error\00" }, align 4
@"reflect/types.type.pkgpath.empty" = linkonce_odr unnamed_addr constant [1 x i8] zeroinitializer, align 1 @"reflect/types.type.pkgpath.empty" = linkonce_odr unnamed_addr constant [1 x i8] zeroinitializer, align 1
@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant { i8, ptr } { i8 84, ptr @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" }, align 4 @"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant { i8, ptr } { i8 84, ptr @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" }, align 4
@"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}" }, align 4 @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}" }, align 4
+2 -2
View File
@@ -122,7 +122,7 @@ entry:
br i1 %slice.maxcap, label %slice.throw, label %slice.next br i1 %slice.maxcap, label %slice.throw, label %slice.next
slice.next: ; preds = %entry slice.next: ; preds = %entry
%makeslice.cap = shl nuw i32 %len, 1 %makeslice.cap = shl i32 %len, 1
%makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3
%0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0
%1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1
@@ -164,7 +164,7 @@ entry:
br i1 %slice.maxcap, label %slice.throw, label %slice.next br i1 %slice.maxcap, label %slice.throw, label %slice.next
slice.next: ; preds = %entry slice.next: ; preds = %entry
%makeslice.cap = shl nuw i32 %len, 2 %makeslice.cap = shl i32 %len, 2
%makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3
%0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0
%1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1
+4 -4
View File
@@ -26,7 +26,7 @@ entry:
%2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2 %2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key) call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key)
store %main.hasPadding %2, ptr %hashmap.key, align 4 store %main.hasPadding %2, ptr %hashmap.key, align 8
%3 = getelementptr inbounds i8, ptr %hashmap.key, i32 1 %3 = getelementptr inbounds i8, ptr %hashmap.key, i32 1
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #5 call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #5
%4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9 %4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
@@ -59,7 +59,7 @@ entry:
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
store i32 5, ptr %hashmap.value, align 4 store i32 5, ptr %hashmap.value, align 4
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key) call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key)
store %main.hasPadding %2, ptr %hashmap.key, align 4 store %main.hasPadding %2, ptr %hashmap.key, align 8
%3 = getelementptr inbounds i8, ptr %hashmap.key, i32 1 %3 = getelementptr inbounds i8, ptr %hashmap.key, i32 1
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #5 call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #5
%4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9 %4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
@@ -80,7 +80,7 @@ entry:
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value) call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key) call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key)
%s.elt = extractvalue [2 x %main.hasPadding] %s, 0 %s.elt = extractvalue [2 x %main.hasPadding] %s, 0
store %main.hasPadding %s.elt, ptr %hashmap.key, align 4 store %main.hasPadding %s.elt, ptr %hashmap.key, align 8
%hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 %hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1
%s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1 %s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1
store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4 store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4
@@ -108,7 +108,7 @@ entry:
store i32 5, ptr %hashmap.value, align 4 store i32 5, ptr %hashmap.value, align 4
call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key) call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key)
%s.elt = extractvalue [2 x %main.hasPadding] %s, 0 %s.elt = extractvalue [2 x %main.hasPadding] %s, 0
store %main.hasPadding %s.elt, ptr %hashmap.key, align 4 store %main.hasPadding %s.elt, ptr %hashmap.key, align 8
%hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1 %hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1
%s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1 %s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1
store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4 store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4
+2 -3
View File
@@ -51,7 +51,6 @@ func TestCorpus(t *testing.T) {
if *testTarget != "" { if *testTarget != "" {
target = *testTarget target = *testTarget
} }
isWASI := strings.HasPrefix(target, "wasi")
repos, err := loadRepos(*corpus) repos, err := loadRepos(*corpus)
if err != nil { if err != nil {
@@ -70,7 +69,7 @@ func TestCorpus(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
t.Parallel() t.Parallel()
if isWASI && repo.SkipWASI { if target == "wasi" && repo.SkipWASI {
t.Skip("skip wasi") t.Skip("skip wasi")
} }
if repo.Slow && testing.Short() { if repo.Slow && testing.Short() {
@@ -136,7 +135,7 @@ func TestCorpus(t *testing.T) {
t.Run(dir.Pkg, func(t *testing.T) { t.Run(dir.Pkg, func(t *testing.T) {
t.Parallel() t.Parallel()
if isWASI && dir.SkipWASI { if target == "wasi" && dir.SkipWASI {
t.Skip("skip wasi") t.Skip("skip wasi")
} }
if dir.Slow && testing.Short() { if dir.Slow && testing.Short() {
+6 -5
View File
@@ -18,10 +18,10 @@
# #
# But you'll need a bit more to make TinyGo actually able to compile code: # But you'll need a bit more to make TinyGo actually able to compile code:
# #
# make llvm-source # fetch compiler-rt # make llvm-source # fetch compiler-rt
# git submodule update --init # fetch lots of other libraries and SVD files # git submodule update --init --recursive # fetch lots of other libraries and SVD files
# make gen-device -j4 # build src/device/*/*.go files # make gen-device -j4 # build src/device/*/*.go files
# make wasi-libc # build support for wasi/wasm # make wasi-libc # build support for wasi/wasm
# #
# With this, you should have an environment that can compile anything - except # With this, you should have an environment that can compile anything - except
# for the Xtensa architecture (ESP8266/ESP32) because support for that lives in # for the Xtensa architecture (ESP8266/ESP32) because support for that lives in
@@ -51,6 +51,7 @@
go go
llvmPackages_17.llvm llvmPackages_17.llvm
llvmPackages_17.libclang llvmPackages_17.libclang
llvmPackages_17.libcxx
# Additional dependencies needed at runtime, for building and/or # Additional dependencies needed at runtime, for building and/or
# flashing. # flashing.
llvmPackages_17.lld llvmPackages_17.lld
@@ -77,7 +78,7 @@
export MD5SUM=md5sum export MD5SUM=md5sum
# Ugly hack to make the Clang resources directory available. # Ugly hack to make the Clang resources directory available.
export GOFLAGS="\"-ldflags=-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${llvmPackages_17.clang.cc.lib}/lib/clang/17\" -tags=llvm17" export GOFLAGS="\"-ldflags=-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${llvmPackages_17.clang.cc.lib}/lib/clang/17"\"
''; '';
}; };
} }
+4 -16
View File
@@ -3,45 +3,33 @@ module github.com/tinygo-org/tinygo
go 1.18 go 1.18
require ( require (
github.com/aykevl/go-wasm v0.0.2-0.20240312204833-50275154210c github.com/aykevl/go-wasm v0.0.2-0.20220616010729-4a0a888aebdc
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee
github.com/chromedp/chromedp v0.7.6 github.com/chromedp/chromedp v0.7.6
github.com/client9/misspell v0.3.4
github.com/gofrs/flock v0.8.1 github.com/gofrs/flock v0.8.1
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892
github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-tty v0.0.4 github.com/mattn/go-tty v0.0.4
github.com/mgechev/revive v1.3.7
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3
go.bug.st/serial v1.6.0 go.bug.st/serial v1.6.0
golang.org/x/net v0.20.0 golang.org/x/net v0.20.0
golang.org/x/sys v0.16.0 golang.org/x/sys v0.16.0
golang.org/x/tools v0.17.0 golang.org/x/tools v0.17.0
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
tinygo.org/x/go-llvm v0.0.0-20240518103902-697964f2a9dc tinygo.org/x/go-llvm v0.0.0-20240106122909-c2c543540318
) )
require ( require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/chavacava/garif v0.1.0 // indirect
github.com/chromedp/sysutil v1.0.0 // indirect github.com/chromedp/sysutil v1.0.0 // indirect
github.com/creack/goselect v0.1.2 // indirect github.com/creack/goselect v0.1.2 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.1.0 // indirect github.com/gobwas/ws v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect
) )
+13 -49
View File
@@ -1,11 +1,7 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/aykevl/go-wasm v0.0.2-0.20220616010729-4a0a888aebdc h1:Yp49g+qqgQRPk/gcRSmAsXgnT16XPJ6Y5JM1poc6gYM=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/aykevl/go-wasm v0.0.2-0.20220616010729-4a0a888aebdc/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw=
github.com/aykevl/go-wasm v0.0.2-0.20240312204833-50275154210c h1:4T0Vj1UkGgcpkRrmn7SbokebnlfxJcMZPgWtOYACAAA=
github.com/aykevl/go-wasm v0.0.2-0.20240312204833-50275154210c/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw=
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI= github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI=
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI= github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc=
github.com/chavacava/garif v0.1.0/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+UIPD+Gww=
github.com/chromedp/cdproto v0.0.0-20211126220118-81fa0469ad77/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U= github.com/chromedp/cdproto v0.0.0-20211126220118-81fa0469ad77/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee h1:+SFdIVfQpG0s0DHYzou0kgfE0n0ZjKPwbiRJsXrZegU= github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee h1:+SFdIVfQpG0s0DHYzou0kgfE0n0ZjKPwbiRJsXrZegU=
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U= github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
@@ -13,17 +9,9 @@ github.com/chromedp/chromedp v0.7.6 h1:2juGaktzjwULlsn+DnvIZXFUckEp5xs+GOBroaea+
github.com/chromedp/chromedp v0.7.6/go.mod h1:ayT4YU/MGAALNfOg9gNrpGSAdnU51PMx+FCeuT1iXzo= github.com/chromedp/chromedp v0.7.6/go.mod h1:ayT4YU/MGAALNfOg9gNrpGSAdnU51PMx+FCeuT1iXzo=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
@@ -43,43 +31,21 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 h1:6J+qramlHVLmiBOgRiBOnQkno8uprqG6YFFQTt6uYIw= github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 h1:6J+qramlHVLmiBOgRiBOnQkno8uprqG6YFFQTt6uYIw=
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M= github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E= github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E=
github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28= github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28=
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 h1:zpIH83+oKzcpryru8ceC6BxnoG8TBrhgAvRg8obzup0=
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg=
github.com/mgechev/revive v1.3.7 h1:502QY0vQGe9KtYJ9FpxMz9rL+Fc/P13CI5POL4uHCcE=
github.com/mgechev/revive v1.3.7/go.mod h1:RJ16jUbF0OWC3co/+XTxmFNgEpUPwnnA0BRllX2aDNA=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/orisano/pixelmatch v0.0.0-20210112091706-4fa4c7ba91d5 h1:1SoBaSPudixRecmlHXb/GxmaD3fLMtHIDN13QujwQuc= github.com/orisano/pixelmatch v0.0.0-20210112091706-4fa4c7ba91d5 h1:1SoBaSPudixRecmlHXb/GxmaD3fLMtHIDN13QujwQuc=
github.com/orisano/pixelmatch v0.0.0-20210112091706-4fa4c7ba91d5/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= github.com/orisano/pixelmatch v0.0.0-20210112091706-4fa4c7ba91d5/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs= github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9BJsJMWg1wpLbfuSnkm8dPF6FdW2JXVhA= github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9BJsJMWg1wpLbfuSnkm8dPF6FdW2JXVhA=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.bug.st/serial v1.6.0 h1:mAbRGN4cKE2J5gMwsMHC2KQisdLRQssO9WSM+rbZJ8A= go.bug.st/serial v1.6.0 h1:mAbRGN4cKE2J5gMwsMHC2KQisdLRQssO9WSM+rbZJ8A=
go.bug.st/serial v1.6.0/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= go.bug.st/serial v1.6.0/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
@@ -88,10 +54,10 @@ golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
@@ -102,8 +68,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= tinygo.org/x/go-llvm v0.0.0-20240106122909-c2c543540318 h1:4KjZvPtcN1UwobevcGbdzeinx0L1i8HDdJu84bu7NI8=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= tinygo.org/x/go-llvm v0.0.0-20240106122909-c2c543540318/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
tinygo.org/x/go-llvm v0.0.0-20240518103902-697964f2a9dc h1:TCzibFa4oLu+njEP3fnRUmZ+QQeb8BjtOwctgcjzL0k=
tinygo.org/x/go-llvm v0.0.0-20240518103902-697964f2a9dc/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
+5 -2
View File
@@ -142,8 +142,11 @@ func Get(name string) string {
} }
return filepath.Join(dir, "tinygo") return filepath.Join(dir, "tinygo")
case "CGO_ENABLED": case "CGO_ENABLED":
// Always enable CGo. It is required by a number of targets, including val := os.Getenv("CGO_ENABLED")
// macOS and the rp2040. if val == "1" || val == "0" {
return val
}
// Default to enabling CGo.
return "1" return "1"
case "TINYGOROOT": case "TINYGOROOT":
return sourceDir() return sourceDir()
+1 -1
View File
@@ -9,7 +9,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.32.0-dev" const version = "0.31.0-dev"
var ( var (
// This variable is set at build time using -ldflags parameters. // This variable is set at build time using -ldflags parameters.
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
# Docker hub does a recursive clone, then checks the branch out, # Docker hub does a recursive clone, then checks the branch out,
# so when a PR adds a submodule (or updates it), it fails. # so when a PR adds a submodule (or updates it), it fails.
git submodule update --init git submodule update --init --recursive
-10
View File
@@ -1,10 +0,0 @@
//go:build tools
// Install linter versions specified in go.mod
// See https://marcofranssen.nl/manage-go-tools-via-go-modules for idom
package tools
import (
_ "github.com/client9/misspell"
_ "github.com/mgechev/revive"
)
+10 -38
View File
@@ -239,8 +239,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// already be emitted in initAll. // already be emitted in initAll.
continue continue
case strings.HasPrefix(callFn.name, "runtime.print") || callFn.name == "runtime._panic" || callFn.name == "runtime.hashmapGet" || callFn.name == "runtime.hashmapInterfaceHash" || case strings.HasPrefix(callFn.name, "runtime.print") || callFn.name == "runtime._panic" || callFn.name == "runtime.hashmapGet" || callFn.name == "runtime.hashmapInterfaceHash" ||
callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current" || callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current":
callFn.name == "time.startTimer" || callFn.name == "time.stopTimer" || callFn.name == "time.resetTimer":
// These functions should be run at runtime. Specifically: // These functions should be run at runtime. Specifically:
// * Print and panic functions are best emitted directly without // * Print and panic functions are best emitted directly without
// interpreting them, otherwise we get a ton of putchar (etc.) // interpreting them, otherwise we get a ton of putchar (etc.)
@@ -253,8 +252,6 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// at runtime. // at runtime.
// * internal/task.start, internal/task.Current: start and read shcheduler state, // * internal/task.start, internal/task.Current: start and read shcheduler state,
// which is modified elsewhere. // which is modified elsewhere.
// * Timer functions access runtime internal state which may
// not be initialized.
err := r.runAtRuntime(fn, inst, locals, &mem, indent) err := r.runAtRuntime(fn, inst, locals, &mem, indent)
if err != nil { if err != nil {
return nil, mem, err return nil, mem, err
@@ -427,22 +424,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
if err != nil { if err != nil {
return nil, mem, r.errorAt(inst, err) return nil, mem, r.errorAt(inst, err)
} }
// typecodePtr always point to the numMethod field in the type methodSetPtr, err := mem.load(typecodePtr.addOffset(-int64(r.pointerSize)), r.pointerSize).asPointer(r)
// description struct. The methodSet, when present, comes right
// before the numMethod field (the compiler doesn't generate
// method sets for concrete types without methods).
// Considering that the compiler doesn't emit interface type
// asserts for interfaces with no methods (as the always succeed)
// then if the offset is zero, this assert must always fail.
if typecodePtr.offset() == 0 {
locals[inst.localIndex] = literalValue{uint8(0)}
break
}
typecodePtrOffset, err := typecodePtr.addOffset(-int64(r.pointerSize))
if err != nil {
return nil, mem, r.errorAt(inst, err)
}
methodSetPtr, err := mem.load(typecodePtrOffset, r.pointerSize).asPointer(r)
if err != nil { if err != nil {
return nil, mem, r.errorAt(inst, err) return nil, mem, r.errorAt(inst, err)
} }
@@ -488,11 +470,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
if err != nil { if err != nil {
return nil, mem, r.errorAt(inst, err) return nil, mem, r.errorAt(inst, err)
} }
typecodePtrOffset, err := typecodePtr.addOffset(-int64(r.pointerSize)) methodSetPtr, err := mem.load(typecodePtr.addOffset(-int64(r.pointerSize)), r.pointerSize).asPointer(r)
if err != nil {
return nil, mem, r.errorAt(inst, err)
}
methodSetPtr, err := mem.load(typecodePtrOffset, r.pointerSize).asPointer(r)
if err != nil { if err != nil {
return nil, mem, r.errorAt(inst, err) return nil, mem, r.errorAt(inst, err)
} }
@@ -655,11 +633,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
case llvm.GetElementPtr: case llvm.GetElementPtr:
// GetElementPtr does pointer arithmetic, changing the offset of the // GetElementPtr does pointer arithmetic, changing the offset of the
// pointer into the underlying object. // pointer into the underlying object.
var offset int64 var offset uint64
for i := 1; i < len(operands); i += 2 { for i := 1; i < len(operands); i += 2 {
index := operands[i].Int() index := operands[i].Uint()
elementSize := operands[i+1].Int() elementSize := operands[i+1].Uint()
if elementSize < 0 { if int64(elementSize) < 0 {
// This is a struct field. // This is a struct field.
offset += index offset += index
} else { } else {
@@ -673,14 +651,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
return nil, mem, r.errorAt(inst, err) return nil, mem, r.errorAt(inst, err)
} }
// GEP on fixed pointer value (for example, memory-mapped I/O). // GEP on fixed pointer value (for example, memory-mapped I/O).
ptrValue := operands[0].Uint() + uint64(offset) ptrValue := operands[0].Uint() + offset
locals[inst.localIndex] = makeLiteralInt(ptrValue, int(operands[0].len(r)*8)) locals[inst.localIndex] = makeLiteralInt(ptrValue, int(operands[0].len(r)*8))
continue continue
} }
ptr, err = ptr.addOffset(int64(offset)) ptr = ptr.addOffset(int64(offset))
if err != nil {
return nil, mem, r.errorAt(inst, err)
}
locals[inst.localIndex] = ptr locals[inst.localIndex] = ptr
if r.debug { if r.debug {
fmt.Fprintln(os.Stderr, indent+"gep:", operands, "->", ptr) fmt.Fprintln(os.Stderr, indent+"gep:", operands, "->", ptr)
@@ -778,10 +753,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
if inst.opcode == llvm.Add { if inst.opcode == llvm.Add {
// This likely means this is part of a // This likely means this is part of a
// unsafe.Pointer(uintptr(ptr) + offset) pattern. // unsafe.Pointer(uintptr(ptr) + offset) pattern.
lhsPtr, err = lhsPtr.addOffset(int64(rhs.Uint())) lhsPtr = lhsPtr.addOffset(int64(rhs.Uint()))
if err != nil {
return nil, mem, r.errorAt(inst, err)
}
locals[inst.localIndex] = lhsPtr locals[inst.localIndex] = lhsPtr
} else if inst.opcode == llvm.Xor && rhs.Uint() == 0 { } else if inst.opcode == llvm.Xor && rhs.Uint() == 0 {
// Special workaround for strings.noescape, see // Special workaround for strings.noescape, see
+3 -3
View File
@@ -517,12 +517,12 @@ func (v pointerValue) offset() uint32 {
// addOffset essentially does a GEP operation (pointer arithmetic): it adds the // addOffset essentially does a GEP operation (pointer arithmetic): it adds the
// offset to the pointer. It also checks that the offset doesn't overflow the // offset to the pointer. It also checks that the offset doesn't overflow the
// maximum offset size (which is 4GB). // maximum offset size (which is 4GB).
func (v pointerValue) addOffset(offset int64) (pointerValue, error) { func (v pointerValue) addOffset(offset int64) pointerValue {
result := pointerValue{v.pointer + uint64(offset)} result := pointerValue{v.pointer + uint64(offset)}
if checks && v.index() != result.index() { if checks && v.index() != result.index() {
return result, fmt.Errorf("interp: offset %d out of range for object %v", offset, v) panic("interp: offset out of range")
} }
return result, nil return result
} }
func (v pointerValue) len(r *runner) uint32 { func (v pointerValue) len(r *runner) uint32 {
-7
View File
@@ -10,8 +10,6 @@ target triple = "x86_64--linux"
@main.exposedValue1 = global i16 0 @main.exposedValue1 = global i16 0
@main.exposedValue2 = global i16 0 @main.exposedValue2 = global i16 0
@main.insertedValue = global {i8, i32, {float, {i64, i16}}} zeroinitializer @main.insertedValue = global {i8, i32, {float, {i64, i16}}} zeroinitializer
@main.gepArray = global [8 x i8] zeroinitializer
@main.negativeGEP = global ptr null
declare void @runtime.printint64(i64) unnamed_addr declare void @runtime.printint64(i64) unnamed_addr
@@ -90,11 +88,6 @@ entry:
%agg2 = insertvalue {i8, i32, {float, {i64, i16}}} %agg, i64 5, 2, 1, 0 %agg2 = insertvalue {i8, i32, {float, {i64, i16}}} %agg, i64 5, 2, 1, 0
store {i8, i32, {float, {i64, i16}}} %agg2, ptr @main.insertedValue store {i8, i32, {float, {i64, i16}}} %agg2, ptr @main.insertedValue
; negative GEP instruction
%ngep1 = getelementptr [8 x i8], ptr @main.negativeGEP, i32 0, i32 5
%ngep2 = getelementptr [8 x i8], ptr %ngep1, i32 0, i32 -3
store ptr %ngep2, ptr @main.negativeGEP
ret void ret void
} }
-2
View File
@@ -9,8 +9,6 @@ target triple = "x86_64--linux"
@main.exposedValue1 = global i16 0 @main.exposedValue1 = global i16 0
@main.exposedValue2 = local_unnamed_addr global i16 0 @main.exposedValue2 = local_unnamed_addr global i16 0
@main.insertedValue = local_unnamed_addr global { i8, i32, { float, { i64, i16 } } } zeroinitializer @main.insertedValue = local_unnamed_addr global { i8, i32, { float, { i64, i16 } } } zeroinitializer
@main.gepArray = local_unnamed_addr global [8 x i8] zeroinitializer
@main.negativeGEP = global ptr getelementptr inbounds (i8, ptr @main.negativeGEP, i64 2)
declare void @runtime.printint64(i64) unnamed_addr declare void @runtime.printint64(i64) unnamed_addr
+1 -1
View File
@@ -214,7 +214,7 @@ func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool)
return merges, nil return merges, nil
} }
// needsSyscallPackage returns whether the syscall package should be overridden // needsSyscallPackage returns whether the syscall package should be overriden
// with the TinyGo version. This is the case on some targets. // with the TinyGo version. This is the case on some targets.
func needsSyscallPackage(buildTags []string) bool { func needsSyscallPackage(buildTags []string) bool {
for _, tag := range buildTags { for _, tag := range buildTags {
+5 -1
View File
@@ -22,8 +22,12 @@ func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, erro
args = append(args, "-tags", strings.Join(config.BuildTags(), " ")) args = append(args, "-tags", strings.Join(config.BuildTags(), " "))
} }
args = append(args, pkgs...) args = append(args, pkgs...)
cgoEnabled := "0"
if config.CgoEnabled() {
cgoEnabled = "1"
}
cmd := exec.Command(filepath.Join(goenv.Get("GOROOT"), "bin", "go"), args...) cmd := exec.Command(filepath.Join(goenv.Get("GOROOT"), "bin", "go"), args...)
cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED=1") cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled)
if config.Options.Directory != "" { if config.Options.Directory != "" {
cmd.Dir = config.Options.Directory cmd.Dir = config.Options.Directory
} }
+1 -1
View File
@@ -430,7 +430,7 @@ func (p *Package) parseFiles() ([]*ast.File, error) {
var files []*ast.File var files []*ast.File
var fileErrs []error var fileErrs []error
// Parse all files (including CgoFiles). // Parse all files (incuding CgoFiles).
parseFile := func(file string) { parseFile := func(file string) {
if !filepath.IsAbs(file) { if !filepath.IsAbs(file) {
file = filepath.Join(p.Dir, file) file = filepath.Join(p.Dir, file)
+16 -19
View File
@@ -285,7 +285,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
// Tests are always run in the package directory. // Tests are always run in the package directory.
cmd.Dir = result.MainDir cmd.Dir = result.MainDir
// wasmtime is the default emulator used for `-target=wasip1`. wasmtime // wasmtime is the default emulator used for `-target=wasi`. wasmtime
// is a WebAssembly runtime CLI with WASI enabled by default. However, // is a WebAssembly runtime CLI with WASI enabled by default. However,
// only stdio are allowed by default. For example, while STDOUT routes // only stdio are allowed by default. For example, while STDOUT routes
// to the host, other files don't. It also does not inherit environment // to the host, other files don't. It also does not inherit environment
@@ -1033,10 +1033,9 @@ func findFATMounts(options *compileopts.Options) ([]mountPoint, error) {
if fstype != "vfat" { if fstype != "vfat" {
continue continue
} }
fspath := strings.ReplaceAll(fields[1], "\\040", " ")
points = append(points, mountPoint{ points = append(points, mountPoint{
name: filepath.Base(fspath), name: filepath.Base(fields[1]),
path: fspath, path: fields[1],
}) })
} }
return points, nil return points, nil
@@ -1226,7 +1225,6 @@ func usage(command string) {
fmt.Fprintln(os.Stderr, " gdb: run/flash and immediately enter GDB") fmt.Fprintln(os.Stderr, " gdb: run/flash and immediately enter GDB")
fmt.Fprintln(os.Stderr, " lldb: run/flash and immediately enter LLDB") fmt.Fprintln(os.Stderr, " lldb: run/flash and immediately enter LLDB")
fmt.Fprintln(os.Stderr, " monitor: open communication port") fmt.Fprintln(os.Stderr, " monitor: open communication port")
fmt.Fprintln(os.Stderr, " ports: list available serial ports")
fmt.Fprintln(os.Stderr, " env: list environment variables used during build") fmt.Fprintln(os.Stderr, " env: list environment variables used during build")
fmt.Fprintln(os.Stderr, " list: run go list using the TinyGo root") fmt.Fprintln(os.Stderr, " list: run go list using the TinyGo root")
fmt.Fprintln(os.Stderr, " clean: empty cache directory ("+goenv.Get("GOCACHE")+")") fmt.Fprintln(os.Stderr, " clean: empty cache directory ("+goenv.Get("GOCACHE")+")")
@@ -1412,7 +1410,7 @@ func main() {
gc := flag.String("gc", "", "garbage collector to use (none, leaking, conservative)") gc := flag.String("gc", "", "garbage collector to use (none, leaking, conservative)")
panicStrategy := flag.String("panic", "print", "panic strategy (print, trap)") panicStrategy := flag.String("panic", "print", "panic strategy (print, trap)")
scheduler := flag.String("scheduler", "", "which scheduler to use (none, tasks, asyncify)") scheduler := flag.String("scheduler", "", "which scheduler to use (none, tasks, asyncify)")
serial := flag.String("serial", "", "which serial output to use (none, uart, usb, rtt)") serial := flag.String("serial", "", "which serial output to use (none, uart, usb)")
work := flag.Bool("work", false, "print the name of the temporary build directory and do not delete this directory on exit") work := flag.Bool("work", false, "print the name of the temporary build directory and do not delete this directory on exit")
interpTimeout := flag.Duration("interp-timeout", 180*time.Second, "interp optimization pass timeout") interpTimeout := flag.Duration("interp-timeout", 180*time.Second, "interp optimization pass timeout")
var tags buildutil.TagsFlag var tags buildutil.TagsFlag
@@ -1439,6 +1437,7 @@ func main() {
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable") llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output") cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
monitor := flag.Bool("monitor", false, "enable serial monitor") monitor := flag.Bool("monitor", false, "enable serial monitor")
info := flag.Bool("info", false, "print information")
baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor") baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor")
// Internal flags, that are only intended for TinyGo development. // Internal flags, that are only intended for TinyGo development.
@@ -1734,19 +1733,17 @@ func main() {
os.Exit(1) os.Exit(1)
} }
case "monitor": case "monitor":
config, err := builder.NewConfig(options) if *info {
handleCompilerError(err) serialPortInfo, err := ListSerialPorts()
err = Monitor("", *port, config) handleCompilerError(err)
handleCompilerError(err) for _, s := range serialPortInfo {
case "ports": fmt.Printf("%s %4s %4s %s\n", s.Name, s.VID, s.PID, s.Target)
serialPortInfo, err := ListSerialPorts() }
handleCompilerError(err) } else {
if len(serialPortInfo) == 0 { config, err := builder.NewConfig(options)
fmt.Println("No serial ports found.") handleCompilerError(err)
} err = Monitor("", *port, config)
fmt.Printf("%-20s %-9s %s\n", "Port", "ID", "Boards") handleCompilerError(err)
for _, s := range serialPortInfo {
fmt.Printf("%-20s %4s:%4s %s\n", s.Name, s.VID, s.PID, s.Target)
} }
case "targets": case "targets":
specs, err := compileopts.GetTargetSpecs() specs, err := compileopts.GetTargetSpecs()
+5 -68
View File
@@ -15,13 +15,11 @@ import (
"reflect" "reflect"
"regexp" "regexp"
"runtime" "runtime"
"slices"
"strings" "strings"
"sync" "sync"
"testing" "testing"
"time" "time"
"github.com/aykevl/go-wasm"
"github.com/tinygo-org/tinygo/builder" "github.com/tinygo-org/tinygo/builder"
"github.com/tinygo-org/tinygo/compileopts" "github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/goenv" "github.com/tinygo-org/tinygo/goenv"
@@ -179,7 +177,7 @@ func TestBuild(t *testing.T) {
}) })
t.Run("WASI", func(t *testing.T) { t.Run("WASI", func(t *testing.T) {
t.Parallel() t.Parallel()
runPlatTests(optionsFromTarget("wasip1", sema), tests, t) runPlatTests(optionsFromTarget("wasi", sema), tests, t)
}) })
} }
} }
@@ -192,10 +190,7 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
t.Fatal("failed to load target spec:", err) t.Fatal("failed to load target spec:", err)
} }
// FIXME: this should really be: isWebAssembly := options.Target == "wasi" || options.Target == "wasm" || (options.Target == "" && options.GOARCH == "wasm")
// isWebAssembly := strings.HasPrefix(spec.Triple, "wasm")
isWASI := strings.HasPrefix(options.Target, "wasi")
isWebAssembly := isWASI || strings.HasPrefix(options.Target, "wasm") || (options.Target == "" && strings.HasPrefix(options.GOARCH, "wasm"))
for _, name := range tests { for _, name := range tests {
if options.GOOS == "linux" && (options.GOARCH == "arm" || options.GOARCH == "386") { if options.GOOS == "linux" && (options.GOARCH == "arm" || options.GOARCH == "386") {
@@ -255,13 +250,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
runTest("alias.go", options, t, nil, nil) runTest("alias.go", options, t, nil, nil)
}) })
} }
if options.Target == "" || isWASI { if options.Target == "" || options.Target == "wasi" {
t.Run("filesystem.go", func(t *testing.T) { t.Run("filesystem.go", func(t *testing.T) {
t.Parallel() t.Parallel()
runTest("filesystem.go", options, t, nil, nil) runTest("filesystem.go", options, t, nil, nil)
}) })
} }
if options.Target == "" || options.Target == "wasm" || isWASI { if options.Target == "" || options.Target == "wasi" || options.Target == "wasm" {
t.Run("rand.go", func(t *testing.T) { t.Run("rand.go", func(t *testing.T) {
t.Parallel() t.Parallel()
runTest("rand.go", options, t, nil, nil) runTest("rand.go", options, t, nil, nil)
@@ -409,64 +404,6 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c
} }
} }
// Test WebAssembly files for certain properties.
func TestWebAssembly(t *testing.T) {
t.Parallel()
type testCase struct {
name string
panicStrategy string
imports []string
}
for _, tc := range []testCase{
// Test whether there really are no imports when using -panic=trap. This
// tests the bugfix for https://github.com/tinygo-org/tinygo/issues/4161.
{name: "panic-default", imports: []string{"wasi_snapshot_preview1.fd_write"}},
{name: "panic-trap", panicStrategy: "trap", imports: []string{}},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
tmpdir := t.TempDir()
options := optionsFromTarget("wasi", sema)
options.PanicStrategy = tc.panicStrategy
config, err := builder.NewConfig(&options)
if err != nil {
t.Fatal(err)
}
result, err := builder.Build("testdata/trivialpanic.go", ".wasm", tmpdir, config)
if err != nil {
t.Fatal("failed to build binary:", err)
}
f, err := os.Open(result.Binary)
if err != nil {
t.Fatal("could not open output binary:", err)
}
defer f.Close()
module, err := wasm.Parse(f)
if err != nil {
t.Fatal("could not parse output binary:", err)
}
// Test the list of imports.
if tc.imports != nil {
var imports []string
for _, section := range module.Sections {
switch section := section.(type) {
case *wasm.SectionImport:
for _, symbol := range section.Entries {
imports = append(imports, symbol.Module+"."+symbol.Field)
}
}
}
if !slices.Equal(imports, tc.imports) {
t.Errorf("import list not as expected!\nexpected: %v\nactual: %v", tc.imports, imports)
}
}
})
}
}
func TestTest(t *testing.T) { func TestTest(t *testing.T) {
t.Parallel() t.Parallel()
@@ -495,7 +432,7 @@ func TestTest(t *testing.T) {
// Node/Wasmtime // Node/Wasmtime
targ{"WASM", optionsFromTarget("wasm", sema)}, targ{"WASM", optionsFromTarget("wasm", sema)},
targ{"WASI", optionsFromTarget("wasip1", sema)}, targ{"WASI", optionsFromTarget("wasi", sema)},
) )
} }
for _, targ := range targs { for _, targ := range targs {
-35
View File
@@ -1,35 +0,0 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0
# Enable these as we fix them
[rule.blank-imports]
Exclude=["src/os/file_other.go"]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
Exclude=["**/*_test.go"]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
Exclude=["src/reflect/*.go"]
[rule.increment-decrement]
[rule.var-naming]
Exclude=["src/os/*.go"]
[rule.var-declaration]
#[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
#[rule.indent-error-flow]
[rule.errorf]
#[rule.empty-block]
[rule.superfluous-else]
#[rule.unused-parameter]
[rule.unreachable-code]
Exclude=["src/reflect/visiblefields_test.go", "src/reflect/all_test.go"]
#[rule.redefines-builtin-id]
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build linux && !baremetal && !wasip1 //go:build linux && !baremetal && !wasi
// This implementation of crypto/rand uses the /dev/urandom pseudo-file to // This implementation of crypto/rand uses the /dev/urandom pseudo-file to
// generate random numbers. // generate random numbers.
-18
View File
@@ -1,18 +0,0 @@
// this is intended to be used as wasm32-unknown-unknown module.
// to compile it, run:
// tinygo build -size short -o hello-unknown.wasm -target wasm-unknown -gc=leaking -no-debug ./src/examples/hello-wasm-unknown/
package main
var x int32
//go:wasmimport hosted echo_i32
func echo(x int32)
//go:export update
func update() {
x++
echo(x)
}
func main() {
}
+2 -2
View File
@@ -57,7 +57,7 @@ func Count(b []byte, c byte) int {
// Count the number of instances of a byte in a string. // Count the number of instances of a byte in a string.
func CountString(s string, c byte) int { func CountString(s string, c byte) int {
// Use a simple implementation, as there is no intrinsic that does this like we want. // Use a simple implementation, as there is no intrinsic that does this like we want.
// Currently, the compiler does not generate zero-copy byte-string conversions, so this needs to be separate from Count. // Currently, the compiler does not generate zero-copy byte-string conversions, so this needs to be seperate from Count.
n := 0 n := 0
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
if s[i] == c { if s[i] == c {
@@ -216,7 +216,7 @@ func HashStrRev[T string | []byte](sep T) (uint32, uint32) {
} }
// IndexRabinKarpBytes uses the Rabin-Karp search algorithm to return the index of the // IndexRabinKarpBytes uses the Rabin-Karp search algorithm to return the index of the
// first occurrence of substr in s, or -1 if not present. // first occurence of substr in s, or -1 if not present.
// //
// This function was removed in Go 1.22. // This function was removed in Go 1.22.
func IndexRabinKarpBytes(s, sep []byte) int { func IndexRabinKarpBytes(s, sep []byte) int {
+1 -1
View File
@@ -44,7 +44,7 @@ func Current() *Task {
// This function may only be called when running on a goroutine stack, not when running on the system stack or in an interrupt. // This function may only be called when running on a goroutine stack, not when running on the system stack or in an interrupt.
func Pause() { func Pause() {
// Check whether the canary (the lowest address of the stack) is still // Check whether the canary (the lowest address of the stack) is still
// valid. If it is not, a stack overflow has occurred. // valid. If it is not, a stack overflow has occured.
if *currentTask.state.canaryPtr != stackCanary { if *currentTask.state.canaryPtr != stackCanary {
runtimePanic("goroutine stack overflow") runtimePanic("goroutine stack overflow")
} }
-2
View File
@@ -1,5 +1,3 @@
//go:build tinygo
// Only generate .debug_frame, don't generate .eh_frame. // Only generate .debug_frame, don't generate .eh_frame.
.cfi_sections .debug_frame .cfi_sections .debug_frame
+1 -3
View File
@@ -1,5 +1,3 @@
//go:build tinygo
.section .bss.tinygo_systemStack .section .bss.tinygo_systemStack
.global tinygo_systemStack .global tinygo_systemStack
.type tinygo_systemStack, %object .type tinygo_systemStack, %object
@@ -28,7 +26,7 @@ tinygo_startTask:
// After return, exit this goroutine. This is a tail call. // After return, exit this goroutine. This is a tail call.
#if __AVR_ARCH__ == 2 || __AVR_ARCH__ == 25 #if __AVR_ARCH__ == 2 || __AVR_ARCH__ == 25
// Small memory devices (8kB flash) that do not have the long call // Small memory devices (8kB flash) that do not have the long call
// instruction available will need to use rcall instead. // instruction availble will need to use rcall instead.
// Note that they will probably not be able to run more than the main // Note that they will probably not be able to run more than the main
// goroutine anyway, but this file is compiled for all AVRs so it needs to // goroutine anyway, but this file is compiled for all AVRs so it needs to
// compile at least. // compile at least.
-2
View File
@@ -1,5 +1,3 @@
//go:build tinygo
// Only generate .debug_frame, don't generate .eh_frame. // Only generate .debug_frame, don't generate .eh_frame.
.cfi_sections .debug_frame .cfi_sections .debug_frame
+4 -4
View File
@@ -52,17 +52,17 @@ func (s *state) archInit(r *calleeSavedRegs, fn uintptr, args unsafe.Pointer) {
} }
func (s *state) resume() { func (s *state) resume() {
tinygo_switchToTask(s.sp) switchToTask(s.sp)
} }
//export tinygo_switchToTask //export tinygo_switchToTask
func tinygo_switchToTask(uintptr) func switchToTask(uintptr)
//export tinygo_switchToScheduler //export tinygo_switchToScheduler
func tinygo_switchToScheduler(*uintptr) func switchToScheduler(*uintptr)
func (s *state) pause() { func (s *state) pause() {
tinygo_switchToScheduler(&s.sp) switchToScheduler(&s.sp)
} }
// SystemStack returns the system stack pointer. On Cortex-M, it is always // SystemStack returns the system stack pointer. On Cortex-M, it is always
+1 -3
View File
@@ -1,5 +1,3 @@
//go:build tinygo
.section .text.tinygo_startTask,"ax",@progbits .section .text.tinygo_startTask,"ax",@progbits
.global tinygo_startTask .global tinygo_startTask
.type tinygo_startTask, %function .type tinygo_startTask, %function
@@ -78,7 +76,7 @@ tinygo_swapTask:
// Switch to the new stack pointer (newStack). // Switch to the new stack pointer (newStack).
mov.n sp, a2 mov.n sp, a2
// Load a0, which is the previous return address from before the previous // Load a0, which is the previous return addres from before the previous
// switch or the constructed return address to tinygo_startTask. This // switch or the constructed return address to tinygo_startTask. This
// register also stores the parent register window. // register also stores the parent register window.
l32i.n a0, sp, 0 l32i.n a0, sp, 0
-2
View File
@@ -1,5 +1,3 @@
//go:build tinygo
.section .text.tinygo_startTask,"ax",@progbits .section .text.tinygo_startTask,"ax",@progbits
.global tinygo_startTask .global tinygo_startTask
.type tinygo_startTask, %function .type tinygo_startTask, %function
@@ -1,5 +1,3 @@
//go:build tinygo
.section .text.tinygo_startTask .section .text.tinygo_startTask
.global tinygo_startTask .global tinygo_startTask
.type tinygo_startTask, %function .type tinygo_startTask, %function
@@ -1,125 +0,0 @@
//go:build adafruit_esp32_feather_v2
package machine
const GPIO20 Pin = 20
const (
IO0 = GPIO0
IO2 = GPIO2
IO4 = GPIO4
IO5 = GPIO5
IO7 = GPIO7
IO8 = GPIO8
IO12 = GPIO12
IO13 = GPIO13
IO14 = GPIO14
IO15 = GPIO15
IO19 = GPIO19
IO20 = GPIO20
IO21 = GPIO21
IO22 = GPIO22
IO25 = GPIO25
IO26 = GPIO26
IO27 = GPIO27
IO32 = GPIO32
IO33 = GPIO33
IO34 = GPIO34
IO35 = GPIO35
IO36 = GPIO36
IO37 = GPIO37
IO38 = GPIO38
IO39 = GPIO39
)
// Digital pins
const (
D12 = IO12
D13 = IO13
D14 = IO14
D15 = IO15
D27 = IO27
D32 = IO32
D33 = IO33
D37 = IO37
)
// Analog pins
const (
A0 = IO26
A1 = IO25
A2 = IO34
A3 = IO39
A4 = IO36
A5 = IO4
)
// Built-in LEDs and Button
const (
WS2812 = IO0
NEOPIXEL = WS2812
NEOPIXEL_I2C_POWER = IO2
LED = IO13
BUTTON = IO38
)
// SPI pins
const (
SPI_SCK_PIN = IO5
SPI_MOSI_PIN = IO19
SPI_MISO_PIN = IO21
SPI_SDO_PIN = SPI_MOSI_PIN
SPI_SDI_PIN = SPI_MISO_PIN
// Silk labels
SCK = SPI_SCK_PIN
MO = SPI_MOSI_PIN
MI = SPI_MISO_PIN
)
// I2C pins
const (
I2C_SCL_PIN = IO20
I2C_SDA_PIN = IO22
// Silk labels
SCL = I2C_SCL_PIN
SDA = I2C_SDA_PIN
)
// ADC pins
const (
ADC1_0 = IO36
ADC1_1 = IO37
ADC1_2 = IO38
ADC1_3 = IO39
ADC1_4 = IO32
ADC1_5 = IO33
ADC1_6 = IO34
ADC1_7 = IO35
ADC2_0 = IO4
ADC2_1 = IO0
ADC2_2 = IO2
ADC2_3 = IO15
ADC2_4 = IO13
ADC2_5 = IO12
ADC2_6 = IO14
ADC2_7 = IO27
ADC2_8 = IO25
ADC2_9 = IO26
)
// UART pins
const (
UART_TX_PIN = IO19
UART_RX_PIN = IO22
UART2_TX_PIN = IO8
UART2_RX_PIN = IO7
// Silk labels
RX = UART2_RX_PIN
TX = UART2_TX_PIN
)
+25
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// GPIO pins // GPIO pins
const ( const (
GP0 Pin = GPIO0 GP0 Pin = GPIO0
@@ -72,8 +77,28 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "AE-RP2040" usb_STRING_PRODUCT = "AE-RP2040"
-95
View File
@@ -1,95 +0,0 @@
//go:build badger2040_w
// This contains the pin mappings for the Badger 2040 W board.
//
// For more information, see: https://shop.pimoroni.com/products/badger-2040-w
// Also
// - Badger 2040 W schematic: https://cdn.shopify.com/s/files/1/0174/1800/files/badger_w_schematic.pdf?v=1675859004
package machine
const (
LED Pin = GPIO22
BUTTON_A Pin = GPIO12
BUTTON_B Pin = GPIO13
BUTTON_C Pin = GPIO14
BUTTON_UP Pin = GPIO15
BUTTON_DOWN Pin = GPIO11
BUTTON_USER Pin = NoPin // Not available on Badger 2040 W
EPD_BUSY_PIN Pin = GPIO26
EPD_RESET_PIN Pin = GPIO21
EPD_DC_PIN Pin = GPIO20
EPD_CS_PIN Pin = GPIO17
EPD_SCK_PIN Pin = GPIO18
EPD_SDO_PIN Pin = GPIO19
VBUS_DETECT Pin = GPIO24
VREF_POWER Pin = GPIO27
VREF_1V24 Pin = GPIO28
VBAT_SENSE Pin = GPIO29
ENABLE_3V3 Pin = GPIO10
BATTERY = VBAT_SENSE
RTC_ALARM = GPIO8
)
// I2C pins
const (
I2C0_SDA_PIN Pin = GPIO4
I2C0_SCL_PIN Pin = GPIO5
I2C1_SDA_PIN Pin = NoPin
I2C1_SCL_PIN Pin = NoPin
)
// SPI pins.
const (
SPI0_SCK_PIN Pin = GPIO18
SPI0_SDO_PIN Pin = GPIO19
SPI0_SDI_PIN Pin = GPIO16
SPI1_SCK_PIN Pin = NoPin
SPI1_SDO_PIN Pin = NoPin
SPI1_SDI_PIN Pin = NoPin
)
// QSPI pins¿?
const (
/*
TODO
SPI0_SD0_PIN Pin = QSPI_SD0
SPI0_SD1_PIN Pin = QSPI_SD1
SPI0_SD2_PIN Pin = QSPI_SD2
SPI0_SD3_PIN Pin = QSPI_SD3
SPI0_SCK_PIN Pin = QSPI_SCLKGPIO6
SPI0_CS_PIN Pin = QSPI_CS
*/
)
// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// USB CDC identifiers
const (
usb_STRING_PRODUCT = "Badger 2040 W"
usb_STRING_MANUFACTURER = "Pimoroni"
)
var (
usb_VID uint16 = 0x2e8a
usb_PID uint16 = 0x0003
)
// UART pins
const (
UART0_TX_PIN = GPIO0
UART0_RX_PIN = GPIO1
UART_TX_PIN = UART0_TX_PIN
UART_RX_PIN = UART0_RX_PIN
)
var DefaultUART = UART0
+20 -6
View File
@@ -1,12 +1,17 @@
//go:build badger2040 //go:build badger2040
// This contains the pin mappings for the Badger 2040 board. // This contains the pin mappings for the Badger 2040 Connect board.
// //
// For more information, see: https://shop.pimoroni.com/products/badger-2040 // For more information, see: https://shop.pimoroni.com/products/badger-2040
// Also // Also
// - Badger 2040 schematic: https://cdn.shopify.com/s/files/1/0174/1800/files/badger_2040_schematic.pdf?v=1645702148 // - Badger 2040 schematic: https://cdn.shopify.com/s/files/1/0174/1800/files/badger_2040_schematic.pdf?v=1645702148
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
const ( const (
LED Pin = GPIO25 LED Pin = GPIO25
@@ -25,12 +30,8 @@ const (
EPD_SDO_PIN Pin = GPIO19 EPD_SDO_PIN Pin = GPIO19
VBUS_DETECT Pin = GPIO24 VBUS_DETECT Pin = GPIO24
VREF_POWER Pin = GPIO27 BATTERY Pin = GPIO29
VREF_1V24 Pin = GPIO28
VBAT_SENSE Pin = GPIO29
ENABLE_3V3 Pin = GPIO10 ENABLE_3V3 Pin = GPIO10
BATTERY = VBAT_SENSE
) )
// I2C pins // I2C pins
@@ -91,4 +92,17 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
}
+25
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
const ( const (
LED = GPIO24 LED = GPIO24
@@ -79,8 +84,28 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "Challenger 2040 LoRa" usb_STRING_PRODUCT = "Challenger 2040 LoRa"
+1 -1
View File
@@ -2,7 +2,7 @@
package machine package machine
const HasLowFrequencyCrystal = false const HasLowFrequencyCrystal = true
// GPIO Pins // GPIO Pins
const ( const (
+25
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Onboard crystal oscillator frequency, in MHz. // Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz const xoscFreq = 12 // MHz
@@ -68,8 +73,28 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "Feather RP2040" usb_STRING_PRODUCT = "Feather RP2040"
+18
View File
@@ -5,6 +5,11 @@
// For more information, see: https://gopherbadge.com/ // For more information, see: https://gopherbadge.com/
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
const ( const (
/*ADC0 Pin = GPIO26 /*ADC0 Pin = GPIO26
ADC1 Pin = GPIO27 ADC1 Pin = GPIO27
@@ -87,4 +92,17 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART1 var DefaultUART = UART1
func init() {
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
+25
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Onboard crystal oscillator frequency, in MHz. // Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz const xoscFreq = 12 // MHz
@@ -70,8 +75,28 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "KB2040" usb_STRING_PRODUCT = "KB2040"
-112
View File
@@ -1,112 +0,0 @@
//go:build m5paper
package machine
const (
IO0 = GPIO0
IO1 = GPIO1
IO2 = GPIO2
IO3 = GPIO3
IO4 = GPIO4
IO5 = GPIO5
IO6 = GPIO6
IO7 = GPIO7
IO8 = GPIO8
IO9 = GPIO9
IO10 = GPIO10
IO11 = GPIO11
IO12 = GPIO12
IO13 = GPIO13
IO14 = GPIO14
IO15 = GPIO15
IO16 = GPIO16
IO17 = GPIO17
IO18 = GPIO18
IO19 = GPIO19
IO21 = GPIO21
IO22 = GPIO22
IO23 = GPIO23
IO25 = GPIO25
IO26 = GPIO26
IO27 = GPIO27
IO32 = GPIO32
IO33 = GPIO33
IO34 = GPIO34
IO35 = GPIO35
IO36 = GPIO36
IO37 = GPIO37
IO38 = GPIO38
IO39 = GPIO39
)
const (
POWER_PIN = IO2
EXT_POWER_PIN = IO5
EPD_POWER_PIN = IO23
// Buttons
BUTTON_RIGHT = IO39
BUTTON_PUSH = IO38
BUTTON_LEFT = IO37
BUTTON = BUTTON_PUSH
// Touch Screen Interrupt
TOUCH_INT = IO36
)
// SPI pins
const (
SPI0_SCK_PIN = IO14
SPI0_SDO_PIN = IO12
SPI0_SDI_PIN = IO13
// EPD (IT8951)
EPD_SCK_PIN = SPI0_SCK_PIN
EPD_SDO_PIN = SPI0_SDO_PIN
EPD_SDI_PIN = SPI0_SDI_PIN
EPD_CS_PIN = IO15
EPD_BUSY_PIN = IO27
// SD CARD
SDCARD_SCK_PIN = SPI0_SCK_PIN
SDCARD_SDO_PIN = SPI0_SDO_PIN
SDCARD_SDI_PIN = SPI0_SDI_PIN
SDCARD_CS_PIN = IO4
)
// I2C pins
const (
SDA0_PIN = IO21
SCL0_PIN = IO22
SDA_PIN = SDA0_PIN
SCL_PIN = SCL0_PIN
I2C_TEMP_ADDR = 0x44 // temperature sensor (SHT30)
I2C_CLOCK_ADDR = 0x51 // real time clock (BM8563)
I2C_TOUCH_ADDR = 0x5D // touch screen controller (GT911)
)
// ADC pins
const (
ADC1 Pin = IO35
ADC2 Pin = IO36
BATTERY_ADC_PIN = ADC1
)
// DAC pins
const (
DAC1 Pin = IO25
DAC2 Pin = IO26
)
// UART pins
const (
// UART0 (CP2104)
UART0_TX_PIN = IO1
UART0_RX_PIN = IO3
UART_TX_PIN = UART0_TX_PIN
UART_RX_PIN = UART0_RX_PIN
)
+18
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
const ( const (
NeopixelCount = 12 NeopixelCount = 12
@@ -73,8 +78,21 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "MacroPad RP2040" usb_STRING_PRODUCT = "MacroPad RP2040"
+1 -1
View File
@@ -26,7 +26,7 @@
// SoftDevice (s140v7) must be flashed first to enable use of bluetooth on this board. // SoftDevice (s140v7) must be flashed first to enable use of bluetooth on this board.
// See https://github.com/tinygo-org/bluetooth // See https://github.com/tinygo-org/bluetooth
// //
// SoftDevice overwrites original bootloader and flashing method described above is not available anymore. // SoftDevice overwrites original bootloader and flashing method described above is not avalable anymore.
// Instead, please use debug probe and flash your code with "nano-33-ble-s140v7" target. // Instead, please use debug probe and flash your code with "nano-33-ble-s140v7" target.
package machine package machine
+27 -2
View File
@@ -11,6 +11,11 @@
// - Nano RP2040 Connect technical reference: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-01-technical-reference // - Nano RP2040 Connect technical reference: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-01-technical-reference
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Digital Pins // Digital Pins
const ( const (
D2 Pin = GPIO25 D2 Pin = GPIO25
@@ -120,7 +125,27 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART_NINA on the Arduino Nano RP2040 connects to the NINA HCI. // UART on the RP2040
var UART_NINA = UART1 var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
// UART_NINA on the Arduino Nano RP2040 connects to the NINA HCI.
UART_NINA = UART1
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
-105
View File
@@ -1,105 +0,0 @@
//go:build nucleol476rg
// Schematic: https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf
// Datasheet: https://www.st.com/resource/en/datasheet/stm32l476je.pdf
package machine
import (
"device/stm32"
"runtime/interrupt"
)
const (
// Arduino Pins
A0 = PA0
A1 = PA1
A2 = PA4
A3 = PB0
A4 = PC1
A5 = PC0
D0 = PA3
D1 = PA2
D2 = PA10
D3 = PB3
D4 = PB5
D5 = PB4
D6 = PB10
D7 = PA8
D8 = PA9
D9 = PC7
D10 = PB6
D11 = PA7
D12 = PA6
D13 = PA5
D14 = PB9
D15 = PB8
)
// User LD2: the green LED is a user LED connected to ARDUINO® signal D13 corresponding
// to STM32 I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32 target.
const (
LED = LED_BUILTIN
LED_BUILTIN = LED_GREEN
LED_GREEN = PA5
)
const (
// This board does not have a user button, so
// use first GPIO pin by default
BUTTON = PA0
)
const (
// UART pins
// PA2 and PA3 are connected to the ST-Link Virtual Com Port (VCP)
UART_TX_PIN = PA2
UART_RX_PIN = PA3
// I2C pins
// With default solder bridge settings:
// PB8 / Arduino D5 / CN3 Pin 8 is SCL
// PB7 / Arduino D4 / CN3 Pin 7 is SDA
I2C0_SCL_PIN = PB8
I2C0_SDA_PIN = PB9
// SPI pins
SPI1_SCK_PIN = PA5
SPI1_SDI_PIN = PA6
SPI1_SDO_PIN = PA7
SPI0_SCK_PIN = SPI1_SCK_PIN
SPI0_SDI_PIN = SPI1_SDI_PIN
SPI0_SDO_PIN = SPI1_SDO_PIN
)
var (
// USART2 is the hardware serial port connected to the onboard ST-LINK
// debugger to be exposed as virtual COM port over USB on Nucleo boards.
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: stm32.USART2,
TxAltFuncSelector: AF7_USART1_2_3,
RxAltFuncSelector: AF7_USART1_2_3,
}
DefaultUART = UART1
// I2C1 is documented, alias to I2C0 as well
I2C1 = &I2C{
Bus: stm32.I2C1,
AltFuncSelector: AF4_I2C1_2_3,
}
I2C0 = I2C1
// SPI1 is documented, alias to SPI0 as well
SPI1 = &SPI{
Bus: stm32.SPI1,
AltFuncSelector: AF5_SPI1_2,
}
SPI0 = SPI1
)
func init() {
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
}
+25
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// GPIO pins // GPIO pins
const ( const (
GP0 Pin = GPIO0 GP0 Pin = GPIO0
@@ -74,8 +79,28 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "Pico" usb_STRING_PRODUCT = "Pico"
+25
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Onboard crystal oscillator frequency, in MHz. // Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz const xoscFreq = 12 // MHz
@@ -79,8 +84,28 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "QT Py RP2040" usb_STRING_PRODUCT = "QT Py RP2040"
+19 -5
View File
@@ -2,6 +2,11 @@
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Onboard crystal oscillator frequency, in MHz. // Onboard crystal oscillator frequency, in MHz.
const xoscFreq = 12 // MHz const xoscFreq = 12 // MHz
@@ -46,11 +51,7 @@ const (
A3 = GPIO29 A3 = GPIO29
) )
// Onboard LEDs const LED = GPIO25
const (
LED = GPIO25
WS2812 = GPIO8
)
// I2C Pins. // I2C Pins.
const ( const (
@@ -89,8 +90,21 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
}
// USB identifiers // USB identifiers
const ( const (
usb_STRING_PRODUCT = "Thing Plus RP2040" usb_STRING_PRODUCT = "Thing Plus RP2040"
-76
View File
@@ -1,76 +0,0 @@
//go:build thumby
// This contains the pin mappings for the Thumby.
//
// https://thumby.us/
package machine
const (
THUMBY_SCK_PIN = I2C1_SDA_PIN
THUMBY_SDA_PIN = I2C1_SCL_PIN
THUMBY_CS_PIN = GPIO16
THUMBY_DC_PIN = GPIO17
THUMBY_RESET_PIN = GPIO20
THUMBY_LINK_TX_PIN = UART0_TX_PIN
THUMBY_LINK_RX_PIN = UART0_RX_PIN
THUMBY_LINK_PU_PIN = GPIO2
THUMBY_BTN_LDPAD_PIN = GPIO3
THUMBY_BTN_RDPAD_PIN = GPIO5
THUMBY_BTN_UDPAD_PIN = GPIO4
THUMBY_BTN_DDPAD_PIN = GPIO6
THUMBY_BTN_B_PIN = GPIO24
THUMBY_BTN_A_PIN = GPIO27
THUMBY_AUDIO_PIN = GPIO28
THUMBY_SCREEN_RESET_PIN = GPIO20
)
// I2C pins
const (
I2C0_SDA_PIN Pin = NoPin
I2C0_SCL_PIN Pin = NoPin
I2C1_SDA_PIN Pin = GPIO18
I2C1_SCL_PIN Pin = GPIO19
)
// SPI pins
const (
SPI0_SCK_PIN = GPIO18
SPI0_SDO_PIN = GPIO19
SPI0_SDI_PIN = GPIO16
SPI1_SCK_PIN = NoPin
SPI1_SDO_PIN = NoPin
SPI1_SDI_PIN = NoPin
)
// Onboard crystal oscillator frequency, in MHz.
const (
xoscFreq = 12 // MHz
)
// USB CDC identifiers
const (
usb_STRING_PRODUCT = "Thumby"
usb_STRING_MANUFACTURER = "TinyCircuits"
)
var (
usb_VID uint16 = 0x2E8A
usb_PID uint16 = 0x0005
)
// UART pins
const (
UART0_TX_PIN = GPIO0
UART0_RX_PIN = GPIO1
UART_TX_PIN = UART0_TX_PIN
UART_RX_PIN = UART0_RX_PIN
)
var DefaultUART = UART0
+18
View File
@@ -7,6 +7,11 @@
// - Tufty 2040 schematic: https://cdn.shopify.com/s/files/1/0174/1800/files/tufty_schematic.pdf?v=1655385675 // - Tufty 2040 schematic: https://cdn.shopify.com/s/files/1/0174/1800/files/tufty_schematic.pdf?v=1655385675
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
const ( const (
LED Pin = GPIO25 LED Pin = GPIO25
@@ -82,4 +87,17 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
}
+24 -1
View File
@@ -7,6 +7,11 @@
// - https://www.waveshare.com/wiki/RP2040-Zero // - https://www.waveshare.com/wiki/RP2040-Zero
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Digital Pins // Digital Pins
const ( const (
D0 Pin = GPIO0 D0 Pin = GPIO0
@@ -52,7 +57,6 @@ const (
// Onboard LEDs // Onboard LEDs
const ( const (
NEOPIXEL = GPIO16 NEOPIXEL = GPIO16
WS2812 = GPIO16
) )
// I2C pins // I2C pins
@@ -90,8 +94,27 @@ const (
UART1_RX_PIN = GPIO9 UART1_RX_PIN = GPIO9
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}
// USB CDC identifiers // USB CDC identifiers
const ( const (
usb_STRING_PRODUCT = "RP2040-Zero" usb_STRING_PRODUCT = "RP2040-Zero"
+18
View File
@@ -7,6 +7,11 @@
// - https://wiki.seeedstudio.com/XIAO-RP2040/ // - https://wiki.seeedstudio.com/XIAO-RP2040/
package machine package machine
import (
"device/rp"
"runtime/interrupt"
)
// Digital Pins // Digital Pins
const ( const (
D0 Pin = GPIO26 D0 Pin = GPIO26
@@ -76,8 +81,21 @@ const (
UART_RX_PIN = UART0_RX_PIN UART_RX_PIN = UART0_RX_PIN
) )
// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}
)
var DefaultUART = UART0 var DefaultUART = UART0
func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
}
// USB CDC identifiers // USB CDC identifiers
const ( const (
usb_STRING_PRODUCT = "XIAO RP2040" usb_STRING_PRODUCT = "XIAO RP2040"
+29
View File
@@ -0,0 +1,29 @@
//go:build atmega || nrf || sam || stm32 || fe310 || k210 || rp2040 || (esp32c3 && !m5stamp_c3)
package machine
// This file implements WriteRegister and ReadRegister for chips that do not
// have direct hardware support for this feature.
// WriteRegister transmits first the register and then the data to the
// peripheral device.
//
// Many I2C-compatible devices are organized in terms of registers. This method
// is a shortcut to easily write to such registers. Also, it only works for
// devices with 7-bit addresses, which is the vast majority.
func (i2c *I2C) WriteRegister(address uint8, register uint8, data []byte) error {
buf := make([]uint8, len(data)+1)
buf[0] = register
copy(buf[1:], data)
return i2c.Tx(uint16(address), buf, nil)
}
// ReadRegister transmits the register, restarts the connection as a read
// operation, and reads the response.
//
// Many I2C-compatible devices are organized in terms of registers. This method
// is a shortcut to easily read such registers. Also, it only works for devices
// with 7-bit addresses, which is the vast majority.
func (i2c *I2C) ReadRegister(address uint8, register uint8, data []byte) error {
return i2c.Tx(uint16(address), []byte{register}, data)
}
+3 -24
View File
@@ -1,4 +1,4 @@
//go:build !baremetal || atmega || nrf || sam || stm32 || fe310 || k210 || rp2040 || mimxrt1062 || (esp32c3 && !m5stamp_c3) || esp32 //go:build atmega || nrf || sam || stm32 || fe310 || k210 || rp2040 || mimxrt1062 || (esp32c3 && !m5stamp_c3)
package machine package machine
@@ -15,6 +15,8 @@ var _ interface { // 2
Configure(config I2CConfig) error Configure(config I2CConfig) error
Tx(addr uint16, w, r []byte) error Tx(addr uint16, w, r []byte) error
SetBaudRate(br uint32) error SetBaudRate(br uint32) error
WriteRegister(address, register uint8, data []byte) error
ReadRegister(address, register uint8, data []byte) error
} = (*I2C)(nil) } = (*I2C)(nil)
// TWI_FREQ is the I2C bus speed. Normally either 100 kHz, or 400 kHz for high-speed bus. // TWI_FREQ is the I2C bus speed. Normally either 100 kHz, or 400 kHz for high-speed bus.
@@ -67,26 +69,3 @@ const (
// I2CModeTarget represents an I2C peripheral in target mode. // I2CModeTarget represents an I2C peripheral in target mode.
I2CModeTarget I2CModeTarget
) )
// WriteRegister transmits first the register and then the data to the
// peripheral device.
//
// Many I2C-compatible devices are organized in terms of registers. This method
// is a shortcut to easily write to such registers. Also, it only works for
// devices with 7-bit addresses, which is the vast majority.
func (i2c *I2C) WriteRegister(address uint8, register uint8, data []byte) error {
buf := make([]uint8, len(data)+1)
buf[0] = register
copy(buf[1:], data)
return i2c.Tx(uint16(address), buf, nil)
}
// ReadRegister transmits the register, restarts the connection as a read
// operation, and reads the response.
//
// Many I2C-compatible devices are organized in terms of registers. This method
// is a shortcut to easily read such registers. Also, it only works for devices
// with 7-bit addresses, which is the vast majority.
func (i2c *I2C) ReadRegister(address uint8, register uint8, data []byte) error {
return i2c.Tx(uint16(address), []byte{register}, data)
}
+5 -5
View File
@@ -1304,7 +1304,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
return byte(spi.Bus.DATA.Get()), nil return byte(spi.Bus.DATA.Get()), nil
} }
// Tx handles read/write operation for SPI interface. Since SPI is a synchronous write/read // Tx handles read/write operation for SPI interface. Since SPI is a syncronous write/read
// interface, there must always be the same number of bytes written as bytes read. // interface, there must always be the same number of bytes written as bytes read.
// The Tx method knows about this, and offers a few different ways of calling it. // The Tx method knows about this, and offers a few different ways of calling it.
// //
@@ -1459,7 +1459,7 @@ func (tcc *TCC) Configure(config PWMConfig) error {
for tcc.timer().SYNCBUSY.Get() != 0 { for tcc.timer().SYNCBUSY.Get() != 0 {
} }
// Return any error that might have occurred in the tcc.setPeriod call. // Return any error that might have occured in the tcc.setPeriod call.
return err return err
} }
@@ -1606,7 +1606,7 @@ func (tcc *TCC) Counter() uint32 {
return tcc.timer().COUNT.Get() return tcc.timer().COUNT.Get()
} }
// Some constants to make pinTimerMapping below easier to read. // Some constans to make pinTimerMapping below easier to read.
const ( const (
pinTCC0 = 1 pinTCC0 = 1
pinTCC1 = 2 pinTCC1 = 2
@@ -1657,7 +1657,7 @@ var pinTimerMapping = [...]uint8{
PB30 / 2: pinTCC0Ch0 | pinTCC1Ch2<<4, PB30 / 2: pinTCC0Ch0 | pinTCC1Ch2<<4,
} }
// findPinTimerMapping returns the pin mode (PinTCC or PinTCCAlt) and the channel // findPinPadMapping returns the pin mode (PinTCC or PinTCCAlt) and the channel
// number for a given timer and pin. A zero PinMode is returned if no mapping // number for a given timer and pin. A zero PinMode is returned if no mapping
// could be found. // could be found.
func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) { func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) {
@@ -1759,7 +1759,7 @@ func (tcc *TCC) Set(channel uint8, value uint32) {
} }
} }
// EnterBootloader should perform a system reset in preparation // EnterBootloader should perform a system reset in preperation
// to switch to the bootloader to flash new firmware. // to switch to the bootloader to flash new firmware.
func EnterBootloader() { func EnterBootloader() {
arm.DisableInterrupts() arm.DisableInterrupts()
+3 -3
View File
@@ -1587,7 +1587,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
return byte(spi.Bus.DATA.Get()), nil return byte(spi.Bus.DATA.Get()), nil
} }
// Tx handles read/write operation for SPI interface. Since SPI is a synchronous write/read // Tx handles read/write operation for SPI interface. Since SPI is a syncronous write/read
// interface, there must always be the same number of bytes written as bytes read. // interface, there must always be the same number of bytes written as bytes read.
// The Tx method knows about this, and offers a few different ways of calling it. // The Tx method knows about this, and offers a few different ways of calling it.
// //
@@ -1720,7 +1720,7 @@ func (tcc *TCC) Configure(config PWMConfig) error {
for tcc.timer().SYNCBUSY.Get() != 0 { for tcc.timer().SYNCBUSY.Get() != 0 {
} }
// Return any error that might have occurred in the tcc.setPeriod call. // Return any error that might have occured in the tcc.setPeriod call.
return err return err
} }
@@ -1928,7 +1928,7 @@ var pinTimerMapping = [...]struct{ F, G uint8 }{
PB02 / 2: {pinTCC2_2, 0}, PB02 / 2: {pinTCC2_2, 0},
} }
// findPinTimerMapping returns the pin mode (PinTCCF or PinTCCG) and the channel // findPinPadMapping returns the pin mode (PinTCCF or PinTCCG) and the channel
// number for a given timer and pin. A zero PinMode is returned if no mapping // number for a given timer and pin. A zero PinMode is returned if no mapping
// could be found. // could be found.
func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) { func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) {
+1 -6
View File
@@ -155,7 +155,7 @@ func (can *CAN) Configure(config CANConfig) error {
} }
// Callbacks to be called for CAN.SetInterrupt(). Wre're using the magic // Callbacks to be called for CAN.SetInterrupt(). Wre're using the magic
// constant 2 and 32 here because the SAM E51/E54 has 2 CAN and 32 interrupt // constant 2 and 32 here beacuse th SAM E51/E54 has 2 CAN and 32 interrupt
// sources. // sources.
var ( var (
canInstances [2]*CAN canInstances [2]*CAN
@@ -221,11 +221,6 @@ func (can *CAN) TxFifoIsFull() bool {
return (can.Bus.TXFQS.Get() & sam.CAN_TXFQS_TFQF_Msk) == sam.CAN_TXFQS_TFQF_Msk return (can.Bus.TXFQS.Get() & sam.CAN_TXFQS_TFQF_Msk) == sam.CAN_TXFQS_TFQF_Msk
} }
// TxFifoFreeLevel returns how many messages can still be set in the TxFifo.
func (can *CAN) TxFifoFreeLevel() int {
return int(can.Bus.GetTXFQS_TFFL())
}
// TxRaw sends a CAN Frame according to CANTxBufferElement. // TxRaw sends a CAN Frame according to CANTxBufferElement.
func (can *CAN) TxRaw(e *CANTxBufferElement) { func (can *CAN) TxRaw(e *CANTxBufferElement) {
putIndex := (can.Bus.TXFQS.Get() & sam.CAN_TXFQS_TFQPI_Msk) >> sam.CAN_TXFQS_TFQPI_Pos putIndex := (can.Bus.TXFQS.Get() & sam.CAN_TXFQS_TFQPI_Msk) >> sam.CAN_TXFQS_TFQPI_Pos
+1 -1
View File
@@ -460,7 +460,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
return byte(spi.Bus.W0.Get()), nil return byte(spi.Bus.W0.Get()), nil
} }
// Tx handles read/write operation for SPI interface. Since SPI is a synchronous write/read // Tx handles read/write operation for SPI interface. Since SPI is a syncronous write/read
// interface, there must always be the same number of bytes written as bytes read. // interface, there must always be the same number of bytes written as bytes read.
// This is accomplished by sending zero bits if r is bigger than w or discarding // This is accomplished by sending zero bits if r is bigger than w or discarding
// the incoming data if w is bigger than r. // the incoming data if w is bigger than r.
-412
View File
@@ -1,412 +0,0 @@
//go:build esp32
package machine
import (
"device/esp"
"runtime/volatile"
"unsafe"
)
var (
I2C0 = &I2C{Bus: esp.I2C0, funcSCL: 29, funcSDA: 30}
I2C1 = &I2C{Bus: esp.I2C1, funcSCL: 95, funcSDA: 96}
)
type I2C struct {
Bus *esp.I2C_Type
funcSCL, funcSDA uint32
config I2CConfig
}
// I2CConfig is used to store config info for I2C.
type I2CConfig struct {
Frequency uint32 // in Hz
SCL Pin
SDA Pin
}
const (
i2cClkSourceFrequency = uint32(80 * MHz)
)
func (i2c *I2C) Configure(config I2CConfig) error {
if config.Frequency == 0 {
config.Frequency = 400 * KHz
}
if config.SCL == 0 {
config.SCL = SCL_PIN
}
if config.SDA == 0 {
config.SDA = SDA_PIN
}
i2c.config = config
i2c.initAll()
return nil
}
func (i2c *I2C) initAll() {
i2c.initClock()
i2c.initNoiseFilter()
i2c.initPins()
i2c.initFrequency()
i2c.startMaster()
}
//go:inline
func (i2c *I2C) initClock() {
// reset I2C clock
if i2c.Bus == esp.I2C0 {
esp.DPORT.SetPERIP_RST_EN_I2C0_EXT0_RST(1)
esp.DPORT.SetPERIP_CLK_EN_I2C0_EXT0_CLK_EN(1)
esp.DPORT.SetPERIP_RST_EN_I2C0_EXT0_RST(0)
} else {
esp.DPORT.SetPERIP_RST_EN_I2C_EXT1_RST(1)
esp.DPORT.SetPERIP_CLK_EN_I2C_EXT1_CLK_EN(1)
esp.DPORT.SetPERIP_RST_EN_I2C_EXT1_RST(0)
}
// disable interrupts
i2c.Bus.INT_ENA.Set(0)
i2c.Bus.INT_CLR.Set(0x3fff)
i2c.Bus.SetCTR_CLK_EN(1)
}
//go:inline
func (i2c *I2C) initNoiseFilter() {
i2c.Bus.SCL_FILTER_CFG.Set(0xF)
i2c.Bus.SDA_FILTER_CFG.Set(0xF)
}
//go:inline
func (i2c *I2C) initPins() {
var muxConfig uint32
const function = 2 // function 2 is just GPIO
// SDA
muxConfig = function << esp.IO_MUX_GPIO0_MCU_SEL_Pos
// Make this pin an input pin (always).
muxConfig |= esp.IO_MUX_GPIO0_FUN_IE
// Set drive strength: 0 is lowest, 3 is highest.
muxConfig |= 1 << esp.IO_MUX_GPIO0_FUN_DRV_Pos
i2c.config.SDA.mux().Set(muxConfig)
i2c.config.SDA.outFunc().Set(i2c.funcSDA)
inFunc(i2c.funcSDA).Set(uint32(esp.GPIO_FUNC_IN_SEL_CFG_SEL | i2c.config.SDA))
i2c.config.SDA.Set(true)
// Configure the pad with the given IO mux configuration.
i2c.config.SDA.pinReg().SetBits(esp.GPIO_PIN_PAD_DRIVER)
esp.GPIO.ENABLE_W1TS.Set(1 << int(i2c.config.SDA))
i2c.Bus.SetCTR_SDA_FORCE_OUT(1)
// SCL
muxConfig = function << esp.IO_MUX_GPIO0_MCU_SEL_Pos
// Make this pin an input pin (always).
muxConfig |= esp.IO_MUX_GPIO0_FUN_IE
// Set drive strength: 0 is lowest, 3 is highest.
muxConfig |= 1 << esp.IO_MUX_GPIO0_FUN_DRV_Pos
i2c.config.SCL.mux().Set(muxConfig)
i2c.config.SCL.outFunc().Set(i2c.funcSCL)
inFunc(i2c.funcSCL).Set(uint32(esp.GPIO_FUNC_IN_SEL_CFG_SEL | i2c.config.SCL))
i2c.config.SCL.Set(true)
// Configure the pad with the given IO mux configuration.
i2c.config.SCL.pinReg().SetBits(esp.GPIO_PIN_PAD_DRIVER)
esp.GPIO.ENABLE_W1TS.Set(1 << int(i2c.config.SCL))
i2c.Bus.SetCTR_SCL_FORCE_OUT(1)
}
//go:inline
func (i2c *I2C) initFrequency() {
clkmDiv := i2cClkSourceFrequency/(i2c.config.Frequency*1024) + 1
sclkFreq := i2cClkSourceFrequency / clkmDiv
halfCycle := sclkFreq / i2c.config.Frequency / 2
//SCL
sclLow := halfCycle
sclWaitHigh := uint32(0)
if i2c.config.Frequency > 50000 {
sclWaitHigh = halfCycle / 8 // compensate the time when freq > 50K
}
sclHigh := halfCycle - sclWaitHigh
// SDA
sdaHold := halfCycle / 4
sda_sample := halfCycle / 2
setup := halfCycle
hold := halfCycle
i2c.Bus.SetSCL_LOW_PERIOD(sclLow - 1)
i2c.Bus.SetSCL_HIGH_PERIOD(sclHigh)
i2c.Bus.SetSCL_RSTART_SETUP_TIME(setup)
i2c.Bus.SetSCL_STOP_SETUP_TIME(setup)
i2c.Bus.SetSCL_START_HOLD_TIME(hold - 1)
i2c.Bus.SetSCL_STOP_HOLD_TIME(hold - 1)
i2c.Bus.SetSDA_SAMPLE_TIME(sda_sample)
i2c.Bus.SetSDA_HOLD_TIME(sdaHold)
// set timeout value
i2c.Bus.SetTO_TIME_OUT(20 * halfCycle)
}
//go:inline
func (i2c *I2C) startMaster() {
// FIFO mode for data
i2c.Bus.SetFIFO_CONF_NONFIFO_EN(0)
// Reset TX & RX buffers
i2c.Bus.SetFIFO_CONF_RX_FIFO_RST(1)
i2c.Bus.SetFIFO_CONF_RX_FIFO_RST(0)
i2c.Bus.SetFIFO_CONF_TX_FIFO_RST(1)
i2c.Bus.SetFIFO_CONF_TX_FIFO_RST(0)
// enable master mode
i2c.Bus.SetCTR_MS_MODE(1)
}
func (i2c *I2C) resetBus() {
// unlike esp32c3, the esp32 i2c modules do not have a reset fsm register,
// so we need to:
// 1. disconnect the pins
// 2. generate a stop condition manually
// 3. do a full reset
// 4. redo all configuration
i2c.config.SDA.mux().Set(2<<esp.IO_MUX_GPIO0_MCU_SEL_Pos | esp.IO_MUX_GPIO0_FUN_IE | 1<<esp.IO_MUX_GPIO0_FUN_DRV_Pos)
i2c.config.SDA.outFunc().Set(0x500)
i2c.config.SDA.pinReg().SetBits(esp.GPIO_PIN_PAD_DRIVER)
i2c.config.SCL.mux().Set(2<<esp.IO_MUX_GPIO0_MCU_SEL_Pos | esp.IO_MUX_GPIO0_FUN_IE | 1<<esp.IO_MUX_GPIO0_FUN_DRV_Pos)
i2c.config.SCL.outFunc().Set(0x500)
i2c.config.SCL.pinReg().SetBits(esp.GPIO_PIN_PAD_DRIVER)
// bit-bang a read-NACK in case any device on the bus is in the middle of a write
i2c.config.SCL.Low()
i2c.config.SDA.High()
wait()
for i := 0; i < 9; i++ {
if i2c.config.SDA.Get() {
break
}
i2c.config.SCL.High()
wait()
i2c.config.SCL.Low()
wait()
}
i2c.config.SDA.Low()
i2c.config.SCL.High()
wait()
i2c.config.SDA.High()
// initAll contains initClock which contains a reset
i2c.initAll()
}
func wait() {
end := nanotime() + 5_000
for nanotime() < end {
//spin
}
}
type i2cCommandType = uint32
type i2cAck = uint32
const (
i2cCMD_RSTART i2cCommandType = 0 << 11
i2cCMD_WRITE i2cCommandType = 1<<11 | 1<<8 // WRITE + ack_check_en
i2cCMD_READ i2cCommandType = 2 << 11
i2cCMD_READLAST i2cCommandType = 2<<11 | 1<<10 // READ + NACK
i2cCMD_STOP i2cCommandType = 3 << 11
i2cCMD_END i2cCommandType = 4 << 11
)
type i2cCommand struct {
cmd i2cCommandType
data []byte
head int
}
//go:linkname nanotime runtime.nanotime
func nanotime() int64
func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
if i2c.Bus.GetSR_BUS_BUSY() == 1 {
i2c.resetBus()
}
const intMask = esp.I2C_INT_STATUS_END_DETECT_INT_ST_Msk | esp.I2C_INT_STATUS_TRANS_COMPLETE_INT_ST_Msk | esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk | esp.I2C_INT_STATUS_ACK_ERR_INT_ST_Msk | esp.I2C_INT_STATUS_ARBITRATION_LOST_INT_ST_Msk
i2c.Bus.INT_CLR.Set(intMask)
i2c.Bus.INT_ENA.Set(intMask)
defer func() {
i2c.Bus.INT_CLR.Set(intMask)
i2c.Bus.INT_ENA.Set(0)
}()
timeoutNS := int64(timeoutMS) * 1000000
needAddress := true
needRestart := false
readLast := false
var readTo []byte
for cmdIdx, reg := 0, &i2c.Bus.COMD0; cmdIdx < len(cmd); {
c := &cmd[cmdIdx]
switch c.cmd {
case i2cCMD_RSTART:
reg.Set(i2cCMD_RSTART)
reg = nextAddress(reg)
cmdIdx++
case i2cCMD_WRITE:
count := 32
if needAddress {
needAddress = false
i2c.Bus.SetDATA_FIFO_RDATA((uint32(addr) & 0x7f) << 1)
count--
i2c.Bus.SLAVE_ADDR.Set(uint32(addr))
}
for ; count > 0 && c.head < len(c.data); count, c.head = count-1, c.head+1 {
i2c.Bus.SetDATA_FIFO_RDATA(uint32(c.data[c.head]))
}
reg.Set(i2cCMD_WRITE | uint32(32-count))
reg = nextAddress(reg)
if c.head < len(c.data) {
reg.Set(i2cCMD_END)
reg = nil
} else {
cmdIdx++
}
needRestart = true
case i2cCMD_READ:
if needAddress {
needAddress = false
i2c.Bus.SetDATA_FIFO_RDATA((uint32(addr)&0x7f)<<1 | 1)
i2c.Bus.SLAVE_ADDR.Set(uint32(addr))
reg.Set(i2cCMD_WRITE | 1)
reg = nextAddress(reg)
}
if needRestart {
// We need to send RESTART again after i2cCMD_WRITE.
reg.Set(i2cCMD_RSTART)
reg = nextAddress(reg)
reg.Set(i2cCMD_WRITE | 1)
reg = nextAddress(reg)
i2c.Bus.SetDATA_FIFO_RDATA((uint32(addr)&0x7f)<<1 | 1)
needRestart = false
}
count := 32
bytes := len(c.data) - c.head
// Only last byte in sequence must be sent with ACK set to 1 to indicate end of data.
split := bytes <= count
if split {
bytes--
}
if bytes > 32 {
bytes = 32
}
if bytes > 0 {
reg.Set(i2cCMD_READ | uint32(bytes))
reg = nextAddress(reg)
}
if split {
readLast = true
reg.Set(i2cCMD_READLAST | 1)
reg = nextAddress(reg)
readTo = c.data[c.head : c.head+bytes+1] // read bytes + 1 last byte
cmdIdx++
} else {
reg.Set(i2cCMD_END)
readTo = c.data[c.head : c.head+bytes]
reg = nil
}
case i2cCMD_STOP:
reg.Set(i2cCMD_STOP)
reg = nil
cmdIdx++
}
if reg == nil {
// transmit now
i2c.Bus.SetCTR_TRANS_START(1)
end := nanotime() + timeoutNS
var mask uint32
for mask = i2c.Bus.INT_STATUS.Get(); mask&intMask == 0; mask = i2c.Bus.INT_STATUS.Get() {
if nanotime() > end {
// timeout leaves the bus in an undefined state, reset
i2c.resetBus()
if readTo != nil {
return errI2CReadTimeout
}
return errI2CWriteTimeout
}
}
switch {
case mask&esp.I2C_INT_STATUS_ACK_ERR_INT_ST_Msk != 0 && !readLast:
return errI2CAckExpected
case mask&esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk != 0:
// timeout leaves the bus in an undefined state, reset
i2c.resetBus()
if readTo != nil {
return errI2CReadTimeout
}
return errI2CWriteTimeout
}
i2c.Bus.INT_CLR.SetBits(intMask)
for i := 0; i < len(readTo); i++ {
readTo[i] = byte(i2c.Bus.GetDATA_FIFO_RDATA() & 0xff)
c.head++
}
readTo = nil
reg = &i2c.Bus.COMD0
}
}
return nil
}
// Tx does a single I2C transaction at the specified address.
// It clocks out the given address, writes the bytes in w, reads back len(r)
// bytes and stores them in r, and generates a stop condition on the bus.
func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) {
// timeout in microseconds.
const timeout = 40 // 40ms is a reasonable time for a real-time system.
cmd := make([]i2cCommand, 0, 8)
cmd = append(cmd, i2cCommand{cmd: i2cCMD_RSTART})
if len(w) > 0 {
cmd = append(cmd, i2cCommand{cmd: i2cCMD_WRITE, data: w})
}
if len(r) > 0 {
cmd = append(cmd, i2cCommand{cmd: i2cCMD_READ, data: r})
}
cmd = append(cmd, i2cCommand{cmd: i2cCMD_STOP})
return i2c.transmit(addr, cmd, timeout)
}
func (i2c *I2C) SetBaudRate(br uint32) error {
return errI2CNotImplemented
}
func (p Pin) pinReg() *volatile.Register32 {
return (*volatile.Register32)(unsafe.Pointer((uintptr(unsafe.Pointer(&esp.GPIO.PIN0)) + uintptr(p)*4)))
}
func nextAddress(reg *volatile.Register32) *volatile.Register32 {
return (*volatile.Register32)(unsafe.Add(unsafe.Pointer(reg), 4))
}
// CheckDevice does an empty I2C transaction at the specified address.
// This can be used to find out if any device with that address is
// connected, e.g. for enumerating all devices on the bus.
func (i2c *I2C) CheckDevice(addr uint16) bool {
// timeout in microseconds.
const timeout = 40 // 40ms is a reasonable time for a real-time system.
cmd := []i2cCommand{
{cmd: i2cCMD_RSTART},
{cmd: i2cCMD_WRITE},
{cmd: i2cCMD_STOP},
}
return i2c.transmit(addr, cmd, timeout) == nil
}
+8 -8
View File
@@ -192,7 +192,7 @@ func (p Pin) SetInterrupt(change PinChange, callback func(Pin)) (err error) {
if callback == nil { if callback == nil {
// Disable this pin interrupt // Disable this pin interrupt
p.pin().ClearBits(esp.GPIO_PIN_INT_TYPE_Msk | esp.GPIO_PIN_INT_ENA_Msk) p.pin().ClearBits(esp.GPIO_PIN_PIN_INT_TYPE_Msk | esp.GPIO_PIN_PIN_INT_ENA_Msk)
if pinCallbacks[p] != nil { if pinCallbacks[p] != nil {
pinCallbacks[p] = nil pinCallbacks[p] = nil
@@ -216,8 +216,8 @@ func (p Pin) SetInterrupt(change PinChange, callback func(Pin)) (err error) {
} }
p.pin().Set( p.pin().Set(
(p.pin().Get() & ^uint32(esp.GPIO_PIN_INT_TYPE_Msk|esp.GPIO_PIN_INT_ENA_Msk)) | (p.pin().Get() & ^uint32(esp.GPIO_PIN_PIN_INT_TYPE_Msk|esp.GPIO_PIN_PIN_INT_ENA_Msk)) |
uint32(change)<<esp.GPIO_PIN_INT_TYPE_Pos | uint32(1)<<esp.GPIO_PIN_INT_ENA_Pos) uint32(change)<<esp.GPIO_PIN_PIN_INT_TYPE_Pos | uint32(1)<<esp.GPIO_PIN_PIN_INT_ENA_Pos)
return nil return nil
} }
@@ -312,7 +312,7 @@ func (uart *UART) configure(config UARTConfig, regs registerSet) error {
initUARTClock(uart.Bus, regs) initUARTClock(uart.Bus, regs)
// - disable TX/RX clock to make sure the UART transmitter or receiver is not at work during configuration // - disbale TX/RX clock to make sure the UART transmitter or receiver is not at work during configuration
uart.Bus.SetCLK_CONF_TX_SCLK_EN(0) uart.Bus.SetCLK_CONF_TX_SCLK_EN(0)
uart.Bus.SetCLK_CONF_RX_SCLK_EN(0) uart.Bus.SetCLK_CONF_RX_SCLK_EN(0)
@@ -395,7 +395,7 @@ func initUARTClock(bus *esp.UART_Type, regs registerSet) {
// synchronize core register // synchronize core register
bus.SetID_REG_UPDATE(0) bus.SetID_REG_UPDATE(0)
// enable RTC clock // enable RTC clock
esp.RTC_CNTL.SetCLK_CONF_DIG_CLK8M_EN(1) esp.RTC_CNTL.SetRTC_CLK_CONF_DIG_CLK8M_EN(1)
// wait for Core Clock to ready for configuration // wait for Core Clock to ready for configuration
for bus.GetID_REG_UPDATE() > 0 { for bus.GetID_REG_UPDATE() > 0 {
riscv.Asm("nop") riscv.Asm("nop")
@@ -419,7 +419,7 @@ func (uart *UART) setupPins(config UARTConfig, regs registerSet) {
// link TX with GPIO signal X (technical reference manual 5.10) (this is not interrupt signal!) // link TX with GPIO signal X (technical reference manual 5.10) (this is not interrupt signal!)
config.TX.outFunc().Set(regs.gpioMatrixSignal) config.TX.outFunc().Set(regs.gpioMatrixSignal)
// link RX with GPIO signal X and route signals via GPIO matrix (GPIO_SIGn_IN_SEL 0x40) // link RX with GPIO signal X and route signals via GPIO matrix (GPIO_SIGn_IN_SEL 0x40)
inFunc(regs.gpioMatrixSignal).Set(esp.GPIO_FUNC_IN_SEL_CFG_SEL | uint32(config.RX)) inFunc(regs.gpioMatrixSignal).Set(esp.GPIO_FUNC_IN_SEL_CFG_SIG_IN_SEL | uint32(config.RX))
} }
func (uart *UART) configureInterrupt(intrMapReg *volatile.Register32) { // Disable all UART interrupts func (uart *UART) configureInterrupt(intrMapReg *volatile.Register32) { // Disable all UART interrupts
@@ -611,8 +611,8 @@ func GetRNG() (ret uint32, err error) {
initADCClock() initADCClock()
// ensure fast RTC clock is enabled // ensure fast RTC clock is enabled
if esp.RTC_CNTL.GetCLK_CONF_DIG_CLK8M_EN() == 0 { if esp.RTC_CNTL.GetRTC_CLK_CONF_DIG_CLK8M_EN() == 0 {
esp.RTC_CNTL.SetCLK_CONF_DIG_CLK8M_EN(1) esp.RTC_CNTL.SetRTC_CLK_CONF_DIG_CLK8M_EN(1)
} }
return esp.APB_CTRL.GetRND_DATA(), nil return esp.APB_CTRL.GetRND_DATA(), nil
+59 -59
View File
@@ -52,22 +52,22 @@ func (i2c *I2C) Configure(config I2CConfig) error {
//go:inline //go:inline
func (i2c *I2C) initClock(config I2CConfig) { func (i2c *I2C) initClock(config I2CConfig) {
// reset I2C clock // reset I2C clock
esp.SYSTEM.SetPERIP_RST_EN0_I2C_EXT0_RST(1) esp.SYSTEM.SetPERIP_RST_EN0_EXT0_RST(1)
esp.SYSTEM.SetPERIP_CLK_EN0_I2C_EXT0_CLK_EN(1) esp.SYSTEM.SetPERIP_CLK_EN0_EXT0_CLK_EN(1)
esp.SYSTEM.SetPERIP_RST_EN0_I2C_EXT0_RST(0) esp.SYSTEM.SetPERIP_RST_EN0_EXT0_RST(0)
// disable interrupts // disable interrupts
esp.I2C0.INT_ENA.ClearBits(0x3fff) esp.I2C.INT_ENA.ClearBits(0x3fff)
esp.I2C0.INT_CLR.ClearBits(0x3fff) esp.I2C.INT_CLR.ClearBits(0x3fff)
esp.I2C0.SetCLK_CONF_SCLK_SEL(i2cClkSource) esp.I2C.SetCLK_CONF_SCLK_SEL(i2cClkSource)
esp.I2C0.SetCLK_CONF_SCLK_ACTIVE(1) esp.I2C.SetCLK_CONF_SCLK_ACTIVE(1)
esp.I2C0.SetCLK_CONF_SCLK_DIV_NUM(i2cClkSourceFrequency / (config.Frequency * 1024)) esp.I2C.SetCLK_CONF_SCLK_DIV_NUM(i2cClkSourceFrequency / (config.Frequency * 1024))
esp.I2C0.SetCTR_CLK_EN(1) esp.I2C.SetCTR_CLK_EN(1)
} }
//go:inline //go:inline
func (i2c *I2C) initNoiseFilter() { func (i2c *I2C) initNoiseFilter() {
esp.I2C0.FILTER_CFG.Set(0x377) esp.I2C.FILTER_CFG.Set(0x377)
} }
//go:inline //go:inline
@@ -83,13 +83,13 @@ func (i2c *I2C) initPins(config I2CConfig) {
muxConfig |= 1 << esp.IO_MUX_GPIO_FUN_DRV_Pos muxConfig |= 1 << esp.IO_MUX_GPIO_FUN_DRV_Pos
config.SDA.mux().Set(muxConfig) config.SDA.mux().Set(muxConfig)
config.SDA.outFunc().Set(54) config.SDA.outFunc().Set(54)
inFunc(54).Set(uint32(esp.GPIO_FUNC_IN_SEL_CFG_SEL | config.SDA)) inFunc(54).Set(uint32(esp.GPIO_FUNC_IN_SEL_CFG_SIG_IN_SEL | config.SDA))
config.SDA.Set(true) config.SDA.Set(true)
// Configure the pad with the given IO mux configuration. // Configure the pad with the given IO mux configuration.
config.SDA.pinReg().SetBits(esp.GPIO_PIN_PAD_DRIVER) config.SDA.pinReg().SetBits(esp.GPIO_PIN_PIN_PAD_DRIVER)
esp.GPIO.ENABLE.SetBits(1 << int(config.SDA)) esp.GPIO.ENABLE.SetBits(1 << int(config.SDA))
esp.I2C0.SetCTR_SDA_FORCE_OUT(1) esp.I2C.SetCTR_SDA_FORCE_OUT(1)
// SCL // SCL
muxConfig = function << esp.IO_MUX_GPIO_MCU_SEL_Pos muxConfig = function << esp.IO_MUX_GPIO_MCU_SEL_Pos
@@ -102,10 +102,10 @@ func (i2c *I2C) initPins(config I2CConfig) {
inFunc(53).Set(uint32(config.SCL)) inFunc(53).Set(uint32(config.SCL))
config.SCL.Set(true) config.SCL.Set(true)
// Configure the pad with the given IO mux configuration. // Configure the pad with the given IO mux configuration.
config.SCL.pinReg().SetBits(esp.GPIO_PIN_PAD_DRIVER) config.SCL.pinReg().SetBits(esp.GPIO_PIN_PIN_PAD_DRIVER)
esp.GPIO.ENABLE.SetBits(1 << int(config.SCL)) esp.GPIO.ENABLE.SetBits(1 << int(config.SCL))
esp.I2C0.SetCTR_SCL_FORCE_OUT(1) esp.I2C.SetCTR_SCL_FORCE_OUT(1)
} }
//go:inline //go:inline
@@ -127,48 +127,48 @@ func (i2c *I2C) initFrequency(config I2CConfig) {
setup := halfCycle setup := halfCycle
hold := halfCycle hold := halfCycle
esp.I2C0.SetSCL_LOW_PERIOD(sclLow - 1) esp.I2C.SetSCL_LOW_PERIOD(sclLow - 1)
esp.I2C0.SetSCL_HIGH_PERIOD(sclHigh) esp.I2C.SetSCL_HIGH_PERIOD(sclHigh)
esp.I2C0.SetSCL_HIGH_PERIOD_SCL_WAIT_HIGH_PERIOD(25) esp.I2C.SetSCL_HIGH_PERIOD_SCL_WAIT_HIGH_PERIOD(25)
esp.I2C0.SetSCL_RSTART_SETUP_TIME(setup) esp.I2C.SetSCL_RSTART_SETUP_TIME(setup)
esp.I2C0.SetSCL_STOP_SETUP_TIME(setup) esp.I2C.SetSCL_STOP_SETUP_TIME(setup)
esp.I2C0.SetSCL_START_HOLD_TIME(hold - 1) esp.I2C.SetSCL_START_HOLD_TIME(hold - 1)
esp.I2C0.SetSCL_STOP_HOLD_TIME(hold - 1) esp.I2C.SetSCL_STOP_HOLD_TIME(hold - 1)
esp.I2C0.SetSDA_SAMPLE_TIME(sda_sample) esp.I2C.SetSDA_SAMPLE_TIME(sda_sample)
esp.I2C0.SetSDA_HOLD_TIME(sdaHold) esp.I2C.SetSDA_HOLD_TIME(sdaHold)
} }
//go:inline //go:inline
func (i2c *I2C) startMaster() { func (i2c *I2C) startMaster() {
// FIFO mode for data // FIFO mode for data
esp.I2C0.SetFIFO_CONF_NONFIFO_EN(0) esp.I2C.SetFIFO_CONF_NONFIFO_EN(0)
// Reset TX & RX buffers // Reset TX & RX buffers
esp.I2C0.SetFIFO_CONF_RX_FIFO_RST(1) esp.I2C.SetFIFO_CONF_RX_FIFO_RST(1)
esp.I2C0.SetFIFO_CONF_RX_FIFO_RST(0) esp.I2C.SetFIFO_CONF_RX_FIFO_RST(0)
esp.I2C0.SetFIFO_CONF_TX_FIFO_RST(1) esp.I2C.SetFIFO_CONF_TX_FIFO_RST(1)
esp.I2C0.SetFIFO_CONF_TX_FIFO_RST(0) esp.I2C.SetFIFO_CONF_TX_FIFO_RST(0)
// set timeout value // set timeout value
esp.I2C0.TO.Set(0x10) esp.I2C.TO.Set(0x10)
// enable master mode // enable master mode
esp.I2C0.CTR.Set(0x113) esp.I2C.CTR.Set(0x113)
esp.I2C0.SetCTR_CONF_UPGATE(1) esp.I2C.SetCTR_CONF_UPGATE(1)
resetMaster() resetMaster()
} }
//go:inline //go:inline
func resetMaster() { func resetMaster() {
// reset FSM // reset FSM
esp.I2C0.SetCTR_FSM_RST(1) esp.I2C.SetCTR_FSM_RST(1)
// clear the bus // clear the bus
esp.I2C0.SetSCL_SP_CONF_SCL_RST_SLV_NUM(9) esp.I2C.SetSCL_SP_CONF_SCL_RST_SLV_NUM(9)
esp.I2C0.SetSCL_SP_CONF_SCL_RST_SLV_EN(1) esp.I2C.SetSCL_SP_CONF_SCL_RST_SLV_EN(1)
esp.I2C0.SetSCL_STRETCH_CONF_SLAVE_SCL_STRETCH_EN(1) esp.I2C.SetSCL_STRETCH_CONF_SLAVE_SCL_STRETCH_EN(1)
esp.I2C0.SetCTR_CONF_UPGATE(1) esp.I2C.SetCTR_CONF_UPGATE(1)
esp.I2C0.FILTER_CFG.Set(0x377) esp.I2C.FILTER_CFG.Set(0x377)
// wait for SCL_RST_SLV_EN // wait for SCL_RST_SLV_EN
for esp.I2C0.GetSCL_SP_CONF_SCL_RST_SLV_EN() != 0 { for esp.I2C.GetSCL_SP_CONF_SCL_RST_SLV_EN() != 0 {
} }
esp.I2C0.SetSCL_SP_CONF_SCL_RST_SLV_NUM(0) esp.I2C.SetSCL_SP_CONF_SCL_RST_SLV_NUM(0)
} }
type i2cCommandType = uint32 type i2cCommandType = uint32
@@ -194,13 +194,13 @@ func nanotime() int64
func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
const intMask = esp.I2C_INT_STATUS_END_DETECT_INT_ST_Msk | esp.I2C_INT_STATUS_TRANS_COMPLETE_INT_ST_Msk | esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk | esp.I2C_INT_STATUS_NACK_INT_ST_Msk const intMask = esp.I2C_INT_STATUS_END_DETECT_INT_ST_Msk | esp.I2C_INT_STATUS_TRANS_COMPLETE_INT_ST_Msk | esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk | esp.I2C_INT_STATUS_NACK_INT_ST_Msk
esp.I2C0.INT_CLR.SetBits(intMask) esp.I2C.INT_CLR.SetBits(intMask)
esp.I2C0.INT_ENA.SetBits(intMask) esp.I2C.INT_ENA.SetBits(intMask)
esp.I2C0.SetCTR_CONF_UPGATE(1) esp.I2C.SetCTR_CONF_UPGATE(1)
defer func() { defer func() {
esp.I2C0.INT_CLR.SetBits(intMask) esp.I2C.INT_CLR.SetBits(intMask)
esp.I2C0.INT_ENA.ClearBits(intMask) esp.I2C.INT_ENA.ClearBits(intMask)
}() }()
timeoutNS := int64(timeoutMS) * 1000000 timeoutNS := int64(timeoutMS) * 1000000
@@ -208,7 +208,7 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
needRestart := false needRestart := false
readLast := false readLast := false
var readTo []byte var readTo []byte
for cmdIdx, reg := 0, &esp.I2C0.COMD0; cmdIdx < len(cmd); { for cmdIdx, reg := 0, &esp.I2C.COMD0; cmdIdx < len(cmd); {
c := &cmd[cmdIdx] c := &cmd[cmdIdx]
switch c.cmd { switch c.cmd {
@@ -221,13 +221,13 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
count := 32 count := 32
if needAddress { if needAddress {
needAddress = false needAddress = false
esp.I2C0.SetDATA_FIFO_RDATA((uint32(addr) & 0x7f) << 1) esp.I2C.SetFIFO_DATA_FIFO_RDATA((uint32(addr) & 0x7f) << 1)
count-- count--
esp.I2C0.SLAVE_ADDR.Set(uint32(addr)) esp.I2C.SLAVE_ADDR.Set(uint32(addr))
esp.I2C0.SetCTR_CONF_UPGATE(1) esp.I2C.SetCTR_CONF_UPGATE(1)
} }
for ; count > 0 && c.head < len(c.data); count, c.head = count-1, c.head+1 { for ; count > 0 && c.head < len(c.data); count, c.head = count-1, c.head+1 {
esp.I2C0.SetDATA_FIFO_RDATA(uint32(c.data[c.head])) esp.I2C.SetFIFO_DATA_FIFO_RDATA(uint32(c.data[c.head]))
} }
reg.Set(i2cCMD_WRITE | uint32(32-count)) reg.Set(i2cCMD_WRITE | uint32(32-count))
reg = nextAddress(reg) reg = nextAddress(reg)
@@ -243,8 +243,8 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
case i2cCMD_READ: case i2cCMD_READ:
if needAddress { if needAddress {
needAddress = false needAddress = false
esp.I2C0.SetDATA_FIFO_RDATA((uint32(addr)&0x7f)<<1 | 1) esp.I2C.SetFIFO_DATA_FIFO_RDATA((uint32(addr)&0x7f)<<1 | 1)
esp.I2C0.SLAVE_ADDR.Set(uint32(addr)) esp.I2C.SLAVE_ADDR.Set(uint32(addr))
reg.Set(i2cCMD_WRITE | 1) reg.Set(i2cCMD_WRITE | 1)
reg = nextAddress(reg) reg = nextAddress(reg)
} }
@@ -256,7 +256,7 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
reg.Set(i2cCMD_WRITE | 1) reg.Set(i2cCMD_WRITE | 1)
reg = nextAddress(reg) reg = nextAddress(reg)
esp.I2C0.SetDATA_FIFO_RDATA((uint32(addr)&0x7f)<<1 | 1) esp.I2C.SetFIFO_DATA_FIFO_RDATA((uint32(addr)&0x7f)<<1 | 1)
needRestart = false needRestart = false
} }
count := 32 count := 32
@@ -291,11 +291,11 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
} }
if reg == nil { if reg == nil {
// transmit now // transmit now
esp.I2C0.SetCTR_CONF_UPGATE(1) esp.I2C.SetCTR_CONF_UPGATE(1)
esp.I2C0.SetCTR_TRANS_START(1) esp.I2C.SetCTR_TRANS_START(1)
end := nanotime() + timeoutNS end := nanotime() + timeoutNS
var mask uint32 var mask uint32
for mask = esp.I2C0.INT_STATUS.Get(); mask&intMask == 0; mask = esp.I2C0.INT_STATUS.Get() { for mask = esp.I2C.INT_STATUS.Get(); mask&intMask == 0; mask = esp.I2C.INT_STATUS.Get() {
if nanotime() > end { if nanotime() > end {
if readTo != nil { if readTo != nil {
return errI2CReadTimeout return errI2CReadTimeout
@@ -312,13 +312,13 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
} }
return errI2CWriteTimeout return errI2CWriteTimeout
} }
esp.I2C0.INT_CLR.SetBits(intMask) esp.I2C.INT_CLR.SetBits(intMask)
for i := 0; i < len(readTo); i++ { for i := 0; i < len(readTo); i++ {
readTo[i] = byte(esp.I2C0.GetDATA_FIFO_RDATA() & 0xff) readTo[i] = byte(esp.I2C.GetFIFO_DATA_FIFO_RDATA() & 0xff)
c.head++ c.head++
} }
readTo = nil readTo = nil
reg = &esp.I2C0.COMD0 reg = &esp.I2C.COMD0
} }
} }
return nil return nil
+2 -2
View File
@@ -201,7 +201,7 @@ func (spi SPI) Configure(config SPIConfig) error {
// configure esp32c3 gpio pin matrix // configure esp32c3 gpio pin matrix
config.SDI.Configure(PinConfig{Mode: PinInput}) config.SDI.Configure(PinConfig{Mode: PinInput})
inFunc(FSPIQ_IN_IDX).Set(esp.GPIO_FUNC_IN_SEL_CFG_SEL | uint32(config.SDI)) inFunc(FSPIQ_IN_IDX).Set(esp.GPIO_FUNC_IN_SEL_CFG_SIG_IN_SEL | uint32(config.SDI))
config.SDO.Configure(PinConfig{Mode: PinOutput}) config.SDO.Configure(PinConfig{Mode: PinOutput})
config.SDO.outFunc().Set(FSPID_OUT_IDX) config.SDO.outFunc().Set(FSPID_OUT_IDX)
config.SCK.Configure(PinConfig{Mode: PinOutput}) config.SCK.Configure(PinConfig{Mode: PinOutput})
@@ -234,7 +234,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
return byte(spi.Bus.GetW0()), nil return byte(spi.Bus.GetW0()), nil
} }
// Tx handles read/write operation for SPI interface. Since SPI is a synchronous write/read // Tx handles read/write operation for SPI interface. Since SPI is a syncronous write/read
// interface, there must always be the same number of bytes written as bytes read. // interface, there must always be the same number of bytes written as bytes read.
// This is accomplished by sending zero bits if r is bigger than w or discarding // This is accomplished by sending zero bits if r is bigger than w or discarding
// the incoming data if w is bigger than r. // the incoming data if w is bigger than r.

Some files were not shown because too many files have changed in this diff Show More