mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-30 08:38:41 +00:00
Compare commits
156 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8615d1007 | |||
| 9245337ecf | |||
| 8170f59440 | |||
| 622de53854 | |||
| 6cd9e3c348 | |||
| 33e2411b6a | |||
| fb1fc267ab | |||
| 490e377bba | |||
| fcedf0beaa | |||
| 4dadb31e18 | |||
| 5b81b835ba | |||
| a9a6d0ee63 | |||
| 19d5e05e37 | |||
| 9e599bac49 | |||
| 81e325205f | |||
| 71cbb1495e | |||
| efc824a103 | |||
| cb4f3f12e6 | |||
| d1b470f04e | |||
| 7aaa9e45a6 | |||
| 5c9930df3f | |||
| cf6b544cd9 | |||
| 097f628955 | |||
| 20a1c730a1 | |||
| 04f65f1189 | |||
| 2ce17a1892 | |||
| 0b9b293651 | |||
| f20c932bb9 | |||
| e7227df80d | |||
| b99175a436 | |||
| de3ffe0af7 | |||
| 1e47d9efac | |||
| 8a2e7bac04 | |||
| ae13db917f | |||
| 98dbbbfda6 | |||
| 475135f546 | |||
| 88fd2823df | |||
| 57a5b833b2 | |||
| c810628a20 | |||
| 51238fba50 | |||
| 7f829fe153 | |||
| 946184b8ba | |||
| 753162f4e0 | |||
| 0e6d2af028 | |||
| 0df4a7a35f | |||
| 9a17698d6a | |||
| 3ee47a9c1b | |||
| da7db81087 | |||
| 098fb5f39c | |||
| 47a975a44f | |||
| 83252448b0 | |||
| 222977a642 | |||
| 58565fa46d | |||
| ecaf9461ce | |||
| ae01904ab0 | |||
| 2194d447e9 | |||
| a21a039ac7 | |||
| a761f556ff | |||
| 29d65cb637 | |||
| 63005622ae | |||
| 510f145a3a | |||
| e5e324f93e | |||
| 4fa1fc6e72 | |||
| ccb803e35d | |||
| d1ac0138e6 | |||
| b132b5bc60 | |||
| 743254d5bc | |||
| 9d625a1ccb | |||
| b75f042c23 | |||
| 32c7f3baf9 | |||
| 1dc85ded47 | |||
| 26a0819119 | |||
| b59a46eef0 | |||
| 8a410b993b | |||
| e412a63a1c | |||
| a81face618 | |||
| 0ac216b093 | |||
| 9575fe628f | |||
| f4e8ea0d23 | |||
| 2d03f65d67 | |||
| 154d4a781f | |||
| b5ab114514 | |||
| 0a7e74045a | |||
| f05b378b89 | |||
| 888ca4ab0c | |||
| 903bebd071 | |||
| 848c3e55a9 | |||
| 3650c2c739 | |||
| d4e04e4e49 | |||
| e41e5106cc | |||
| ca03b8d442 | |||
| d1c4ed664e | |||
| fdaddf6917 | |||
| 50a677e9b7 | |||
| 6ad6f14a04 | |||
| 19e0f4709e | |||
| ae5b297d59 | |||
| ca1a282495 | |||
| 01f5c51b77 | |||
| ad6adfd8ff | |||
| 9815628930 | |||
| 05495c4282 | |||
| d606315515 | |||
| 60fdf81209 | |||
| 39433a3553 | |||
| 04d097f4ea | |||
| 4750635a20 | |||
| 59218cd784 | |||
| 079a789d49 | |||
| ca8e1b075a | |||
| 33024d4aa2 | |||
| 49df129ccd | |||
| 3088dcadec | |||
| 7ed7e6cb11 | |||
| 0b94e486c1 | |||
| 5ff76aacab | |||
| 3ee7599a09 | |||
| 43a66b39cc | |||
| 66b21b4c86 | |||
| a9568932be | |||
| f2fbd1dd7e | |||
| 21a9aa8102 | |||
| e1757e0347 | |||
| a05fc10699 | |||
| a685217743 | |||
| ad0c15080a | |||
| 5446c6927e | |||
| 53c83fa445 | |||
| 804dc8b1f9 | |||
| e1ceca1931 | |||
| 6620c4d2aa | |||
| ccc604d2e0 | |||
| dfab1aa717 | |||
| 75bcbbe6d8 | |||
| d599959711 | |||
| 7814964693 | |||
| 2fe4a9be71 | |||
| 163631df9e | |||
| 9ad96fd809 | |||
| 4a658b9082 | |||
| 34e0961a79 | |||
| 875d36cba0 | |||
| 1a6bed3305 | |||
| e0b9b1ecd1 | |||
| 149c9533e2 | |||
| a85df334e6 | |||
| 89a9c09af5 | |||
| 1451eeaf41 | |||
| e8c84d24a0 | |||
| a4f3457747 | |||
| aa3481e06a | |||
| 2136cb2f59 | |||
| acb3cfba6d | |||
| 8cfc4005d3 | |||
| 2dbe29327a | |||
| de0fbb5e2f |
+111
-23
@@ -44,28 +44,40 @@ commands:
|
||||
command: |
|
||||
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
||||
sudo apt install ./google-chrome-stable_current_amd64.deb
|
||||
install-xtensa-toolchain:
|
||||
parameters:
|
||||
variant:
|
||||
type: string
|
||||
steps:
|
||||
- run:
|
||||
name: "Install Xtensa toolchain"
|
||||
command: |
|
||||
curl -L https://github.com/espressif/crosstool-NG/releases/download/esp-2020r2/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<<parameters.variant>>.tar.gz -o xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<<parameters.variant>>.tar.gz
|
||||
sudo tar -C /usr/local -xf xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<<parameters.variant>>.tar.gz
|
||||
sudo ln -s /usr/local/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld /usr/local/bin/xtensa-esp32-elf-ld
|
||||
rm xtensa-esp32-elf-gcc8_2_0-esp-2020r2-<<parameters.variant>>.tar.gz
|
||||
llvm-source-linux:
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- llvm-source-10-v0
|
||||
- llvm-source-10-v1
|
||||
- run:
|
||||
name: "Fetch LLVM source"
|
||||
command: make llvm-source
|
||||
- save_cache:
|
||||
key: llvm-source-10-v0
|
||||
key: llvm-source-10-v1
|
||||
paths:
|
||||
- llvm-project
|
||||
build-wasi-libc:
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- wasi-libc-sysroot-v2
|
||||
- wasi-libc-sysroot-v3
|
||||
- run:
|
||||
name: "Build wasi-libc"
|
||||
command: make wasi-libc
|
||||
- save_cache:
|
||||
key: wasi-libc-sysroot-v2
|
||||
key: wasi-libc-sysroot-v3
|
||||
paths:
|
||||
- lib/wasi-libc/sysroot
|
||||
test-linux:
|
||||
@@ -87,22 +99,21 @@ commands:
|
||||
- run: go install -tags=llvm<<parameters.llvm>> .
|
||||
- restore_cache:
|
||||
keys:
|
||||
- wasi-libc-sysroot-systemclang-v1
|
||||
- wasi-libc-sysroot-systemclang-v2
|
||||
- run: make wasi-libc
|
||||
- save_cache:
|
||||
key: wasi-libc-sysroot-systemclang-v1
|
||||
key: wasi-libc-sysroot-systemclang-v2
|
||||
paths:
|
||||
- lib/wasi-libc/sysroot
|
||||
- run: tinygo clean
|
||||
- run: go test -v -tags=llvm<<parameters.llvm>> ./cgo ./compileopts ./interp ./transform .
|
||||
- run: make gen-device -j4
|
||||
- run: make smoketest
|
||||
- run: make smoketest XTENSA=0
|
||||
- run: make tinygo-test
|
||||
- run: make wasmtest
|
||||
- save_cache:
|
||||
key: go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
|
||||
paths:
|
||||
- ~/.cache/go-build
|
||||
- ~/.cache/tinygo
|
||||
- /go/pkg/mod
|
||||
- run: make fmt-check
|
||||
assert-test-linux:
|
||||
@@ -123,6 +134,8 @@ commands:
|
||||
gcc-avr \
|
||||
avr-libc
|
||||
- install-node
|
||||
- install-xtensa-toolchain:
|
||||
variant: "linux-amd64"
|
||||
- restore_cache:
|
||||
keys:
|
||||
- go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_PREVIOUS_BUILD_NUM }}
|
||||
@@ -130,7 +143,7 @@ commands:
|
||||
- llvm-source-linux
|
||||
- restore_cache:
|
||||
keys:
|
||||
- llvm-build-10-linux-v0-assert
|
||||
- llvm-build-10-linux-v1-assert
|
||||
- run:
|
||||
name: "Build LLVM"
|
||||
command: |
|
||||
@@ -148,7 +161,7 @@ commands:
|
||||
make ASSERT=1 llvm-build
|
||||
fi
|
||||
- save_cache:
|
||||
key: llvm-build-10-linux-v0-assert
|
||||
key: llvm-build-10-linux-v1-assert
|
||||
paths:
|
||||
llvm-build
|
||||
- run: make ASSERT=1
|
||||
@@ -160,7 +173,6 @@ commands:
|
||||
key: go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
|
||||
paths:
|
||||
- ~/.cache/go-build
|
||||
- ~/.cache/tinygo
|
||||
- /go/pkg/mod
|
||||
- run: make gen-device -j4
|
||||
- run: make smoketest TINYGO=build/tinygo
|
||||
@@ -182,6 +194,8 @@ commands:
|
||||
gcc-avr \
|
||||
avr-libc
|
||||
- install-node
|
||||
- install-xtensa-toolchain:
|
||||
variant: "linux-amd64"
|
||||
- restore_cache:
|
||||
keys:
|
||||
- go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_PREVIOUS_BUILD_NUM }}
|
||||
@@ -189,7 +203,7 @@ commands:
|
||||
- llvm-source-linux
|
||||
- restore_cache:
|
||||
keys:
|
||||
- llvm-build-10-linux-v0
|
||||
- llvm-build-10-linux-v1
|
||||
- run:
|
||||
name: "Build LLVM"
|
||||
command: |
|
||||
@@ -207,7 +221,7 @@ commands:
|
||||
make llvm-build
|
||||
fi
|
||||
- save_cache:
|
||||
key: llvm-build-10-linux-v0
|
||||
key: llvm-build-10-linux-v1
|
||||
paths:
|
||||
llvm-build
|
||||
- build-wasi-libc
|
||||
@@ -233,7 +247,6 @@ commands:
|
||||
key: go-cache-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
|
||||
paths:
|
||||
- ~/.cache/go-build
|
||||
- ~/.cache/tinygo
|
||||
- /go/pkg/mod
|
||||
- run:
|
||||
name: "Extract release tarball"
|
||||
@@ -254,23 +267,25 @@ commands:
|
||||
sudo tar -C /usr/local -xzf go1.14.darwin-amd64.tar.gz
|
||||
ln -s /usr/local/go/bin/go /usr/local/bin/go
|
||||
HOMEBREW_NO_AUTO_UPDATE=1 brew install qemu
|
||||
- install-xtensa-toolchain:
|
||||
variant: "macos"
|
||||
- restore_cache:
|
||||
keys:
|
||||
- go-cache-macos-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_PREVIOUS_BUILD_NUM }}
|
||||
- go-cache-macos-v2-{{ checksum "go.mod" }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- llvm-source-10-macos-v0
|
||||
- llvm-source-10-macos-v1
|
||||
- run:
|
||||
name: "Fetch LLVM source"
|
||||
command: make llvm-source
|
||||
- save_cache:
|
||||
key: llvm-source-10-macos-v0
|
||||
key: llvm-source-10-macos-v1
|
||||
paths:
|
||||
- llvm-project
|
||||
- restore_cache:
|
||||
keys:
|
||||
- llvm-build-10-macos-v0
|
||||
- llvm-build-10-macos-v1
|
||||
- run:
|
||||
name: "Build LLVM"
|
||||
command: |
|
||||
@@ -282,17 +297,17 @@ commands:
|
||||
make llvm-build
|
||||
fi
|
||||
- save_cache:
|
||||
key: llvm-build-10-macos-v0
|
||||
key: llvm-build-10-macos-v1
|
||||
paths:
|
||||
llvm-build
|
||||
- restore_cache:
|
||||
keys:
|
||||
- wasi-libc-sysroot-macos-v1
|
||||
- wasi-libc-sysroot-macos-v2
|
||||
- run:
|
||||
name: "Build wasi-libc"
|
||||
command: make wasi-libc
|
||||
- save_cache:
|
||||
key: wasi-libc-sysroot-macos-v1
|
||||
key: wasi-libc-sysroot-macos-v2
|
||||
paths:
|
||||
- lib/wasi-libc/sysroot
|
||||
- run:
|
||||
@@ -317,9 +332,61 @@ commands:
|
||||
key: go-cache-macos-v2-{{ checksum "go.mod" }}-{{ .Environment.CIRCLE_BUILD_NUM }}
|
||||
paths:
|
||||
- ~/.cache/go-build
|
||||
- ~/.cache/tinygo
|
||||
- /go/pkg/mod
|
||||
|
||||
arch-release:
|
||||
steps:
|
||||
- run:
|
||||
name: Install dependencies
|
||||
command: pacman -Sy --noconfirm openssh git pacman-contrib binutils
|
||||
- run:
|
||||
name: Create TinyGo user
|
||||
command: useradd -m tinygo
|
||||
- run:
|
||||
name: Start SSH Agent
|
||||
user: tinygo
|
||||
command: eval $(ssh-agent -s)
|
||||
- run:
|
||||
name: Add ARCH_RELEASE_SSH_PRIVATE_KEY identity
|
||||
user: tinygo
|
||||
command: echo "${ARCH_RELEASE_SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
|
||||
- run:
|
||||
name: Create SSH directory
|
||||
user: tinygo
|
||||
command: mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
||||
- run:
|
||||
name: Add aur.archlinux.org to known hosts
|
||||
user: tinygo
|
||||
command: ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts
|
||||
- run:
|
||||
name: Clone tinygo-bin repo
|
||||
user: tinygo
|
||||
command: git clone ssh://aur@aur.archlinux.org/tinygo-bin.git ~/tinygo-bin
|
||||
- run:
|
||||
name: Update package version
|
||||
user: tinygo
|
||||
command: sed -i -E "s/(pkgver=)(.*)$/\1${CIRCLE_TAG}/" ~/tinygo-bin/PKGBUILD
|
||||
- run:
|
||||
name: Update file checksums
|
||||
user: tinygo
|
||||
command: cd ~/tinygo-bin && updpkgsums
|
||||
- run:
|
||||
name: Update .SRCINFO
|
||||
user: tinygo
|
||||
command: cd ~/tinygo-bin && makepkg --printsrcinfo > .SRCINFO
|
||||
# Commit the update
|
||||
- run:
|
||||
name: Set git commit config
|
||||
user: tinygo
|
||||
command: |
|
||||
git config --global user.email "tinygo-bot@tinygo.org" &&
|
||||
git config --global user.name "TinyGo Release Bot"
|
||||
- run:
|
||||
name: Commit and push changes
|
||||
user: tinygo
|
||||
command: |
|
||||
cd ~/tinygo-bin &&
|
||||
git commit -a -m "Update tinygo-bin to v${CIRCLE_TAG}" &&
|
||||
git push origin master
|
||||
|
||||
jobs:
|
||||
test-llvm9-go111:
|
||||
@@ -346,6 +413,12 @@ jobs:
|
||||
steps:
|
||||
- test-linux:
|
||||
llvm: "10"
|
||||
test-llvm10-go115:
|
||||
docker:
|
||||
- image: circleci/golang:1.15-buster
|
||||
steps:
|
||||
- test-linux:
|
||||
llvm: "10"
|
||||
assert-test-linux:
|
||||
docker:
|
||||
- image: circleci/golang:1.14-stretch
|
||||
@@ -361,6 +434,11 @@ jobs:
|
||||
xcode: "10.1.0"
|
||||
steps:
|
||||
- build-macos
|
||||
arch-release:
|
||||
docker:
|
||||
- image: archlinux:latest
|
||||
steps:
|
||||
- arch-release
|
||||
|
||||
|
||||
|
||||
@@ -372,6 +450,16 @@ workflows:
|
||||
- test-llvm10-go112
|
||||
- test-llvm10-go113
|
||||
- test-llvm10-go114
|
||||
- test-llvm10-go115
|
||||
- build-linux
|
||||
- build-macos
|
||||
- assert-test-linux
|
||||
release:
|
||||
jobs:
|
||||
- arch-release:
|
||||
filters:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
tags:
|
||||
# Runs on every semver release
|
||||
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
|
||||
|
||||
@@ -3,14 +3,19 @@ docs/_build
|
||||
src/device/avr/*.go
|
||||
src/device/avr/*.ld
|
||||
src/device/avr/*.s
|
||||
src/device/esp/*.go
|
||||
src/device/nrf/*.go
|
||||
src/device/nrf/*.s
|
||||
src/device/nxp/*.go
|
||||
src/device/nxp/*.s
|
||||
src/device/sam/*.go
|
||||
src/device/sam/*.s
|
||||
src/device/sifive/*.go
|
||||
src/device/sifive/*.s
|
||||
src/device/stm32/*.go
|
||||
src/device/stm32/*.s
|
||||
src/device/kendryte/*.go
|
||||
src/device/kendryte/*.s
|
||||
vendor
|
||||
llvm-build
|
||||
llvm-project
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
url = https://github.com/avr-rust/avr-mcu.git
|
||||
[submodule "lib/cmsis-svd"]
|
||||
path = lib/cmsis-svd
|
||||
url = https://github.com/posborne/cmsis-svd
|
||||
url = https://github.com/tinygo-org/cmsis-svd
|
||||
[submodule "lib/compiler-rt"]
|
||||
path = lib/compiler-rt
|
||||
url = https://github.com/llvm-mirror/compiler-rt.git
|
||||
|
||||
+12
@@ -10,6 +10,14 @@ This guide describes how to statically link TinyGo against LLVM, libclang and
|
||||
lld so that the binary can be easily moved between systems. It also shows how to
|
||||
build a release tarball that includes this binary and all necessary extra files.
|
||||
|
||||
**Note**: this documentation describes how to build a statically linked release
|
||||
tarball. If you want to develop TinyGo, you will probably want to follow a
|
||||
different guide:
|
||||
|
||||
* [Linux](https://tinygo.org/getting-started/linux/#source-install)
|
||||
* [macOS](https://tinygo.org/getting-started/macos/#source-install)
|
||||
* [Windows](https://tinygo.org/getting-started/windows/#source-install)
|
||||
|
||||
## Dependencies
|
||||
|
||||
LLVM, Clang and LLD are quite light on dependencies, requiring only standard
|
||||
@@ -84,6 +92,10 @@ Now that we have a working static build, it's time to make a release tarball:
|
||||
|
||||
make release
|
||||
|
||||
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
|
||||
|
||||
The release tarball is stored in build/release.tar.gz, and can be extracted with
|
||||
the following command (for example in ~/lib):
|
||||
|
||||
|
||||
+169
@@ -1,3 +1,172 @@
|
||||
0.15.0
|
||||
---
|
||||
|
||||
* **command-line**
|
||||
- add cached GOROOT to info subcommand
|
||||
- embed git-hash in tinygo-dev executable
|
||||
- implement tinygo targets to list usable targets
|
||||
- use simpler file copy instead of file renaming to avoid issues on nrf52840 UF2 bootloaders
|
||||
- use ToSlash() to specify program path
|
||||
- support flashing esp32/esp8266 directly from tinygo
|
||||
- when flashing call PortReset only on other than openocd
|
||||
* **compiler**
|
||||
- `compileopts`: add support for custom binary formats
|
||||
- `compiler`: improve display of goroutine wrappers
|
||||
- `interp`: don't panic in the Store method
|
||||
- `interp`: replace some panics with error messages
|
||||
- `interp`: show error line in first line of the traceback
|
||||
- `loader`: be more robust when creating the cached GOROOT
|
||||
- `loader`: rewrite/refactor much of the code to use go list directly
|
||||
- `loader`: use ioutil.TempDir to create a temporary directory
|
||||
- `stacksize`: deal with DW_CFA_advance_loc1
|
||||
* **standard library**
|
||||
- `runtime`: use waitForEvents when appropriate
|
||||
* **wasm**
|
||||
- `wasm`: Remove --no-threads from wasm-ld calls.
|
||||
- `wasm`: update wasi-libc dependency
|
||||
* **targets**
|
||||
- `arduino-mega2560`: fix flashing on Windows
|
||||
- `arm`: automatically determine stack sizes
|
||||
- `arm64`: make dynamic loader structs and constants private
|
||||
- `avr`: configure emulator in board files
|
||||
- `cortexm`: fix stack size calculation with interrupts
|
||||
- `flash`: add openocd settings to atsamd21 / atsamd51
|
||||
- `flash`: add openocd settings to nrf5
|
||||
- `microbit`: reelboard: flash using OpenOCD when needed
|
||||
- `nintendoswitch`: Add dynamic loader for runtime loading PIE sections
|
||||
- `nintendoswitch`: fix import cycle on dynamic_arm64.go
|
||||
- `nintendoswitch`: Fix invalid memory read / write in print calls
|
||||
- `nintendoswitch`: simplified assembly code
|
||||
- `nintendoswitch`: support outputting .nro files directly
|
||||
* **boards**
|
||||
- `arduino-zero`: Adding support for the Arduino Zero (#1365)
|
||||
- `atsamd2x`: fix BAUD value
|
||||
- `atsamd5x`: fix BAUD value
|
||||
- `bluepill`: Enable stm32's USART2 for the board and map it to UART1 tinygo's device
|
||||
- `device/atsamd51x`: add all remaining bitfield values for PCHCTRLm Mapping
|
||||
- `esp32`: add libgcc ROM functions to linker script
|
||||
- `esp32`: add SPI support
|
||||
- `esp32`: add support for basic GPIO
|
||||
- `esp32`: add support for the Espressif ESP32 chip
|
||||
- `esp32`: configure the I/O matrix for GPIO pins
|
||||
- `esp32`: export machine.PortMask* for bitbanging implementations
|
||||
- `esp8266`: add support for this chip
|
||||
- `machine/atsamd51x,runtime/atsamd51x`: fixes needed for full support for all PWM pins. Also adds some useful constants to clarify peripheral clock usage
|
||||
- `machine/itsybitsy-nrf52840`: add support for Adafruit Itsybitsy nrf52840 (#1243)
|
||||
- `machine/stm32f4`: refactor common code and add new build tag stm32f4 (#1332)
|
||||
- `nrf`: add SoftDevice support for the Circuit Playground Bluefruit
|
||||
- `nrf`: call sd_app_evt_wait when the SoftDevice is enabled
|
||||
- `nrf52840`: add build tags for SoftDevice support
|
||||
- `nrf52840`: use higher priority for USB-CDC code
|
||||
- `runtime/atsamd51x`: use PCHCTRL_GCLK_SERCOMX_SLOW for setting clocks on all SERCOM ports
|
||||
- `stm32f405`: add basic UART handler
|
||||
- `stm32f405`: add STM32F405 machine/runtime, and new board/target feather-stm32f405
|
||||
* **build**
|
||||
- `all`: run test binaries in the correct directory
|
||||
- `build`: Fix arch release job
|
||||
- `ci`: run `tinygo test` for known-working packages
|
||||
- `ci`: set git-fetch-depth to 1
|
||||
- `docker`: fix the problem with the wasm build (#1357)
|
||||
- `Makefile`: check whether submodules have been downloaded in some common cases
|
||||
* **docs**
|
||||
- add ESP32, ESP8266, and Adafruit Feather STM32F405 to list of supported boards
|
||||
|
||||
0.14.1
|
||||
---
|
||||
* **command-line**
|
||||
- support for Go 1.15
|
||||
* **compiler**
|
||||
- loader: work around Windows symlink limitation
|
||||
|
||||
0.14.0
|
||||
---
|
||||
* **command-line**
|
||||
- fix `getDefaultPort()` on non-English Windows locales
|
||||
- compileopts: improve error reporting of unsupported flags
|
||||
- fix test subcommand
|
||||
- use auto-retry to locate MSD for UF2 and HEX flashing
|
||||
- fix touchSerialPortAt1200bps on Windows
|
||||
- support package names with backslashes on Windows
|
||||
* **compiler**
|
||||
- fix a few crashes due to named types
|
||||
- add support for atomic operations
|
||||
- move the channel blocked list onto the stack
|
||||
- fix -gc=none
|
||||
- fix named string to `[]byte` slice conversion
|
||||
- implement func value and builtin defers
|
||||
- add proper parameter names to runtime.initAll, to fix a panic
|
||||
- builder: fix picolibc include path
|
||||
- builder: use newer version of gohex
|
||||
- builder: try to determine stack size information at compile time
|
||||
- builder: remove -opt=0
|
||||
- interp: fix sync/atomic.Value load/store methods
|
||||
- loader: add Go module support
|
||||
- transform: fix debug information in func lowering pass
|
||||
- transform: do not special-case zero or one implementations of a method call
|
||||
- transform: introduce check for method calls on nil interfaces
|
||||
- transform: gc: track 0-index GEPs to fix miscompilation
|
||||
* **cgo**
|
||||
- Add LDFlags support
|
||||
* **standard library**
|
||||
- extend stdlib to allow import of more packages
|
||||
- replace master/slave terminology with appropriate alternatives (MOSI->SDO
|
||||
etc)
|
||||
- `internal/bytealg`: reimplement bytealg in pure Go
|
||||
- `internal/task`: fix nil panic in (*internal/task.Stack).Pop
|
||||
- `os`: add Args and stub it with mock data
|
||||
- `os`: implement virtual filesystem support
|
||||
- `reflect`: add Cap and Len support for map and chan
|
||||
- `runtime`: fix return address in scheduler on RISC-V
|
||||
- `runtime`: avoid recursion in printuint64 function
|
||||
- `runtime`: replace ReadRegister with AsmFull inline assembly
|
||||
- `runtime`: fix compilation errors when using gc.extalloc
|
||||
- `runtime`: add cap and len support for chans
|
||||
- `runtime`: refactor time handling (improving accuracy)
|
||||
- `runtime`: make channels work in interrupts
|
||||
- `runtime/interrupt`: add cross-chip disable/restore interrupt support
|
||||
- `sync`: implement `sync.Cond`
|
||||
- `sync`: add WaitGroup
|
||||
* **targets**
|
||||
- `arm`: allow nesting in DisableInterrupts and EnableInterrupts
|
||||
- `arm`: make FPU configuraton consistent
|
||||
- `arm`: do not mask fault handlers in critical sections
|
||||
- `atmega2560`: fix pin mapping for pins D2, D5 and the L port
|
||||
- `atsamd`: return an error when an incorrect PWM pin is used
|
||||
- `atsamd`: add support for pin change interrupts
|
||||
- `atsamd`: add DAC support
|
||||
- `atsamd21`: add more ADC pins
|
||||
- `atsamd51`: fix ROM / RAM size on atsamd51j20
|
||||
- `atsamd51`: add more pins
|
||||
- `atsamd51`: add more ADC pins
|
||||
- `atsamd51`: add pin change interrupt settings
|
||||
- `atsamd51`: extend pinPadMapping
|
||||
- `arduino-nano33`: use (U)SB flag to ensure that device can be found when
|
||||
not on default port
|
||||
- `arduino-nano33`: remove (d)ebug flag to reduce console noise when flashing
|
||||
- `avr`: use standard pin numbering
|
||||
- `avr`: unify GPIO pin/port code
|
||||
- `avr`: add support for PinInputPullup
|
||||
- `avr`: work around codegen bug in LLVM 10
|
||||
- `avr`: fix target triple
|
||||
- `fe310`: remove extra println left in by mistake
|
||||
- `feather-nrf52840`: add support for the Feather nRF52840
|
||||
- `maixbit`: add board definition and dummy runtime
|
||||
- `nintendoswitch`: Add experimental Nintendo Switch support without CRT
|
||||
- `nrf`: expose the RAM base address
|
||||
- `nrf`: add support for pin change interrupts
|
||||
- `nrf`: add microbit-s110v8 target
|
||||
- `nrf`: fix bug in SPI.Tx
|
||||
- `nrf`: support debugging the PCA10056
|
||||
- `pygamer`: add Adafruit PyGamer suport
|
||||
- `riscv`: fix interrupt configuration bug
|
||||
- `riscv`: disable linker relaxations during gp init
|
||||
- `stm32f4disco`: add new target with ST-Link v2.1 debugger
|
||||
- `teensy36`: add Teensy 3.6 support
|
||||
- `wasm`: fix event handling
|
||||
- `wasm`: add --no-demangle linker option
|
||||
- `wioterminal`: add support for the Seeed Wio Terminal
|
||||
- `xiao`: add support for the Seeed XIAO
|
||||
|
||||
0.13.1
|
||||
---
|
||||
* **standard library**
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ Microcontrollers have lots of peripherals (I2C, SPI, ADC, etc.) and many don't h
|
||||
|
||||
## How to use our Github repository
|
||||
|
||||
The `master` branch of this repo will always have the latest released version of TinyGo. All of the active development work for the next release will take place in the `dev` branch. TinyGo will use semantic versioning and will create a tag/release for each release.
|
||||
The `release` branch of this repo will always have the latest released version of TinyGo. All of the active development work for the next release will take place in the `dev` branch. TinyGo will use semantic versioning and will create a tag/release for each release.
|
||||
|
||||
Here is how to contribute back some code or documentation:
|
||||
|
||||
|
||||
+1
-1
@@ -15,4 +15,4 @@ Ayke van Laethem <aykevanlaethem@gmail.com>
|
||||
Daniel Esteban <conejo@conejo.me>
|
||||
Loon, LLC.
|
||||
Ron Evans <ron@hybridgroup.com>
|
||||
Jaden Weiss <jaden@jadendw.dev>
|
||||
Nia Weiss <niaow1234@gmail.com>
|
||||
|
||||
+4
-1
@@ -27,7 +27,10 @@ COPY --from=tinygo-base /go/bin/tinygo /go/bin/tinygo
|
||||
COPY --from=tinygo-base /tinygo/src /tinygo/src
|
||||
COPY --from=tinygo-base /tinygo/targets /tinygo/targets
|
||||
|
||||
RUN apt-get install -y libllvm10 lld-10
|
||||
RUN cd /tinygo/ && \
|
||||
apt-get update && \
|
||||
apt-get install -y make clang-10 libllvm10 lld-10 && \
|
||||
make wasi-libc
|
||||
|
||||
# tinygo-avr stage installs the needed dependencies to compile TinyGo programs for AVR microcontrollers.
|
||||
FROM tinygo-base AS tinygo-avr
|
||||
|
||||
@@ -51,7 +51,7 @@ else
|
||||
LLVM_OPTION += '-DLLVM_ENABLE_ASSERTIONS=OFF'
|
||||
endif
|
||||
|
||||
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-avr
|
||||
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr
|
||||
|
||||
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf executionengine frontendopenmp instrumentation interpreter ipo irreader linker lto mc mcjit objcarcopts option profiledata scalaropts support target
|
||||
|
||||
@@ -118,9 +118,10 @@ fmt-check:
|
||||
@unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1
|
||||
|
||||
|
||||
gen-device: gen-device-avr gen-device-nrf gen-device-sam gen-device-sifive gen-device-stm32
|
||||
gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-stm32 gen-device-kendryte gen-device-nxp
|
||||
|
||||
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
|
||||
$(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/tiny src/device/avr/
|
||||
@@ -129,10 +130,18 @@ gen-device-avr:
|
||||
build/gen-device-svd: ./tools/gen-device-svd/*.go
|
||||
$(GO) build -o $@ ./tools/gen-device-svd/
|
||||
|
||||
gen-device-esp: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Espressif-Community -interrupts=software lib/cmsis-svd/data/Espressif-Community/ src/device/esp/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/esp
|
||||
|
||||
gen-device-nrf: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk lib/nrfx/mdk/ src/device/nrf/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/nrf
|
||||
|
||||
gen-device-nxp: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP lib/cmsis-svd/data/NXP/ src/device/nxp/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/nxp
|
||||
|
||||
gen-device-sam: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel lib/cmsis-svd/data/Atmel/ src/device/sam/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/sam
|
||||
@@ -141,6 +150,10 @@ gen-device-sifive: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/SiFive-Community -interrupts=software lib/cmsis-svd/data/SiFive-Community/ src/device/sifive/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/sifive
|
||||
|
||||
gen-device-kendryte: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Kendryte-Community -interrupts=software lib/cmsis-svd/data/Kendryte-Community/ src/device/kendryte/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/kendryte
|
||||
|
||||
gen-device-stm32: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/STMicro lib/cmsis-svd/data/STMicro/ src/device/stm32/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/stm32
|
||||
@@ -148,13 +161,13 @@ gen-device-stm32: build/gen-device-svd
|
||||
|
||||
# Get LLVM sources.
|
||||
$(LLVM_PROJECTDIR)/README.md:
|
||||
git clone -b release/10.x https://github.com/llvm/llvm-project $(LLVM_PROJECTDIR)
|
||||
git clone -b xtensa_release_10.0.1 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR)
|
||||
llvm-source: $(LLVM_PROJECTDIR)/README.md
|
||||
|
||||
# Configure LLVM.
|
||||
TINYGO_SOURCE_DIR=$(shell pwd)
|
||||
$(LLVM_BUILDDIR)/build.ninja: llvm-source
|
||||
mkdir -p $(LLVM_BUILDDIR); cd $(LLVM_BUILDDIR); cmake -G Ninja $(TINYGO_SOURCE_DIR)/$(LLVM_PROJECTDIR)/llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;RISCV;WebAssembly" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR" -DCMAKE_BUILD_TYPE=Release -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF $(LLVM_OPTION)
|
||||
mkdir -p $(LLVM_BUILDDIR); cd $(LLVM_BUILDDIR); cmake -G Ninja $(TINYGO_SOURCE_DIR)/$(LLVM_PROJECTDIR)/llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;RISCV;WebAssembly" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;Xtensa" -DCMAKE_BUILD_TYPE=Release -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF $(LLVM_OPTION)
|
||||
|
||||
# Build LLVM.
|
||||
$(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja
|
||||
@@ -165,19 +178,26 @@ $(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja
|
||||
.PHONY: wasi-libc
|
||||
wasi-libc: 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
|
||||
cd lib/wasi-libc && make -j4 WASM_CC=$(CLANG) WASM_AR=$(LLVM_AR) WASM_NM=$(LLVM_NM)
|
||||
|
||||
|
||||
# Build the Go compiler.
|
||||
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
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o build/tinygo$(EXE) -tags byollvm .
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags byollvm -ldflags="-X main.gitSha1=`git rev-parse --short HEAD`" .
|
||||
|
||||
test: wasi-libc
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test -v -tags byollvm ./cgo ./compileopts ./interp ./transform .
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test -v -buildmode exe -tags byollvm ./cgo ./compileopts ./interp ./transform .
|
||||
|
||||
# Test known-working standard library packages.
|
||||
# TODO: do this in one command, parallelize, and only show failing tests (no
|
||||
# implied -v flag).
|
||||
.PHONY: tinygo-test
|
||||
tinygo-test:
|
||||
cd tests/tinygotest && tinygo test
|
||||
$(TINYGO) test container/list
|
||||
$(TINYGO) test container/ring
|
||||
$(TINYGO) test text/scanner
|
||||
|
||||
.PHONY: smoketest
|
||||
smoketest:
|
||||
@@ -259,6 +279,10 @@ smoketest:
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=stm32f4disco examples/blinky2
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=stm32f4disco-1 examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=feather-stm32f405 examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s
|
||||
@@ -296,8 +320,26 @@ smoketest:
|
||||
$(TINYGO) build -size short -o test.hex -target=wioterminal examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=pygamer examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=xiao examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/dac
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=pyportal examples/dac
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=feather-nrf52840 examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=itsybitsy-nrf52840 examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
# test pwm
|
||||
$(TINYGO) build -size short -o test.hex -target=itsybitsy-m0 examples/pwm
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=itsybitsy-m4 examples/pwm
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=feather-m4 examples/pwm
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=pyportal examples/pwm
|
||||
@$(MD5SUM) test.hex
|
||||
ifneq ($(AVR), 0)
|
||||
$(TINYGO) build -size short -o test.hex -target=atmega1284p examples/serial
|
||||
@$(MD5SUM) test.hex
|
||||
@@ -313,11 +355,26 @@ ifneq ($(AVR), 0)
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=digispark -gc=leaking examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
endif
|
||||
ifneq ($(XTENSA), 0)
|
||||
$(TINYGO) build -size short -o test.bin -target=esp32-wroom-32 examples/blinky1
|
||||
@$(MD5SUM) test.bin
|
||||
$(TINYGO) build -size short -o test.bin -target=nodemcu examples/blinky1
|
||||
@$(MD5SUM) test.bin
|
||||
endif
|
||||
$(TINYGO) build -size short -o test.hex -target=hifive1b examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=maixbit examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -o wasm.wasm -target=wasm examples/wasm/export
|
||||
$(TINYGO) build -o wasm.wasm -target=wasm examples/wasm/main
|
||||
# test various compiler flags
|
||||
$(TINYGO) build -size short -o test.hex -target=pca10040 -gc=none -scheduler=none examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=pca10040 -opt=1 examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -o test.nro -target=nintendoswitch examples/serial
|
||||
@$(MD5SUM) test.nro
|
||||
|
||||
wasmtest:
|
||||
$(GO) test ./tests/wasm
|
||||
|
||||
@@ -43,27 +43,35 @@ See the [getting started instructions](https://tinygo.org/getting-started/) for
|
||||
|
||||
You can compile TinyGo programs for microcontrollers, WebAssembly and Linux.
|
||||
|
||||
The following 34 microcontroller boards are currently supported:
|
||||
The following 44 microcontroller boards are currently supported:
|
||||
|
||||
* [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333)
|
||||
* [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333)
|
||||
* [Adafruit CLUE Alpha](https://www.adafruit.com/product/4500)
|
||||
* [Adafruit Feather M0](https://www.adafruit.com/product/2772)
|
||||
* [Adafruit Feather M4](https://www.adafruit.com/product/3857)
|
||||
* [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
|
||||
* [Adafruit Feather STM32F405 Express](https://www.adafruit.com/product/4382)
|
||||
* [Adafruit ItsyBitsy M0](https://www.adafruit.com/product/3727)
|
||||
* [Adafruit ItsyBitsy M4](https://www.adafruit.com/product/3800)
|
||||
* [Adafruit ItsyBitsy nRF52840](https://www.adafruit.com/product/4481)
|
||||
* [Adafruit Metro M4 Express Airlift](https://www.adafruit.com/product/4000)
|
||||
* [Adafruit PyBadge](https://www.adafruit.com/product/4200)
|
||||
* [Adafruit PyGamer](https://www.adafruit.com/product/4242)
|
||||
* [Adafruit PyPortal](https://www.adafruit.com/product/4116)
|
||||
* [Adafruit Trinket M0](https://www.adafruit.com/product/3500)
|
||||
* [Arduino Mega 2560](https://store.arduino.cc/arduino-mega-2560-rev3)
|
||||
* [Arduino Nano](https://store.arduino.cc/arduino-nano)
|
||||
* [Arduino Nano33 IoT](https://store.arduino.cc/nano-33-iot)
|
||||
* [Arduino Uno](https://store.arduino.cc/arduino-uno-rev3)
|
||||
* [Arduino Zero](https://store.arduino.cc/usa/arduino-zero)
|
||||
* [BBC micro:bit](https://microbit.org/)
|
||||
* [Digispark](http://digistump.com/products/1)
|
||||
* [ESP32](https://www.espressif.com/en/products/socs/esp32)
|
||||
* [ESP8266](https://www.espressif.com/en/products/socs/esp8266)
|
||||
* [Game Boy Advance](https://en.wikipedia.org/wiki/Game_Boy_Advance)
|
||||
* [Makerdiary nRF52840-MDK](https://wiki.makerdiary.com/nrf52840-mdk/)
|
||||
* [Nintendo Switch](https://www.nintendo.com/switch/)
|
||||
* [Nordic Semiconductor PCA10031](https://www.nordicsemi.com/eng/Products/nRF51-Dongle)
|
||||
* [Nordic Semiconductor PCA10040](https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF52-DK)
|
||||
* [Nordic Semiconductor PCA10056](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK)
|
||||
@@ -72,8 +80,10 @@ The following 34 microcontroller boards are currently supported:
|
||||
* [Particle Xenon](https://docs.particle.io/datasheets/discontinued/xenon-datasheet/)
|
||||
* [Phytec reel board](https://www.phytec.eu/product-eu/internet-of-things/reelboard/)
|
||||
* [PineTime DevKit](https://www.pine64.org/pinetime/)
|
||||
* [PJRC Teensy 3.6](https://www.pjrc.com/store/teensy36.html)
|
||||
* [Seeed Wio Terminal](https://www.seeedstudio.com/Wio-Terminal-p-4509.html)
|
||||
* [Seeed Seeeduino XIAO](https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html)
|
||||
* [Seeed Sipeed MAix BiT](https://www.seeedstudio.com/Sipeed-MAix-BiT-for-RISC-V-AI-IoT-p-2872.html)
|
||||
* [SiFIve HiFive1](https://www.sifive.com/boards/hifive1)
|
||||
* [ST Micro "Nucleo F103RB"](https://www.st.com/en/evaluation-tools/nucleo-f103rb.html)
|
||||
* [ST Micro STM32F103XX "Bluepill"](http://wiki.stm32duino.com/index.php?title=Blue_Pill)
|
||||
@@ -139,3 +149,5 @@ The original reasoning was: if [Python](https://micropython.org/) can run on mic
|
||||
This project is licensed under the BSD 3-clause license, just like the [Go project](https://golang.org/LICENSE) itself.
|
||||
|
||||
Some code has been copied from the LLVM project and is therefore licensed under [a variant of the Apache 2.0 license](http://releases.llvm.org/10.0.0/LICENSE.TXT). This has been clearly indicated in the header of these files.
|
||||
|
||||
Some code has been copied and/or ported from Paul Stoffregen's Teensy libraries and is therefore licensed under PJRC's license. This has been clearly indicated in the header of these files.
|
||||
|
||||
+14
-9
@@ -1,7 +1,7 @@
|
||||
# Avoid lengthy LLVM rebuilds on each newly pushed branch. Pull requests will
|
||||
# be built anyway.
|
||||
trigger:
|
||||
- master
|
||||
- release
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
@@ -12,22 +12,27 @@ jobs:
|
||||
steps:
|
||||
- task: GoTool@0
|
||||
inputs:
|
||||
version: '1.14.1'
|
||||
version: '1.15'
|
||||
- checkout: self
|
||||
- task: CacheBeta@0
|
||||
fetchDepth: 1
|
||||
- task: Cache@2
|
||||
displayName: Cache LLVM source
|
||||
inputs:
|
||||
key: llvm-source-10-windows-v0
|
||||
key: llvm-source-10-windows-v1
|
||||
path: llvm-project
|
||||
- task: Bash@3
|
||||
displayName: Download LLVM source
|
||||
inputs:
|
||||
targetType: inline
|
||||
script: make llvm-source
|
||||
script: |
|
||||
make llvm-source
|
||||
# Workaround for bad symlinks:
|
||||
# https://github.com/microsoft/azure-pipelines-tasks/issues/13418
|
||||
rm -f llvm-project/libcxx/test/std/input.output/filesystems/Inputs/static_test_env/bad_symlink
|
||||
- task: CacheBeta@0
|
||||
displayName: Cache LLVM build
|
||||
inputs:
|
||||
key: llvm-build-10-windows-v0
|
||||
key: llvm-build-10-windows-v1
|
||||
path: llvm-build
|
||||
- task: Bash@3
|
||||
displayName: Build LLVM
|
||||
@@ -43,11 +48,11 @@ jobs:
|
||||
displayName: Install QEMU
|
||||
inputs:
|
||||
targetType: inline
|
||||
script: choco install qemu
|
||||
script: choco install qemu --version=2020.06.12
|
||||
- task: CacheBeta@0
|
||||
displayName: Cache wasi-libc sysroot
|
||||
inputs:
|
||||
key: wasi-libc-sysroot-v2
|
||||
key: wasi-libc-sysroot-v3
|
||||
path: lib/wasi-libc/sysroot
|
||||
- task: Bash@3
|
||||
displayName: Build wasi-libc
|
||||
@@ -80,4 +85,4 @@ jobs:
|
||||
script: |
|
||||
export PATH="$PATH:./llvm-build/bin:/c/Program Files/qemu"
|
||||
unset GOROOT
|
||||
make smoketest TINYGO=build/tinygo AVR=0
|
||||
make smoketest TINYGO=build/tinygo AVR=0 XTENSA=0
|
||||
|
||||
+319
-11
@@ -4,11 +4,14 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"debug/elf"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -16,26 +19,40 @@ import (
|
||||
"github.com/tinygo-org/tinygo/compiler"
|
||||
"github.com/tinygo-org/tinygo/goenv"
|
||||
"github.com/tinygo-org/tinygo/interp"
|
||||
"github.com/tinygo-org/tinygo/stacksize"
|
||||
"github.com/tinygo-org/tinygo/transform"
|
||||
"tinygo.org/x/go-llvm"
|
||||
)
|
||||
|
||||
// BuildResult is the output of a build. This includes the binary itself and
|
||||
// some other metadata that is obtained while building the binary.
|
||||
type BuildResult struct {
|
||||
// A path to the output binary. It will be removed after Build returns, so
|
||||
// if it should be kept it must be copied or moved away.
|
||||
Binary string
|
||||
|
||||
// The directory of the main package. This is useful for testing as the test
|
||||
// binary must be run in the directory of the tested package.
|
||||
MainDir string
|
||||
}
|
||||
|
||||
// Build performs a single package to executable Go build. It takes in a package
|
||||
// name, an output path, and set of compile options and from that it manages the
|
||||
// whole compilation process.
|
||||
//
|
||||
// The error value may be of type *MultiError. Callers will likely want to check
|
||||
// for this case and print such errors individually.
|
||||
func Build(pkgName, outpath string, config *compileopts.Config, action func(string) error) error {
|
||||
func Build(pkgName, outpath string, config *compileopts.Config, action func(BuildResult) error) error {
|
||||
// Compile Go code to IR.
|
||||
machine, err := compiler.NewTargetMachine(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mod, extraFiles, extraLDFlags, errs := compiler.Compile(pkgName, machine, config)
|
||||
buildOutput, errs := compiler.Compile(pkgName, machine, config)
|
||||
if errs != nil {
|
||||
return newMultiError(errs)
|
||||
}
|
||||
mod := buildOutput.Mod
|
||||
|
||||
if config.Options.PrintIR {
|
||||
fmt.Println("; Generated LLVM IR:")
|
||||
@@ -73,8 +90,15 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||
// exactly.
|
||||
errs = nil
|
||||
switch config.Options.Opt {
|
||||
case "none", "0":
|
||||
errs = transform.Optimize(mod, config, 0, 0, 0) // -O0
|
||||
/*
|
||||
Currently, turning optimizations off causes compile failures.
|
||||
We rely on the optimizer removing some dead symbols.
|
||||
Avoid providing an option that does not work right now.
|
||||
In the future once everything has been fixed we can re-enable this.
|
||||
|
||||
case "none", "0":
|
||||
errs = transform.Optimize(mod, config, 0, 0, 0) // -O0
|
||||
*/
|
||||
case "1":
|
||||
errs = transform.Optimize(mod, config, 1, 0, 0) // -O1
|
||||
case "2":
|
||||
@@ -105,6 +129,13 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure stack sizes are loaded from a separate section so they can be
|
||||
// modified after linking.
|
||||
var stackSizeLoads []string
|
||||
if config.AutomaticStackSize() {
|
||||
stackSizeLoads = transform.CreateStackSizeLoads(mod, config)
|
||||
}
|
||||
|
||||
// Generate output.
|
||||
outext := filepath.Ext(outpath)
|
||||
switch outext {
|
||||
@@ -178,7 +209,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||
}
|
||||
|
||||
// Compile C files in packages.
|
||||
for i, file := range extraFiles {
|
||||
for i, file := range buildOutput.ExtraFiles {
|
||||
outpath := filepath.Join(dir, "pkg"+strconv.Itoa(i)+"-"+filepath.Base(file)+".o")
|
||||
err := runCCompiler(config.Target.Compiler, append(config.CFlags(), "-c", "-o", outpath, file)...)
|
||||
if err != nil {
|
||||
@@ -187,8 +218,8 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||
ldflags = append(ldflags, outpath)
|
||||
}
|
||||
|
||||
if len(extraLDFlags) > 0 {
|
||||
ldflags = append(ldflags, extraLDFlags...)
|
||||
if len(buildOutput.ExtraLDFlags) > 0 {
|
||||
ldflags = append(ldflags, buildOutput.ExtraLDFlags...)
|
||||
}
|
||||
|
||||
// Link the object files together.
|
||||
@@ -197,6 +228,26 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||
return &commandError{"failed to link", executable, err}
|
||||
}
|
||||
|
||||
var calculatedStacks []string
|
||||
var stackSizes map[string]functionStackSize
|
||||
if config.Options.PrintStacks || config.AutomaticStackSize() {
|
||||
// Try to determine stack sizes at compile time.
|
||||
// Don't do this by default as it usually doesn't work on
|
||||
// unsupported architectures.
|
||||
calculatedStacks, stackSizes, err = determineStackSizes(mod, executable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if config.AutomaticStackSize() {
|
||||
// Modify the .tinygo_stacksizes section that contains a stack size
|
||||
// for each goroutine.
|
||||
err = modifyStackSizes(executable, stackSizeLoads, stackSizes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not modify stack sizes: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if config.Options.PrintSizes == "short" || config.Options.PrintSizes == "full" {
|
||||
sizes, err := loadProgramSize(executable)
|
||||
if err != nil {
|
||||
@@ -216,21 +267,278 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(stri
|
||||
}
|
||||
}
|
||||
|
||||
// Print goroutine stack sizes, as far as possible.
|
||||
if config.Options.PrintStacks {
|
||||
printStacks(calculatedStacks, stackSizes)
|
||||
}
|
||||
|
||||
// Get an Intel .hex file or .bin file from the .elf file.
|
||||
if outext == ".hex" || outext == ".bin" || outext == ".gba" {
|
||||
outputBinaryFormat := config.BinaryFormat(outext)
|
||||
switch outputBinaryFormat {
|
||||
case "elf":
|
||||
// do nothing, file is already in ELF format
|
||||
case "hex", "bin":
|
||||
// Extract raw binary, either encoding it as a hex file or as a raw
|
||||
// firmware file.
|
||||
tmppath = filepath.Join(dir, "main"+outext)
|
||||
err := objcopy(executable, tmppath)
|
||||
err := objcopy(executable, tmppath, outputBinaryFormat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if outext == ".uf2" {
|
||||
case "uf2":
|
||||
// Get UF2 from the .elf file.
|
||||
tmppath = filepath.Join(dir, "main"+outext)
|
||||
err := convertELFFileToUF2File(executable, tmppath, config.Target.UF2FamilyID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "esp32", "esp8266":
|
||||
// Special format for the ESP family of chips (parsed by the ROM
|
||||
// bootloader).
|
||||
tmppath = filepath.Join(dir, "main"+outext)
|
||||
err := makeESPFirmareImage(executable, tmppath, outputBinaryFormat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unknown output binary format: %s", outputBinaryFormat)
|
||||
}
|
||||
return action(BuildResult{
|
||||
Binary: tmppath,
|
||||
MainDir: buildOutput.MainDir,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// functionStackSizes keeps stack size information about a single function
|
||||
// (usually a goroutine).
|
||||
type functionStackSize struct {
|
||||
humanName string
|
||||
stackSize uint64
|
||||
stackSizeType stacksize.SizeType
|
||||
missingStackSize *stacksize.CallNode
|
||||
}
|
||||
|
||||
// determineStackSizes tries to determine the stack sizes of all started
|
||||
// goroutines and of the reset vector. The LLVM module is necessary to find
|
||||
// functions that call a function pointer.
|
||||
func determineStackSizes(mod llvm.Module, executable string) ([]string, map[string]functionStackSize, error) {
|
||||
var callsIndirectFunction []string
|
||||
gowrappers := []string{}
|
||||
gowrapperNames := make(map[string]string)
|
||||
for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) {
|
||||
// Determine which functions call a function pointer.
|
||||
for bb := fn.FirstBasicBlock(); !bb.IsNil(); bb = llvm.NextBasicBlock(bb) {
|
||||
for inst := bb.FirstInstruction(); !inst.IsNil(); inst = llvm.NextInstruction(inst) {
|
||||
if inst.IsACallInst().IsNil() {
|
||||
continue
|
||||
}
|
||||
if callee := inst.CalledValue(); callee.IsAFunction().IsNil() && callee.IsAInlineAsm().IsNil() {
|
||||
callsIndirectFunction = append(callsIndirectFunction, fn.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get a list of "go wrappers", small wrapper functions that decode
|
||||
// parameters when starting a new goroutine.
|
||||
attr := fn.GetStringAttributeAtIndex(-1, "tinygo-gowrapper")
|
||||
if !attr.IsNil() {
|
||||
gowrappers = append(gowrappers, fn.Name())
|
||||
gowrapperNames[fn.Name()] = attr.GetStringValue()
|
||||
}
|
||||
}
|
||||
sort.Strings(gowrappers)
|
||||
|
||||
// Load the ELF binary.
|
||||
f, err := elf.Open(executable)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not load executable for stack size analysis: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Determine the frame size of each function (if available) and the callgraph.
|
||||
functions, err := stacksize.CallGraph(f, callsIndirectFunction)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not parse executable for stack size analysis: %w", err)
|
||||
}
|
||||
|
||||
// Goroutines need to be started and finished and take up some stack space
|
||||
// that way. This can be measured by measuing the stack size of
|
||||
// tinygo_startTask.
|
||||
if numFuncs := len(functions["tinygo_startTask"]); numFuncs != 1 {
|
||||
return nil, nil, fmt.Errorf("expected exactly one definition of tinygo_startTask, got %d", numFuncs)
|
||||
}
|
||||
baseStackSize, baseStackSizeType, baseStackSizeFailedAt := functions["tinygo_startTask"][0].StackSize()
|
||||
|
||||
sizes := make(map[string]functionStackSize)
|
||||
|
||||
// Add the reset handler function, for convenience. The reset handler runs
|
||||
// startup code and the scheduler. The listed stack size is not the full
|
||||
// stack size: interrupts are not counted.
|
||||
var resetFunction string
|
||||
switch f.Machine {
|
||||
case elf.EM_ARM:
|
||||
// Note: all interrupts happen on this stack so the real size is bigger.
|
||||
resetFunction = "Reset_Handler"
|
||||
}
|
||||
if resetFunction != "" {
|
||||
funcs := functions[resetFunction]
|
||||
if len(funcs) != 1 {
|
||||
return nil, nil, fmt.Errorf("expected exactly one definition of %s in the callgraph, found %d", resetFunction, len(funcs))
|
||||
}
|
||||
stackSize, stackSizeType, missingStackSize := funcs[0].StackSize()
|
||||
sizes[resetFunction] = functionStackSize{
|
||||
stackSize: stackSize,
|
||||
stackSizeType: stackSizeType,
|
||||
missingStackSize: missingStackSize,
|
||||
humanName: resetFunction,
|
||||
}
|
||||
}
|
||||
|
||||
// Add all goroutine wrapper functions.
|
||||
for _, name := range gowrappers {
|
||||
funcs := functions[name]
|
||||
if len(funcs) != 1 {
|
||||
return nil, nil, fmt.Errorf("expected exactly one definition of %s in the callgraph, found %d", name, len(funcs))
|
||||
}
|
||||
humanName := gowrapperNames[name]
|
||||
if humanName == "" {
|
||||
humanName = name // fallback
|
||||
}
|
||||
stackSize, stackSizeType, missingStackSize := funcs[0].StackSize()
|
||||
if baseStackSizeType != stacksize.Bounded {
|
||||
// It was not possible to determine the stack size at compile time
|
||||
// because tinygo_startTask does not have a fixed stack size. This
|
||||
// can happen when using -opt=1.
|
||||
stackSizeType = baseStackSizeType
|
||||
missingStackSize = baseStackSizeFailedAt
|
||||
} else if stackSize < baseStackSize {
|
||||
// This goroutine has a very small stack, but still needs to fit all
|
||||
// registers to start and suspend the goroutine. Otherwise a stack
|
||||
// overflow will occur even before the goroutine is started.
|
||||
stackSize = baseStackSize
|
||||
}
|
||||
sizes[name] = functionStackSize{
|
||||
stackSize: stackSize,
|
||||
stackSizeType: stackSizeType,
|
||||
missingStackSize: missingStackSize,
|
||||
humanName: humanName,
|
||||
}
|
||||
}
|
||||
|
||||
if resetFunction != "" {
|
||||
return append([]string{resetFunction}, gowrappers...), sizes, nil
|
||||
}
|
||||
return gowrappers, sizes, nil
|
||||
}
|
||||
|
||||
// modifyStackSizes modifies the .tinygo_stacksizes section with the updated
|
||||
// stack size information. Before this modification, all stack sizes in the
|
||||
// section assume the default stack size (which is relatively big).
|
||||
func modifyStackSizes(executable string, stackSizeLoads []string, stackSizes map[string]functionStackSize) error {
|
||||
fp, err := os.OpenFile(executable, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
elfFile, err := elf.NewFile(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
section := elfFile.Section(".tinygo_stacksizes")
|
||||
if section == nil {
|
||||
return errors.New("could not find .tinygo_stacksizes section")
|
||||
}
|
||||
|
||||
if section.Size != section.FileSize {
|
||||
// Sanity check.
|
||||
return fmt.Errorf("expected .tinygo_stacksizes to have identical size and file size, got %d and %d", section.Size, section.FileSize)
|
||||
}
|
||||
|
||||
// Read all goroutine stack sizes.
|
||||
data := make([]byte, section.Size)
|
||||
_, err = fp.ReadAt(data, int64(section.Offset))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(stackSizeLoads)*4 != len(data) {
|
||||
// Note: while AVR should use 2 byte stack sizes, even 64-bit platforms
|
||||
// should probably stick to 4 byte stack sizes as a larger than 4GB
|
||||
// stack doesn't make much sense.
|
||||
return errors.New("expected 4 byte stack sizes")
|
||||
}
|
||||
|
||||
// Modify goroutine stack sizes with a compile-time known worst case stack
|
||||
// size.
|
||||
for i, name := range stackSizeLoads {
|
||||
fn, ok := stackSizes[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("could not find symbol %s in ELF file", name)
|
||||
}
|
||||
if fn.stackSizeType == stacksize.Bounded {
|
||||
stackSize := uint32(fn.stackSize)
|
||||
|
||||
// Adding 4 for the stack canary. Even though the size may be
|
||||
// automatically determined, stack overflow checking is still
|
||||
// important as the stack size cannot be determined for all
|
||||
// goroutines.
|
||||
stackSize += 4
|
||||
|
||||
// Add stack size used by interrupts.
|
||||
switch elfFile.Machine {
|
||||
case elf.EM_ARM:
|
||||
// On Cortex-M (assumed here), this stack size is 8 words or 32
|
||||
// bytes. This is only to store the registers that the interrupt
|
||||
// may modify, the interrupt will switch to the interrupt stack
|
||||
// (MSP).
|
||||
// Some background:
|
||||
// https://interrupt.memfault.com/blog/cortex-m-rtos-context-switching
|
||||
stackSize += 32
|
||||
}
|
||||
|
||||
// Finally write the stack size to the binary.
|
||||
binary.LittleEndian.PutUint32(data[i*4:], stackSize)
|
||||
}
|
||||
}
|
||||
|
||||
// Write back the modified stack sizes.
|
||||
_, err = fp.WriteAt(data, int64(section.Offset))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// printStacks prints the maximum stack depth for functions that are started as
|
||||
// goroutines. Stack sizes cannot always be determined statically, in particular
|
||||
// recursive functions and functions that call interface methods or function
|
||||
// pointers may have an unknown stack depth (depending on what the optimizer
|
||||
// manages to optimize away).
|
||||
//
|
||||
// It might print something like the following:
|
||||
//
|
||||
// function stack usage (in bytes)
|
||||
// Reset_Handler 316
|
||||
// examples/blinky2.led1 92
|
||||
// runtime.run$1 300
|
||||
func printStacks(calculatedStacks []string, stackSizes map[string]functionStackSize) {
|
||||
// Print the sizes of all stacks.
|
||||
fmt.Printf("%-32s %s\n", "function", "stack usage (in bytes)")
|
||||
for _, name := range calculatedStacks {
|
||||
fn := stackSizes[name]
|
||||
switch fn.stackSizeType {
|
||||
case stacksize.Bounded:
|
||||
fmt.Printf("%-32s %d\n", fn.humanName, fn.stackSize)
|
||||
case stacksize.Unknown:
|
||||
fmt.Printf("%-32s unknown, %s does not have stack frame information\n", fn.humanName, fn.missingStackSize)
|
||||
case stacksize.Recursive:
|
||||
fmt.Printf("%-32s recursive, %s may call itself\n", fn.humanName, fn.missingStackSize)
|
||||
case stacksize.IndirectCall:
|
||||
fmt.Printf("%-32s unknown, %s calls a function pointer\n", fn.humanName, fn.missingStackSize)
|
||||
}
|
||||
return action(tmppath)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err)
|
||||
}
|
||||
if major != 1 || minor < 11 || minor > 14 {
|
||||
return nil, fmt.Errorf("requires go version 1.11, 1.12, 1.13, or 1.14, got go%d.%d", major, minor)
|
||||
if major != 1 || minor < 11 || minor > 15 {
|
||||
return nil, fmt.Errorf("requires go version 1.11 through 1.15, got go%d.%d", major, minor)
|
||||
}
|
||||
clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT"))
|
||||
return &compileopts.Config{
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
package builder
|
||||
|
||||
// This file implements support for writing ESP image files. These image files
|
||||
// are read by the ROM bootloader so have to be in a particular format.
|
||||
//
|
||||
// In the future, it may be necessary to implement support for other image
|
||||
// formats, such as the ESP8266 image formats (again, used by the ROM bootloader
|
||||
// to load the firmware).
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"debug/elf"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type espImageSegment struct {
|
||||
addr uint32
|
||||
data []byte
|
||||
}
|
||||
|
||||
// makeESPFirmare converts an input ELF file to an image file for an ESP32 or
|
||||
// ESP8266 chip. This is a special purpose image format just for the ESP chip
|
||||
// family, and is parsed by the on-chip mask ROM bootloader.
|
||||
//
|
||||
// The following documentation has been used:
|
||||
// https://github.com/espressif/esptool/wiki/Firmware-Image-Format
|
||||
// https://github.com/espressif/esp-idf/blob/8fbb63c2a701c22ccf4ce249f43aded73e134a34/components/bootloader_support/include/esp_image_format.h#L58
|
||||
// https://github.com/espressif/esptool/blob/master/esptool.py
|
||||
func makeESPFirmareImage(infile, outfile, format string) error {
|
||||
inf, err := elf.Open(infile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer inf.Close()
|
||||
|
||||
// Load all segments to be written to the image. These are actually ELF
|
||||
// sections, not true ELF segments (similar to how esptool does it).
|
||||
var segments []*espImageSegment
|
||||
for _, section := range inf.Sections {
|
||||
if section.Type != elf.SHT_PROGBITS || section.Size == 0 || section.Flags&elf.SHF_ALLOC == 0 {
|
||||
continue
|
||||
}
|
||||
data, err := section.Data()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read section data: %w", err)
|
||||
}
|
||||
for len(data)%4 != 0 {
|
||||
// Align segment to 4 bytes.
|
||||
data = append(data, 0)
|
||||
}
|
||||
if uint64(uint32(section.Addr)) != section.Addr {
|
||||
return fmt.Errorf("section address too big: 0x%x", section.Addr)
|
||||
}
|
||||
segments = append(segments, &espImageSegment{
|
||||
addr: uint32(section.Addr),
|
||||
data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// Sort the segments by address. This is what esptool does too.
|
||||
sort.SliceStable(segments, func(i, j int) bool { return segments[i].addr < segments[j].addr })
|
||||
|
||||
// Calculate checksum over the segment data. This is used in the image
|
||||
// footer.
|
||||
checksum := uint8(0xef)
|
||||
for _, segment := range segments {
|
||||
for _, b := range segment.data {
|
||||
checksum ^= b
|
||||
}
|
||||
}
|
||||
|
||||
// Write first to an in-memory buffer, primarily so that we can easily
|
||||
// calculate a hash over the entire image.
|
||||
// An added benefit is that we don't need to check for errors all the time.
|
||||
outf := &bytes.Buffer{}
|
||||
|
||||
// Image header.
|
||||
switch format {
|
||||
case "esp32":
|
||||
// Header format:
|
||||
// https://github.com/espressif/esp-idf/blob/8fbb63c2/components/bootloader_support/include/esp_image_format.h#L58
|
||||
binary.Write(outf, binary.LittleEndian, struct {
|
||||
magic uint8
|
||||
segment_count uint8
|
||||
spi_mode uint8
|
||||
spi_speed_size uint8
|
||||
entry_addr uint32
|
||||
wp_pin uint8
|
||||
spi_pin_drv [3]uint8
|
||||
reserved [11]uint8
|
||||
hash_appended bool
|
||||
}{
|
||||
magic: 0xE9,
|
||||
segment_count: byte(len(segments)),
|
||||
spi_mode: 0, // irrelevant, replaced by esptool when flashing
|
||||
spi_speed_size: 0, // spi_speed, spi_size: replaced by esptool when flashing
|
||||
entry_addr: uint32(inf.Entry),
|
||||
wp_pin: 0xEE, // disable WP pin
|
||||
hash_appended: true, // add a SHA256 hash
|
||||
})
|
||||
case "esp8266":
|
||||
// Header format:
|
||||
// https://github.com/espressif/esptool/wiki/Firmware-Image-Format
|
||||
// Basically a truncated version of the ESP32 header.
|
||||
binary.Write(outf, binary.LittleEndian, struct {
|
||||
magic uint8
|
||||
segment_count uint8
|
||||
spi_mode uint8
|
||||
spi_speed_size uint8
|
||||
entry_addr uint32
|
||||
}{
|
||||
magic: 0xE9,
|
||||
segment_count: byte(len(segments)),
|
||||
spi_mode: 0, // irrelevant, replaced by esptool when flashing
|
||||
spi_speed_size: 0x20, // spi_speed, spi_size: replaced by esptool when flashing
|
||||
entry_addr: uint32(inf.Entry),
|
||||
})
|
||||
default:
|
||||
return fmt.Errorf("builder: unknown binary format %#v, expected esp32 or esp8266", format)
|
||||
}
|
||||
|
||||
// Write all segments to the image.
|
||||
// https://github.com/espressif/esptool/wiki/Firmware-Image-Format#segment
|
||||
for _, segment := range segments {
|
||||
binary.Write(outf, binary.LittleEndian, struct {
|
||||
addr uint32
|
||||
length uint32
|
||||
}{
|
||||
addr: segment.addr,
|
||||
length: uint32(len(segment.data)),
|
||||
})
|
||||
outf.Write(segment.data)
|
||||
}
|
||||
|
||||
// Footer, including checksum.
|
||||
// The entire image size must be a multiple of 16, so pad the image to one
|
||||
// byte less than that before writing the checksum.
|
||||
outf.Write(make([]byte, 15-outf.Len()%16))
|
||||
outf.WriteByte(checksum)
|
||||
|
||||
if format == "esp32" {
|
||||
// SHA256 hash (to protect against image corruption, not for security).
|
||||
hash := sha256.Sum256(outf.Bytes())
|
||||
outf.Write(hash[:])
|
||||
}
|
||||
|
||||
// Write the image to the output file.
|
||||
return ioutil.WriteFile(outfile, outf.Bytes(), 0666)
|
||||
}
|
||||
@@ -74,6 +74,9 @@ func (l *Library) Load(target string) (path string, err error) {
|
||||
if strings.HasPrefix(target, "riscv32-") {
|
||||
args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128")
|
||||
}
|
||||
if strings.HasPrefix(target, "riscv64-") {
|
||||
args = append(args, "-march=rv64gc", "-mabi=lp64")
|
||||
}
|
||||
|
||||
// Compile all sources.
|
||||
var objs []string
|
||||
|
||||
+19
-14
@@ -4,12 +4,15 @@ import (
|
||||
"debug/elf"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/marcinbor85/gohex"
|
||||
)
|
||||
|
||||
// maxPadBytes is the maximum allowed bytes to be padded in a rom extraction
|
||||
// this value is currently defined by Nintendo Switch Page Alignment (4096 bytes)
|
||||
const maxPadBytes = 4095
|
||||
|
||||
// objcopyError is an error returned by functions that act like objcopy.
|
||||
type objcopyError struct {
|
||||
Op string
|
||||
@@ -71,7 +74,12 @@ func extractROM(path string) (uint64, []byte, error) {
|
||||
var rom []byte
|
||||
for _, prog := range progs {
|
||||
if prog.Paddr != progs[0].Paddr+uint64(len(rom)) {
|
||||
return 0, nil, objcopyError{"ROM segments are non-contiguous: " + path, nil}
|
||||
diff := prog.Paddr - (progs[0].Paddr + uint64(len(rom)))
|
||||
if diff > maxPadBytes {
|
||||
return 0, nil, objcopyError{"ROM segments are non-contiguous: " + path, nil}
|
||||
}
|
||||
// Pad the difference
|
||||
rom = append(rom, make([]byte, diff)...)
|
||||
}
|
||||
data, err := ioutil.ReadAll(prog.Open())
|
||||
if err != nil {
|
||||
@@ -93,7 +101,7 @@ func extractROM(path string) (uint64, []byte, error) {
|
||||
|
||||
// objcopy converts an ELF file to a different (simpler) output file format:
|
||||
// .bin or .hex. It extracts only the .text section.
|
||||
func objcopy(infile, outfile string) error {
|
||||
func objcopy(infile, outfile, binaryFormat string) error {
|
||||
f, err := os.OpenFile(outfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -107,23 +115,20 @@ func objcopy(infile, outfile string) error {
|
||||
}
|
||||
|
||||
// Write to the file, in the correct format.
|
||||
switch filepath.Ext(outfile) {
|
||||
case ".gba":
|
||||
// The address is not stored in a .gba file.
|
||||
_, err := f.Write(data)
|
||||
return err
|
||||
case ".bin":
|
||||
// The address is not stored in a .bin file (therefore you
|
||||
// should use .hex files in most cases).
|
||||
_, err := f.Write(data)
|
||||
return err
|
||||
case ".hex":
|
||||
switch binaryFormat {
|
||||
case "hex":
|
||||
// Intel hex file, includes the firmware start address.
|
||||
mem := gohex.NewMemory()
|
||||
err := mem.AddBinary(uint32(addr), data)
|
||||
if err != nil {
|
||||
return objcopyError{"failed to create .hex file", err}
|
||||
}
|
||||
return mem.DumpIntelHex(f, 16)
|
||||
case "bin":
|
||||
// The start address is not stored in raw firmware files (therefore you
|
||||
// should use .hex files in most cases).
|
||||
_, err := f.Write(data)
|
||||
return err
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
@@ -164,6 +164,16 @@ func (c *Config) PanicStrategy() string {
|
||||
return c.Options.PanicStrategy
|
||||
}
|
||||
|
||||
// AutomaticStackSize returns whether goroutine stack sizes should be determined
|
||||
// automatically at compile time, if possible. If it is false, no attempt is
|
||||
// made.
|
||||
func (c *Config) AutomaticStackSize() bool {
|
||||
if c.Target.AutoStackSize != nil && c.Scheduler() == "tasks" {
|
||||
return *c.Target.AutoStackSize
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CFlags returns the flags to pass to the C compiler. This is necessary for CGo
|
||||
// preprocessing.
|
||||
func (c *Config) CFlags() []string {
|
||||
@@ -176,6 +186,9 @@ func (c *Config) CFlags() []string {
|
||||
cflags = append(cflags, "-nostdlibinc", "-Xclang", "-internal-isystem", "-Xclang", filepath.Join(root, "lib", "picolibc", "newlib", "libc", "include"))
|
||||
cflags = append(cflags, "-I"+filepath.Join(root, "lib/picolibc-include"))
|
||||
}
|
||||
if c.Debug() {
|
||||
cflags = append(cflags, "-g")
|
||||
}
|
||||
return cflags
|
||||
}
|
||||
|
||||
@@ -226,6 +239,31 @@ func (c *Config) Debug() bool {
|
||||
return c.Options.Debug
|
||||
}
|
||||
|
||||
// BinaryFormat returns an appropriate binary format, based on the file
|
||||
// extension and the configured binary format in the target JSON file.
|
||||
func (c *Config) BinaryFormat(ext string) string {
|
||||
switch ext {
|
||||
case ".bin", ".gba", ".nro":
|
||||
// The simplest format possible: dump everything in a raw binary file.
|
||||
if c.Target.BinaryFormat != "" {
|
||||
return c.Target.BinaryFormat
|
||||
}
|
||||
return "bin"
|
||||
case ".hex":
|
||||
// Similar to bin, but includes the start address and is thus usually a
|
||||
// better format.
|
||||
return "hex"
|
||||
case ".uf2":
|
||||
// Special purpose firmware format, mainly used on Adafruit boards.
|
||||
// More information:
|
||||
// https://github.com/Microsoft/uf2
|
||||
return "uf2"
|
||||
default:
|
||||
// Use the ELF format for unrecognized file formats.
|
||||
return "elf"
|
||||
}
|
||||
}
|
||||
|
||||
// Programmer returns the flash method and OpenOCD interface name given a
|
||||
// particular configuration. It may either be all configured in the target JSON
|
||||
// file or be modified using the -programmmer command-line option.
|
||||
@@ -281,6 +319,16 @@ func (c *Config) CodeModel() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// RelocationModel returns the relocation model in use on this platform. Valid
|
||||
// values are "static", "pic", "dynamicnopic".
|
||||
func (c *Config) RelocationModel() string {
|
||||
if c.Target.RelocationModel != "" {
|
||||
return c.Target.RelocationModel
|
||||
}
|
||||
|
||||
return "static"
|
||||
}
|
||||
|
||||
type TestConfig struct {
|
||||
CompileTestBinary bool
|
||||
// TODO: Filter the test functions to run, include verbose flag, etc
|
||||
|
||||
@@ -25,6 +25,7 @@ type Options struct {
|
||||
VerifyIR bool
|
||||
Debug bool
|
||||
PrintSizes string
|
||||
PrintStacks bool
|
||||
CFlags []string
|
||||
LDFlags []string
|
||||
Tags string
|
||||
|
||||
@@ -33,6 +33,8 @@ type TargetSpec struct {
|
||||
Linker string `json:"linker"`
|
||||
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
|
||||
Libc string `json:"libc"`
|
||||
AutoStackSize *bool `json:"automatic-stack-size"` // Determine stack size automatically at compile time.
|
||||
DefaultStackSize uint64 `json:"default-stack-size"` // Default stack size if the size couldn't be determined at compile time.
|
||||
CFlags []string `json:"cflags"`
|
||||
LDFlags []string `json:"ldflags"`
|
||||
LinkerScript string `json:"linkerscript"`
|
||||
@@ -45,11 +47,13 @@ type TargetSpec struct {
|
||||
FlashVolume string `json:"msd-volume-name"`
|
||||
FlashFilename string `json:"msd-firmware-name"`
|
||||
UF2FamilyID string `json:"uf2-family-id"`
|
||||
BinaryFormat string `json:"binary-format"`
|
||||
OpenOCDInterface string `json:"openocd-interface"`
|
||||
OpenOCDTarget string `json:"openocd-target"`
|
||||
OpenOCDTransport string `json:"openocd-transport"`
|
||||
JLinkDevice string `json:"jlink-device"`
|
||||
CodeModel string `json:"code-model"`
|
||||
RelocationModel string `json:"relocation-model"`
|
||||
}
|
||||
|
||||
// copyProperties copies all properties that are set in spec2 into itself.
|
||||
@@ -89,6 +93,12 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
|
||||
if spec2.Libc != "" {
|
||||
spec.Libc = spec2.Libc
|
||||
}
|
||||
if spec2.AutoStackSize != nil {
|
||||
spec.AutoStackSize = spec2.AutoStackSize
|
||||
}
|
||||
if spec2.DefaultStackSize != 0 {
|
||||
spec.DefaultStackSize = spec2.DefaultStackSize
|
||||
}
|
||||
spec.CFlags = append(spec.CFlags, spec2.CFlags...)
|
||||
spec.LDFlags = append(spec.LDFlags, spec2.LDFlags...)
|
||||
if spec2.LinkerScript != "" {
|
||||
@@ -119,6 +129,9 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
|
||||
if spec2.UF2FamilyID != "" {
|
||||
spec.UF2FamilyID = spec2.UF2FamilyID
|
||||
}
|
||||
if spec2.BinaryFormat != "" {
|
||||
spec.BinaryFormat = spec2.BinaryFormat
|
||||
}
|
||||
if spec2.OpenOCDInterface != "" {
|
||||
spec.OpenOCDInterface = spec2.OpenOCDInterface
|
||||
}
|
||||
@@ -134,6 +147,10 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
|
||||
if spec2.CodeModel != "" {
|
||||
spec.CodeModel = spec2.CodeModel
|
||||
}
|
||||
|
||||
if spec2.RelocationModel != "" {
|
||||
spec.RelocationModel = spec2.RelocationModel
|
||||
}
|
||||
}
|
||||
|
||||
// load reads a target specification from the JSON in the given io.Reader. It
|
||||
|
||||
+59
-50
@@ -5,18 +5,15 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compileopts"
|
||||
"github.com/tinygo-org/tinygo/compiler/llvmutil"
|
||||
"github.com/tinygo-org/tinygo/goenv"
|
||||
"github.com/tinygo-org/tinygo/ir"
|
||||
"github.com/tinygo-org/tinygo/loader"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
@@ -74,7 +71,14 @@ type builder struct {
|
||||
deferFuncs map[*ir.Function]int
|
||||
deferInvokeFuncs map[string]int
|
||||
deferClosureFuncs map[*ir.Function]int
|
||||
deferExprFuncs map[ssa.Value]int
|
||||
selectRecvBuf map[*ssa.Select]llvm.Value
|
||||
deferBuiltinFuncs map[ssa.Value]deferBuiltin
|
||||
}
|
||||
|
||||
type deferBuiltin struct {
|
||||
funcName string
|
||||
callback int
|
||||
}
|
||||
|
||||
type phiNode struct {
|
||||
@@ -93,6 +97,7 @@ func NewTargetMachine(config *compileopts.Config) (llvm.TargetMachine, error) {
|
||||
features := strings.Join(config.Features(), ",")
|
||||
|
||||
var codeModel llvm.CodeModel
|
||||
var relocationModel llvm.RelocMode
|
||||
|
||||
switch config.CodeModel() {
|
||||
case "default":
|
||||
@@ -109,10 +114,41 @@ func NewTargetMachine(config *compileopts.Config) (llvm.TargetMachine, error) {
|
||||
codeModel = llvm.CodeModelLarge
|
||||
}
|
||||
|
||||
machine := target.CreateTargetMachine(config.Triple(), config.CPU(), features, llvm.CodeGenLevelDefault, llvm.RelocStatic, codeModel)
|
||||
switch config.RelocationModel() {
|
||||
case "static":
|
||||
relocationModel = llvm.RelocStatic
|
||||
case "pic":
|
||||
relocationModel = llvm.RelocPIC
|
||||
case "dynamicnopic":
|
||||
relocationModel = llvm.RelocDynamicNoPic
|
||||
}
|
||||
|
||||
machine := target.CreateTargetMachine(config.Triple(), config.CPU(), features, llvm.CodeGenLevelDefault, relocationModel, codeModel)
|
||||
return machine, nil
|
||||
}
|
||||
|
||||
// CompilerOutput is returned from the Compile() call. It contains the compile
|
||||
// output and information necessary to continue to compile and link the program.
|
||||
type CompilerOutput struct {
|
||||
// The LLVM module that contains the compiled but not optimized LLVM module
|
||||
// for all the Go code in the program.
|
||||
Mod llvm.Module
|
||||
|
||||
// ExtraFiles is a list of C source files included in packages that should
|
||||
// be built and linked together with the main executable to form one
|
||||
// program. They can be used from CGo, for example.
|
||||
ExtraFiles []string
|
||||
|
||||
// ExtraLDFlags are linker flags obtained during CGo processing. These flags
|
||||
// must be passed to the linker which links the entire executable.
|
||||
ExtraLDFlags []string
|
||||
|
||||
// MainDir is the absolute directory path to the directory of the main
|
||||
// package. This is useful for testing: tests must be run in the package
|
||||
// directory that is being tested.
|
||||
MainDir string
|
||||
}
|
||||
|
||||
// Compile the given package path or .go file path. Return an error when this
|
||||
// fails (in any stage). If successful it returns the LLVM module and a list of
|
||||
// extra C files to be compiled. If not, one or more errors will be returned.
|
||||
@@ -121,7 +157,7 @@ func NewTargetMachine(config *compileopts.Config) (llvm.TargetMachine, error) {
|
||||
// violation. Eventually, this Compile function should only compile a single
|
||||
// package and not the whole program, and loading of the program (including CGo
|
||||
// processing) should be moved outside the compiler package.
|
||||
func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Config) (mod llvm.Module, extrafiles []string, extraldflags []string, errors []error) {
|
||||
func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Config) (output CompilerOutput, errors []error) {
|
||||
c := &compilerContext{
|
||||
Config: config,
|
||||
difiles: make(map[string]llvm.Metadata),
|
||||
@@ -137,6 +173,7 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con
|
||||
if c.Debug() {
|
||||
c.dibuilder = llvm.NewDIBuilder(c.mod)
|
||||
}
|
||||
output.Mod = c.mod
|
||||
|
||||
c.uintptrType = c.ctx.IntType(c.targetData.PointerSize() * 8)
|
||||
if c.targetData.PointerSize() <= 4 {
|
||||
@@ -155,55 +192,29 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con
|
||||
c.funcPtrAddrSpace = dummyFunc.Type().PointerAddressSpace()
|
||||
dummyFunc.EraseFromParentAsFunction()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
lprogram, err := loader.Load(c.Config, []string{pkgName}, c.ClangHeaders, types.Config{
|
||||
Sizes: &stdSizes{
|
||||
IntSize: int64(c.targetData.TypeAllocSize(c.intType)),
|
||||
PtrSize: int64(c.targetData.PointerSize()),
|
||||
MaxAlign: int64(c.targetData.PrefTypeAlignment(c.i8ptrType)),
|
||||
}})
|
||||
if err != nil {
|
||||
return c.mod, nil, nil, []error{err}
|
||||
}
|
||||
goroot, err := loader.GetCachedGoroot(c.Config)
|
||||
if err != nil {
|
||||
return c.mod, nil, nil, []error{err}
|
||||
}
|
||||
lprogram := &loader.Program{
|
||||
Build: &build.Context{
|
||||
GOARCH: c.GOARCH(),
|
||||
GOOS: c.GOOS(),
|
||||
GOROOT: goroot,
|
||||
GOPATH: goenv.Get("GOPATH"),
|
||||
CgoEnabled: c.CgoEnabled(),
|
||||
UseAllFiles: false,
|
||||
Compiler: "gc", // must be one of the recognized compilers
|
||||
BuildTags: c.BuildTags(),
|
||||
},
|
||||
Tests: c.TestConfig.CompileTestBinary,
|
||||
TypeChecker: types.Config{
|
||||
Sizes: &stdSizes{
|
||||
IntSize: int64(c.targetData.TypeAllocSize(c.intType)),
|
||||
PtrSize: int64(c.targetData.PointerSize()),
|
||||
MaxAlign: int64(c.targetData.PrefTypeAlignment(c.i8ptrType)),
|
||||
},
|
||||
},
|
||||
Dir: wd,
|
||||
TINYGOROOT: goenv.Get("TINYGOROOT"),
|
||||
CFlags: c.CFlags(),
|
||||
ClangHeaders: c.ClangHeaders,
|
||||
}
|
||||
|
||||
err = lprogram.Load(pkgName)
|
||||
if err != nil {
|
||||
return c.mod, nil, nil, []error{err}
|
||||
return output, []error{err}
|
||||
}
|
||||
|
||||
err = lprogram.Parse()
|
||||
if err != nil {
|
||||
return c.mod, nil, nil, []error{err}
|
||||
return output, []error{err}
|
||||
}
|
||||
output.ExtraLDFlags = lprogram.LDFlags
|
||||
output.MainDir = lprogram.MainPkg().Dir
|
||||
|
||||
c.ir = ir.NewProgram(lprogram)
|
||||
|
||||
// Run a simple dead code elimination pass.
|
||||
err = c.ir.SimpleDCE()
|
||||
if err != nil {
|
||||
return c.mod, nil, nil, []error{err}
|
||||
return output, []error{err}
|
||||
}
|
||||
|
||||
// Initialize debug information.
|
||||
@@ -276,6 +287,8 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con
|
||||
pos := c.ir.Program.Fset.Position(initFn.Pos())
|
||||
irbuilder.SetCurrentDebugLocation(uint(pos.Line), uint(pos.Column), difunc, llvm.Metadata{})
|
||||
}
|
||||
initFn.LLVMFn.Param(0).SetName("context")
|
||||
initFn.LLVMFn.Param(1).SetName("parentHandle")
|
||||
block := c.ctx.AddBasicBlock(initFn.LLVMFn, "entry")
|
||||
irbuilder.SetInsertPointAtEnd(block)
|
||||
for _, fn := range initFuncs {
|
||||
@@ -340,17 +353,13 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con
|
||||
}
|
||||
|
||||
// Gather the list of (C) file paths that should be included in the build.
|
||||
var extraFiles []string
|
||||
for _, pkg := range c.ir.LoaderProgram.Sorted() {
|
||||
for _, file := range pkg.OtherFiles {
|
||||
switch strings.ToLower(filepath.Ext(file)) {
|
||||
case ".c":
|
||||
extraFiles = append(extraFiles, file)
|
||||
}
|
||||
for _, filename := range pkg.CFiles {
|
||||
output.ExtraFiles = append(output.ExtraFiles, filepath.Join(pkg.Dir, filename))
|
||||
}
|
||||
}
|
||||
|
||||
return c.mod, extraFiles, lprogram.LDFlags, c.diagnostics
|
||||
return output, c.diagnostics
|
||||
}
|
||||
|
||||
// getLLVMRuntimeType obtains a named type from the runtime package and returns
|
||||
@@ -2536,7 +2545,7 @@ func (b *builder) createConvert(typeFrom, typeTo types.Type, value llvm.Value, p
|
||||
return llvm.Value{}, b.makeError(pos, "todo: convert: basic non-integer type: "+typeFrom.String()+" -> "+typeTo.String())
|
||||
|
||||
case *types.Slice:
|
||||
if basic, ok := typeFrom.(*types.Basic); !ok || basic.Info()&types.IsString == 0 {
|
||||
if basic, ok := typeFrom.Underlying().(*types.Basic); !ok || basic.Info()&types.IsString == 0 {
|
||||
panic("can only convert from a string to a slice")
|
||||
}
|
||||
|
||||
|
||||
+109
-14
@@ -16,6 +16,7 @@ package compiler
|
||||
import (
|
||||
"github.com/tinygo-org/tinygo/compiler/llvmutil"
|
||||
"github.com/tinygo-org/tinygo/ir"
|
||||
"go/types"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"tinygo.org/x/go-llvm"
|
||||
)
|
||||
@@ -28,6 +29,8 @@ func (b *builder) deferInitFunc() {
|
||||
b.deferFuncs = make(map[*ir.Function]int)
|
||||
b.deferInvokeFuncs = make(map[string]int)
|
||||
b.deferClosureFuncs = make(map[*ir.Function]int)
|
||||
b.deferExprFuncs = make(map[ssa.Value]int)
|
||||
b.deferBuiltinFuncs = make(map[ssa.Value]deferBuiltin)
|
||||
|
||||
// Create defer list pointer.
|
||||
deferType := llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0)
|
||||
@@ -151,9 +154,54 @@ func (b *builder) createDefer(instr *ssa.Defer) {
|
||||
values = append(values, context)
|
||||
valueTypes = append(valueTypes, context.Type())
|
||||
|
||||
} else if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok {
|
||||
var funcName string
|
||||
switch builtin.Name() {
|
||||
case "close":
|
||||
funcName = "chanClose"
|
||||
default:
|
||||
b.addError(instr.Pos(), "todo: Implement defer for "+builtin.Name())
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := b.deferBuiltinFuncs[instr.Call.Value]; !ok {
|
||||
b.deferBuiltinFuncs[instr.Call.Value] = deferBuiltin{
|
||||
funcName,
|
||||
len(b.allDeferFuncs),
|
||||
}
|
||||
b.allDeferFuncs = append(b.allDeferFuncs, instr.Call.Value)
|
||||
}
|
||||
callback := llvm.ConstInt(b.uintptrType, uint64(b.deferBuiltinFuncs[instr.Call.Value].callback), false)
|
||||
|
||||
// Collect all values to be put in the struct (starting with
|
||||
// runtime._defer fields).
|
||||
values = []llvm.Value{callback, next}
|
||||
for _, param := range instr.Call.Args {
|
||||
llvmParam := b.getValue(param)
|
||||
values = append(values, llvmParam)
|
||||
valueTypes = append(valueTypes, llvmParam.Type())
|
||||
}
|
||||
|
||||
} else {
|
||||
b.addError(instr.Pos(), "todo: defer on uncommon function call type")
|
||||
return
|
||||
funcValue := b.getValue(instr.Call.Value)
|
||||
|
||||
if _, ok := b.deferExprFuncs[instr.Call.Value]; !ok {
|
||||
b.deferExprFuncs[instr.Call.Value] = len(b.allDeferFuncs)
|
||||
b.allDeferFuncs = append(b.allDeferFuncs, &instr.Call)
|
||||
}
|
||||
|
||||
callback := llvm.ConstInt(b.uintptrType, uint64(b.deferExprFuncs[instr.Call.Value]), false)
|
||||
|
||||
// Collect all values to be put in the struct (starting with
|
||||
// runtime._defer fields, followed by all parameters including the
|
||||
// context pointer).
|
||||
values = []llvm.Value{callback, next, funcValue}
|
||||
valueTypes = append(valueTypes, funcValue.Type())
|
||||
for _, param := range instr.Call.Args {
|
||||
llvmParam := b.getValue(param)
|
||||
values = append(values, llvmParam)
|
||||
valueTypes = append(valueTypes, llvmParam.Type())
|
||||
}
|
||||
}
|
||||
|
||||
// Make a struct out of the collected values to put in the defer frame.
|
||||
@@ -243,16 +291,23 @@ func (b *builder) createRunDefers() {
|
||||
b.SetInsertPointAtEnd(block)
|
||||
switch callback := callback.(type) {
|
||||
case *ssa.CallCommon:
|
||||
// Call on an interface value.
|
||||
if !callback.IsInvoke() {
|
||||
panic("expected an invoke call, not a direct call")
|
||||
}
|
||||
// Call on an value or interface value.
|
||||
|
||||
// Get the real defer struct type and cast to it.
|
||||
valueTypes := []llvm.Type{b.uintptrType, llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0), b.uintptrType, b.i8ptrType}
|
||||
valueTypes := []llvm.Type{b.uintptrType, llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0)}
|
||||
|
||||
if !callback.IsInvoke() {
|
||||
//Expect funcValue to be passed through the defer frame.
|
||||
valueTypes = append(valueTypes, b.getFuncType(callback.Signature()))
|
||||
} else {
|
||||
//Expect typecode
|
||||
valueTypes = append(valueTypes, b.uintptrType, b.i8ptrType)
|
||||
}
|
||||
|
||||
for _, arg := range callback.Args {
|
||||
valueTypes = append(valueTypes, b.getLLVMType(arg.Type()))
|
||||
}
|
||||
|
||||
deferFrameType := b.ctx.StructType(valueTypes, false)
|
||||
deferFramePtr := b.CreateBitCast(deferData, llvm.PointerType(deferFrameType, 0), "deferFrame")
|
||||
|
||||
@@ -265,18 +320,34 @@ func (b *builder) createRunDefers() {
|
||||
forwardParams = append(forwardParams, forwardParam)
|
||||
}
|
||||
|
||||
// Isolate the typecode.
|
||||
typecode, forwardParams := forwardParams[0], forwardParams[1:]
|
||||
var fnPtr llvm.Value
|
||||
|
||||
// Add the context parameter. An interface call cannot also be a
|
||||
// closure but we have to supply the parameter anyway for platforms
|
||||
// with a strict calling convention.
|
||||
forwardParams = append(forwardParams, llvm.Undef(b.i8ptrType))
|
||||
if !callback.IsInvoke() {
|
||||
// Isolate the func value.
|
||||
funcValue := forwardParams[0]
|
||||
forwardParams = forwardParams[1:]
|
||||
|
||||
//Get function pointer and context
|
||||
fp, context := b.decodeFuncValue(funcValue, callback.Signature())
|
||||
fnPtr = fp
|
||||
|
||||
//Pass context
|
||||
forwardParams = append(forwardParams, context)
|
||||
} else {
|
||||
// Isolate the typecode.
|
||||
typecode := forwardParams[0]
|
||||
forwardParams = forwardParams[1:]
|
||||
fnPtr = b.getInvokePtr(callback, typecode)
|
||||
|
||||
// Add the context parameter. An interface call cannot also be a
|
||||
// closure but we have to supply the parameter anyway for platforms
|
||||
// with a strict calling convention.
|
||||
forwardParams = append(forwardParams, llvm.Undef(b.i8ptrType))
|
||||
}
|
||||
|
||||
// Parent coroutine handle.
|
||||
forwardParams = append(forwardParams, llvm.Undef(b.i8ptrType))
|
||||
|
||||
fnPtr := b.getInvokePtr(callback, typecode)
|
||||
b.createCall(fnPtr, forwardParams, "")
|
||||
|
||||
case *ir.Function:
|
||||
@@ -339,7 +410,31 @@ func (b *builder) createRunDefers() {
|
||||
|
||||
// Call deferred function.
|
||||
b.createCall(fn.LLVMFn, forwardParams, "")
|
||||
case *ssa.Builtin:
|
||||
db := b.deferBuiltinFuncs[callback]
|
||||
|
||||
//Get parameter types
|
||||
valueTypes := []llvm.Type{b.uintptrType, llvm.PointerType(b.getLLVMRuntimeType("_defer"), 0)}
|
||||
|
||||
//Get signature from call results
|
||||
params := callback.Type().Underlying().(*types.Signature).Params()
|
||||
for i := 0; i < params.Len(); i++ {
|
||||
valueTypes = append(valueTypes, b.getLLVMType(params.At(i).Type()))
|
||||
}
|
||||
|
||||
deferFrameType := b.ctx.StructType(valueTypes, false)
|
||||
deferFramePtr := b.CreateBitCast(deferData, llvm.PointerType(deferFrameType, 0), "deferFrame")
|
||||
|
||||
// Extract the params from the struct.
|
||||
var forwardParams []llvm.Value
|
||||
zero := llvm.ConstInt(b.ctx.Int32Type(), 0, false)
|
||||
for i := 0; i < params.Len(); i++ {
|
||||
gep := b.CreateInBoundsGEP(deferFramePtr, []llvm.Value{zero, llvm.ConstInt(b.ctx.Int32Type(), uint64(i+2), false)}, "gep")
|
||||
forwardParam := b.CreateLoad(gep, "param")
|
||||
forwardParams = append(forwardParams, forwardParam)
|
||||
}
|
||||
|
||||
b.createRuntimeCall(db.funcName, forwardParams, "")
|
||||
default:
|
||||
panic("unknown deferred function type")
|
||||
}
|
||||
|
||||
+19
-3
@@ -19,16 +19,30 @@ import (
|
||||
// Because a go statement doesn't return anything, return undef.
|
||||
func (b *builder) createGoInstruction(funcPtr llvm.Value, params []llvm.Value, prefix string, pos token.Pos) llvm.Value {
|
||||
paramBundle := b.emitPointerPack(params)
|
||||
var callee llvm.Value
|
||||
var callee, stackSize llvm.Value
|
||||
switch b.Scheduler() {
|
||||
case "none", "tasks":
|
||||
callee = b.createGoroutineStartWrapper(funcPtr, prefix, pos)
|
||||
if b.AutomaticStackSize() {
|
||||
// The stack size is not known until after linking. Call a dummy
|
||||
// function that will be replaced with a load from a special ELF
|
||||
// section that contains the stack size (and is modified after
|
||||
// linking).
|
||||
stackSize = b.createCall(b.mod.NamedFunction("internal/task.getGoroutineStackSize"), []llvm.Value{callee, llvm.Undef(b.i8ptrType), llvm.Undef(b.i8ptrType)}, "stacksize")
|
||||
} else {
|
||||
// The stack size is fixed at compile time. By emitting it here as a
|
||||
// constant, it can be optimized.
|
||||
stackSize = llvm.ConstInt(b.uintptrType, b.Target.DefaultStackSize, false)
|
||||
}
|
||||
case "coroutines":
|
||||
callee = b.CreatePtrToInt(funcPtr, b.uintptrType, "")
|
||||
// There is no goroutine stack size: coroutines are used instead of
|
||||
// stacks.
|
||||
stackSize = llvm.Undef(b.uintptrType)
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
b.createCall(b.mod.NamedFunction("internal/task.start"), []llvm.Value{callee, paramBundle, llvm.Undef(b.i8ptrType), llvm.ConstPointerNull(b.i8ptrType)}, "")
|
||||
b.createCall(b.mod.NamedFunction("internal/task.start"), []llvm.Value{callee, paramBundle, stackSize, llvm.Undef(b.i8ptrType), llvm.ConstPointerNull(b.i8ptrType)}, "")
|
||||
return llvm.Undef(funcPtr.Type().ElementType().ReturnType())
|
||||
}
|
||||
|
||||
@@ -67,8 +81,9 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri
|
||||
// Create the wrapper.
|
||||
wrapperType := llvm.FunctionType(c.ctx.VoidType(), []llvm.Type{c.i8ptrType}, false)
|
||||
wrapper = llvm.AddFunction(c.mod, name+"$gowrapper", wrapperType)
|
||||
wrapper.SetLinkage(llvm.PrivateLinkage)
|
||||
wrapper.SetLinkage(llvm.InternalLinkage)
|
||||
wrapper.SetUnnamedAddr(true)
|
||||
wrapper.AddAttributeAtIndex(-1, c.ctx.CreateStringAttribute("tinygo-gowrapper", name))
|
||||
entry := c.ctx.AddBasicBlock(wrapper, "entry")
|
||||
builder.SetInsertPointAtEnd(entry)
|
||||
|
||||
@@ -125,6 +140,7 @@ func (c *compilerContext) createGoroutineStartWrapper(fn llvm.Value, prefix stri
|
||||
wrapper = llvm.AddFunction(c.mod, prefix+".gowrapper", wrapperType)
|
||||
wrapper.SetLinkage(llvm.InternalLinkage)
|
||||
wrapper.SetUnnamedAddr(true)
|
||||
wrapper.AddAttributeAtIndex(-1, c.ctx.CreateStringAttribute("tinygo-gowrapper", ""))
|
||||
entry := c.ctx.AddBasicBlock(wrapper, "entry")
|
||||
builder.SetInsertPointAtEnd(entry)
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// Version of TinyGo.
|
||||
// Update this value before release of new version of software.
|
||||
const Version = "0.14.0-dev"
|
||||
const Version = "0.15.0"
|
||||
|
||||
// GetGorootVersion returns the major and minor version for a given GOROOT path.
|
||||
// If the goroot cannot be determined, (0, 0) is returned.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Hooks for Docker Hub
|
||||
|
||||
Files in this directory are custom commands to be run during the different Docker Hub build phases.
|
||||
|
||||
See https://docs.docker.com/docker-hub/builds/advanced/#custom-build-phase-hooks
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
# Docker hub does a recursive clone, then checks the branch out,
|
||||
# so when a PR adds a submodule (or updates it), it fails.
|
||||
git submodule update --init
|
||||
+3
-1
@@ -47,10 +47,12 @@ func (e *Error) Error() string {
|
||||
// location of the instruction. The location information may not be complete as
|
||||
// it depends on debug information in the IR.
|
||||
func (e *evalPackage) errorAt(inst llvm.Value, err error) *Error {
|
||||
pos := getPosition(inst)
|
||||
return &Error{
|
||||
ImportPath: e.packagePath,
|
||||
Pos: getPosition(inst),
|
||||
Pos: pos,
|
||||
Err: err,
|
||||
Traceback: []ErrorLine{{pos, inst}},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-9
@@ -95,7 +95,11 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
|
||||
if !operand.IsConstant() || inst.IsVolatile() || (!operand.Underlying.IsAConstantExpr().IsNil() && operand.Underlying.Opcode() == llvm.BitCast) {
|
||||
value = fr.builder.CreateLoad(operand.Value(), inst.Name())
|
||||
} else {
|
||||
value = operand.Load()
|
||||
var err error
|
||||
value, err = operand.Load()
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
}
|
||||
if value.Type() != inst.Type() {
|
||||
return nil, nil, fr.errorAt(inst, errors.New("interp: load: type does not match"))
|
||||
@@ -107,7 +111,10 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
|
||||
if inst.IsVolatile() {
|
||||
fr.builder.CreateStore(value.Value(), ptr.Value())
|
||||
} else {
|
||||
ptr.Store(value.Value())
|
||||
err := ptr.Store(value.Value())
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
}
|
||||
case !inst.IsAGetElementPtrInst().IsNil():
|
||||
value := fr.getLocal(inst.Operand(0))
|
||||
@@ -308,7 +315,10 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
|
||||
}
|
||||
// "key" is a Go string value, which in the TinyGo calling convention is split up
|
||||
// into separate pointer and length parameters.
|
||||
m.PutString(keyBuf, keyLen, valPtr)
|
||||
err := m.PutString(keyBuf, keyLen, valPtr)
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
case callee.Name() == "runtime.hashmapBinarySet":
|
||||
// set a binary (int etc.) key in the map
|
||||
keyBuf := fr.getLocal(inst.Operand(1)).(*LocalValue)
|
||||
@@ -329,15 +339,24 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
|
||||
fr.builder.CreateCall(callee, llvmParams, "")
|
||||
continue
|
||||
}
|
||||
m.PutBinary(keyBuf, valPtr)
|
||||
err := m.PutBinary(keyBuf, valPtr)
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
case callee.Name() == "runtime.stringConcat":
|
||||
// adding two strings together
|
||||
buf1Ptr := fr.getLocal(inst.Operand(0))
|
||||
buf1Len := fr.getLocal(inst.Operand(1))
|
||||
buf2Ptr := fr.getLocal(inst.Operand(2))
|
||||
buf2Len := fr.getLocal(inst.Operand(3))
|
||||
buf1 := getStringBytes(buf1Ptr, buf1Len.Value())
|
||||
buf2 := getStringBytes(buf2Ptr, buf2Len.Value())
|
||||
buf1, err := getStringBytes(buf1Ptr, buf1Len.Value())
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
buf2, err := getStringBytes(buf2Ptr, buf2Len.Value())
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
result := []byte(string(buf1) + string(buf2))
|
||||
vals := make([]llvm.Value, len(result))
|
||||
for i := range vals {
|
||||
@@ -401,9 +420,15 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
|
||||
return nil, nil, fr.errorAt(inst, errors.New("interp: trying to copy a slice with negative length?"))
|
||||
}
|
||||
for i := int64(0); i < length; i++ {
|
||||
var err error
|
||||
// *dst = *src
|
||||
dstArray.Store(srcArray.Load())
|
||||
val, err := srcArray.Load()
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
err = dstArray.Store(val)
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
// dst++
|
||||
dstArrayValue, err := dstArray.GetElementPtr([]uint32{1})
|
||||
if err != nil {
|
||||
@@ -421,7 +446,10 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
|
||||
// convert a string to a []byte
|
||||
bufPtr := fr.getLocal(inst.Operand(0))
|
||||
bufLen := fr.getLocal(inst.Operand(1))
|
||||
result := getStringBytes(bufPtr, bufLen.Value())
|
||||
result, err := getStringBytes(bufPtr, bufLen.Value())
|
||||
if err != nil {
|
||||
return nil, nil, fr.errorAt(inst, err)
|
||||
}
|
||||
vals := make([]llvm.Value, len(result))
|
||||
for i := range vals {
|
||||
vals[i] = llvm.ConstInt(fr.Mod.Context().Int8Type(), uint64(result[i]), false)
|
||||
|
||||
@@ -62,6 +62,10 @@ func (e *evalPackage) hasSideEffects(fn llvm.Value) (*sideEffectResult, *Error)
|
||||
return &sideEffectResult{severity: sideEffectNone}, nil
|
||||
case name == "llvm.dbg.value":
|
||||
return &sideEffectResult{severity: sideEffectNone}, nil
|
||||
case name == "(*sync/atomic.Value).Load" || name == "(*sync/atomic.Value).Store":
|
||||
// These functions do some unsafe pointer loading/storing but are
|
||||
// otherwise safe.
|
||||
return &sideEffectResult{severity: sideEffectLimited}, nil
|
||||
case strings.HasPrefix(name, "llvm.lifetime."):
|
||||
return &sideEffectResult{severity: sideEffectNone}, nil
|
||||
}
|
||||
@@ -122,6 +126,8 @@ func (e *evalPackage) hasSideEffects(fn llvm.Value) (*sideEffectResult, *Error)
|
||||
// External function call. Assume only limited side effects
|
||||
// (no affected globals, etc.).
|
||||
switch child.Name() {
|
||||
case "runtime.alloc":
|
||||
continue
|
||||
case "runtime.typeAssert":
|
||||
continue // implemented in interp
|
||||
case "runtime.interfaceImplements":
|
||||
|
||||
+10
-5
@@ -1,6 +1,8 @@
|
||||
package interp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"tinygo.org/x/go-llvm"
|
||||
)
|
||||
|
||||
@@ -18,20 +20,23 @@ func getUses(value llvm.Value) []llvm.Value {
|
||||
|
||||
// getStringBytes loads the byte slice of a Go string represented as a
|
||||
// {ptr, len} pair.
|
||||
func getStringBytes(strPtr Value, strLen llvm.Value) []byte {
|
||||
func getStringBytes(strPtr Value, strLen llvm.Value) ([]byte, error) {
|
||||
if !strLen.IsConstant() {
|
||||
panic("getStringBytes with a non-constant length")
|
||||
return nil, errors.New("getStringBytes with a non-constant length")
|
||||
}
|
||||
buf := make([]byte, strLen.ZExtValue())
|
||||
for i := range buf {
|
||||
gep, err := strPtr.GetElementPtr([]uint32{uint32(i)})
|
||||
if err != nil {
|
||||
panic(err) // TODO
|
||||
return nil, err
|
||||
}
|
||||
c, err := gep.Load()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := gep.Load()
|
||||
buf[i] = byte(c.ZExtValue())
|
||||
}
|
||||
return buf
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// getLLVMIndices converts an []uint32 into an []llvm.Value, for use in
|
||||
|
||||
+60
-36
@@ -15,8 +15,8 @@ type Value interface {
|
||||
Value() llvm.Value // returns a LLVM value
|
||||
Type() llvm.Type // equal to Value().Type()
|
||||
IsConstant() bool // returns true if this value is a constant value
|
||||
Load() llvm.Value // dereference a pointer
|
||||
Store(llvm.Value) // store to a pointer
|
||||
Load() (llvm.Value, error) // dereference a pointer
|
||||
Store(llvm.Value) error // store to a pointer
|
||||
GetElementPtr([]uint32) (Value, error) // returns an interior pointer
|
||||
String() string // string representation, for debugging
|
||||
}
|
||||
@@ -44,29 +44,32 @@ func (v *LocalValue) IsConstant() bool {
|
||||
}
|
||||
|
||||
// Load loads a constant value if this is a constant pointer.
|
||||
func (v *LocalValue) Load() llvm.Value {
|
||||
func (v *LocalValue) Load() (llvm.Value, error) {
|
||||
if !v.Underlying.IsAGlobalVariable().IsNil() {
|
||||
return v.Underlying.Initializer()
|
||||
return v.Underlying.Initializer(), nil
|
||||
}
|
||||
switch v.Underlying.Opcode() {
|
||||
case llvm.GetElementPtr:
|
||||
indices := v.getConstGEPIndices()
|
||||
if indices[0] != 0 {
|
||||
panic("invalid GEP")
|
||||
return llvm.Value{}, errors.New("invalid GEP")
|
||||
}
|
||||
global := v.Eval.getValue(v.Underlying.Operand(0))
|
||||
agg := global.Load()
|
||||
return llvm.ConstExtractValue(agg, indices[1:])
|
||||
agg, err := global.Load()
|
||||
if err != nil {
|
||||
return llvm.Value{}, err
|
||||
}
|
||||
return llvm.ConstExtractValue(agg, indices[1:]), nil
|
||||
case llvm.BitCast:
|
||||
panic("interp: load from a bitcast")
|
||||
return llvm.Value{}, errors.New("interp: load from a bitcast")
|
||||
default:
|
||||
panic("interp: load from a constant")
|
||||
return llvm.Value{}, errors.New("interp: load from a constant")
|
||||
}
|
||||
}
|
||||
|
||||
// Store stores to the underlying value if the value type is a pointer type,
|
||||
// otherwise it panics.
|
||||
func (v *LocalValue) Store(value llvm.Value) {
|
||||
// otherwise it returns an error.
|
||||
func (v *LocalValue) Store(value llvm.Value) error {
|
||||
if !v.Underlying.IsAGlobalVariable().IsNil() {
|
||||
if !value.IsConstant() {
|
||||
v.MarkDirty()
|
||||
@@ -74,26 +77,28 @@ func (v *LocalValue) Store(value llvm.Value) {
|
||||
} else {
|
||||
v.Underlying.SetInitializer(value)
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
if !value.IsConstant() {
|
||||
v.MarkDirty()
|
||||
v.Eval.builder.CreateStore(value, v.Underlying)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
switch v.Underlying.Opcode() {
|
||||
case llvm.GetElementPtr:
|
||||
indices := v.getConstGEPIndices()
|
||||
if indices[0] != 0 {
|
||||
panic("invalid GEP")
|
||||
return errors.New("invalid GEP")
|
||||
}
|
||||
global := &LocalValue{v.Eval, v.Underlying.Operand(0)}
|
||||
agg := global.Load()
|
||||
agg, err := global.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
agg = llvm.ConstInsertValue(agg, value, indices[1:])
|
||||
global.Store(agg)
|
||||
return
|
||||
return global.Store(agg)
|
||||
default:
|
||||
panic("interp: store on a constant")
|
||||
return errors.New("interp: store on a constant")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +230,11 @@ func (v *MapValue) Value() llvm.Value {
|
||||
keyPtr := llvm.ConstExtractValue(llvmKey, []uint32{0})
|
||||
keyLen := llvm.ConstExtractValue(llvmKey, []uint32{1})
|
||||
keyPtrVal := v.Eval.getValue(keyPtr)
|
||||
keyBuf = getStringBytes(keyPtrVal, keyLen)
|
||||
var err error
|
||||
keyBuf, err = getStringBytes(keyPtrVal, keyLen)
|
||||
if err != nil {
|
||||
panic(err) // TODO
|
||||
}
|
||||
} else if key.Type().TypeKind() == llvm.IntegerTypeKind {
|
||||
keyBuf = make([]byte, v.Eval.TargetData.TypeAllocSize(key.Type()))
|
||||
n := key.Value().ZExtValue()
|
||||
@@ -299,13 +308,15 @@ func (v *MapValue) IsConstant() bool {
|
||||
}
|
||||
|
||||
// Load panics: maps are of reference type so cannot be dereferenced.
|
||||
func (v *MapValue) Load() llvm.Value {
|
||||
func (v *MapValue) Load() (llvm.Value, error) {
|
||||
panic("interp: load from a map")
|
||||
}
|
||||
|
||||
// Store panics: maps are of reference type so cannot be stored to.
|
||||
func (v *MapValue) Store(value llvm.Value) {
|
||||
panic("interp: store on a map")
|
||||
// Store returns an error: maps are of reference type so cannot be stored to.
|
||||
func (v *MapValue) Store(value llvm.Value) error {
|
||||
// This must be a bug, but it might be helpful to indicate the location
|
||||
// anyway.
|
||||
return errors.New("interp: store on a map")
|
||||
}
|
||||
|
||||
// GetElementPtr panics: maps are of reference type so their (interior)
|
||||
@@ -316,23 +327,26 @@ func (v *MapValue) GetElementPtr(indices []uint32) (Value, error) {
|
||||
|
||||
// PutString does a map assign operation, assuming that the map is of type
|
||||
// map[string]T.
|
||||
func (v *MapValue) PutString(keyBuf, keyLen, valPtr *LocalValue) {
|
||||
func (v *MapValue) PutString(keyBuf, keyLen, valPtr *LocalValue) error {
|
||||
if !v.Underlying.IsNil() {
|
||||
panic("map already created")
|
||||
return errors.New("map already created")
|
||||
}
|
||||
|
||||
if valPtr.Underlying.Opcode() == llvm.BitCast {
|
||||
valPtr = &LocalValue{v.Eval, valPtr.Underlying.Operand(0)}
|
||||
}
|
||||
value := valPtr.Load()
|
||||
value, err := valPtr.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if v.ValueType.IsNil() {
|
||||
v.ValueType = value.Type()
|
||||
if int(v.Eval.TargetData.TypeAllocSize(v.ValueType)) != v.ValueSize {
|
||||
panic("interp: map store value type has the wrong size")
|
||||
return errors.New("interp: map store value type has the wrong size")
|
||||
}
|
||||
} else {
|
||||
if value.Type() != v.ValueType {
|
||||
panic("interp: map store value type is inconsistent")
|
||||
return errors.New("interp: map store value type is inconsistent")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,26 +359,31 @@ func (v *MapValue) PutString(keyBuf, keyLen, valPtr *LocalValue) {
|
||||
// TODO: avoid duplicate keys
|
||||
v.Keys = append(v.Keys, &LocalValue{v.Eval, key})
|
||||
v.Values = append(v.Values, &LocalValue{v.Eval, value})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutBinary does a map assign operation.
|
||||
func (v *MapValue) PutBinary(keyPtr, valPtr *LocalValue) {
|
||||
func (v *MapValue) PutBinary(keyPtr, valPtr *LocalValue) error {
|
||||
if !v.Underlying.IsNil() {
|
||||
panic("map already created")
|
||||
return errors.New("map already created")
|
||||
}
|
||||
|
||||
if valPtr.Underlying.Opcode() == llvm.BitCast {
|
||||
valPtr = &LocalValue{v.Eval, valPtr.Underlying.Operand(0)}
|
||||
}
|
||||
value := valPtr.Load()
|
||||
value, err := valPtr.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if v.ValueType.IsNil() {
|
||||
v.ValueType = value.Type()
|
||||
if int(v.Eval.TargetData.TypeAllocSize(v.ValueType)) != v.ValueSize {
|
||||
panic("interp: map store value type has the wrong size")
|
||||
return errors.New("interp: map store value type has the wrong size")
|
||||
}
|
||||
} else {
|
||||
if value.Type() != v.ValueType {
|
||||
panic("interp: map store value type is inconsistent")
|
||||
return errors.New("interp: map store value type is inconsistent")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,21 +394,26 @@ func (v *MapValue) PutBinary(keyPtr, valPtr *LocalValue) {
|
||||
keyPtr = &LocalValue{v.Eval, keyPtr.Underlying.Operand(0)}
|
||||
}
|
||||
}
|
||||
key := keyPtr.Load()
|
||||
key, err := keyPtr.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if v.KeyType.IsNil() {
|
||||
v.KeyType = key.Type()
|
||||
if int(v.Eval.TargetData.TypeAllocSize(v.KeyType)) != v.KeySize {
|
||||
panic("interp: map store key type has the wrong size")
|
||||
return errors.New("interp: map store key type has the wrong size")
|
||||
}
|
||||
} else {
|
||||
if key.Type() != v.KeyType {
|
||||
panic("interp: map store key type is inconsistent")
|
||||
return errors.New("interp: map store key type is inconsistent")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: avoid duplicate keys
|
||||
v.Keys = append(v.Keys, &LocalValue{v.Eval, key})
|
||||
v.Values = append(v.Values, &LocalValue{v.Eval, value})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get FNV-1a hash of this string.
|
||||
|
||||
@@ -67,7 +67,7 @@ func NewProgram(lprogram *loader.Program) *Program {
|
||||
program := lprogram.LoadSSA()
|
||||
program.Build()
|
||||
|
||||
mainPkg := program.ImportedPackage(lprogram.MainPkg.PkgPath)
|
||||
mainPkg := program.ImportedPackage(lprogram.MainPkg().ImportPath)
|
||||
if mainPkg == nil {
|
||||
panic("could not find main package")
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func NewProgram(lprogram *loader.Program) *Program {
|
||||
}
|
||||
|
||||
for _, pkg := range lprogram.Sorted() {
|
||||
p.AddPackage(program.ImportedPackage(pkg.PkgPath))
|
||||
p.AddPackage(program.ImportedPackage(pkg.ImportPath))
|
||||
}
|
||||
|
||||
return p
|
||||
|
||||
+1
-1
Submodule lib/cmsis-svd updated: 15b462f152...d9b58694ce
+1
-1
Submodule lib/wasi-libc updated: a280fead2a...215adc8ac9
@@ -1,5 +1,7 @@
|
||||
package loader
|
||||
|
||||
import "go/scanner"
|
||||
|
||||
// Errors contains a list of parser errors or a list of typechecker errors for
|
||||
// the given package.
|
||||
type Errors struct {
|
||||
@@ -10,3 +12,14 @@ type Errors struct {
|
||||
func (e Errors) Error() string {
|
||||
return "could not compile: " + e.Errs[0].Error()
|
||||
}
|
||||
|
||||
// Error is a regular error but with an added import stack. This is especially
|
||||
// useful for debugging import cycle errors.
|
||||
type Error struct {
|
||||
ImportStack []string
|
||||
Err scanner.Error
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return e.Err.Error()
|
||||
}
|
||||
|
||||
+50
-9
@@ -8,19 +8,21 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compileopts"
|
||||
"github.com/tinygo-org/tinygo/goenv"
|
||||
)
|
||||
|
||||
var gorootCreateMutex sync.Mutex
|
||||
|
||||
// GetCachedGoroot creates a new GOROOT by merging both the standard GOROOT and
|
||||
// the GOROOT from TinyGo using lots of symbolic links.
|
||||
func GetCachedGoroot(config *compileopts.Config) (string, error) {
|
||||
@@ -49,16 +51,29 @@ func GetCachedGoroot(config *compileopts.Config) (string, error) {
|
||||
fmt.Fprintln(hash, tinygoroot)
|
||||
gorootsHash := hash.Sum(nil)
|
||||
gorootsHashHex := hex.EncodeToString(gorootsHash[:])
|
||||
cachedgoroot := filepath.Join(goenv.Get("GOCACHE"), "goroot-"+version+"-"+gorootsHashHex)
|
||||
cachedgorootName := "goroot-" + version + "-" + gorootsHashHex
|
||||
cachedgoroot := filepath.Join(goenv.Get("GOCACHE"), cachedgorootName)
|
||||
if needsSyscallPackage(config.BuildTags()) {
|
||||
cachedgoroot += "-syscall"
|
||||
}
|
||||
|
||||
// Do not try to create the cached GOROOT in parallel, that's only a waste
|
||||
// of I/O bandwidth and thus speed. Instead, use a mutex to make sure only
|
||||
// one goroutine does it at a time.
|
||||
// This is not a way to ensure atomicity (a different TinyGo invocation
|
||||
// could be creating the same directory), but instead a way to avoid
|
||||
// creating it many times in parallel when running tests in parallel.
|
||||
gorootCreateMutex.Lock()
|
||||
defer gorootCreateMutex.Unlock()
|
||||
|
||||
if _, err := os.Stat(cachedgoroot); err == nil {
|
||||
return cachedgoroot, nil
|
||||
}
|
||||
tmpgoroot := cachedgoroot + ".tmp" + strconv.Itoa(rand.Int())
|
||||
err = os.MkdirAll(tmpgoroot, 0777)
|
||||
err = os.MkdirAll(goenv.Get("GOCACHE"), 0777)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
tmpgoroot, err := ioutil.TempDir(goenv.Get("GOCACHE"), cachedgorootName+".tmp")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -85,6 +100,15 @@ func GetCachedGoroot(config *compileopts.Config) (string, error) {
|
||||
// deleted by the defer above.
|
||||
return cachedgoroot, nil
|
||||
}
|
||||
if runtime.GOOS == "windows" && os.IsPermission(err) {
|
||||
// On Windows, a rename with a destination directory that already
|
||||
// exists does not result in an IsExist error, but rather in an
|
||||
// access denied error. To be sure, check for this case by checking
|
||||
// whether the target directory exists.
|
||||
if _, err := os.Stat(cachedgoroot); err == nil {
|
||||
return cachedgoroot, nil
|
||||
}
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return cachedgoroot, nil
|
||||
@@ -165,7 +189,7 @@ func mergeDirectory(goroot, tinygoroot, tmpgoroot, importPath string, overrides
|
||||
// with the TinyGo version. This is the case on some targets.
|
||||
func needsSyscallPackage(buildTags []string) bool {
|
||||
for _, tag := range buildTags {
|
||||
if tag == "baremetal" || tag == "darwin" {
|
||||
if tag == "baremetal" || tag == "darwin" || tag == "nintendoswitch" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -188,7 +212,7 @@ func pathsToOverride(needsSyscallPackage bool) map[string]bool {
|
||||
"reflect/": false,
|
||||
"runtime/": false,
|
||||
"sync/": true,
|
||||
"testing/": false,
|
||||
"testing/": true,
|
||||
}
|
||||
if needsSyscallPackage {
|
||||
paths["syscall/"] = true // include syscall/js
|
||||
@@ -228,10 +252,27 @@ func symlink(oldname, newname string) error {
|
||||
return symlinkErr
|
||||
}
|
||||
} else {
|
||||
// Make a hard link.
|
||||
// Try making a hard link.
|
||||
err := os.Link(oldname, newname)
|
||||
if err != nil {
|
||||
return symlinkErr
|
||||
// Making a hardlink failed. Try copying the file as a last
|
||||
// fallback.
|
||||
inf, err := os.Open(oldname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer inf.Close()
|
||||
outf, err := os.Create(newname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer outf.Close()
|
||||
_, err = io.Copy(outf, inf)
|
||||
if err != nil {
|
||||
os.Remove(newname)
|
||||
return err
|
||||
}
|
||||
// File was copied.
|
||||
}
|
||||
}
|
||||
return nil // success
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compileopts"
|
||||
)
|
||||
|
||||
// List returns a ready-to-run *exec.Cmd for running the `go list` command with
|
||||
// the configuration used for TinyGo.
|
||||
func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, error) {
|
||||
goroot, err := GetCachedGoroot(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args := append([]string{"list"}, extraArgs...)
|
||||
if len(config.BuildTags()) != 0 {
|
||||
args = append(args, "-tags", strings.Join(config.BuildTags(), " "))
|
||||
}
|
||||
args = append(args, pkgs...)
|
||||
cgoEnabled := "0"
|
||||
if config.CgoEnabled() {
|
||||
cgoEnabled = "1"
|
||||
}
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled)
|
||||
return cmd, nil
|
||||
}
|
||||
+186
-255
@@ -2,165 +2,178 @@ package loader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/parser"
|
||||
"go/scanner"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"syscall"
|
||||
|
||||
"github.com/tinygo-org/tinygo/cgo"
|
||||
"github.com/tinygo-org/tinygo/compileopts"
|
||||
"github.com/tinygo-org/tinygo/goenv"
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
// Program holds all packages and some metadata about the program as a whole.
|
||||
type Program struct {
|
||||
Build *build.Context
|
||||
Tests bool
|
||||
Packages map[string]*Package
|
||||
MainPkg *Package
|
||||
sorted []*Package
|
||||
fset *token.FileSet
|
||||
TypeChecker types.Config
|
||||
Dir string // current working directory (for error reporting)
|
||||
TINYGOROOT string // root of the TinyGo installation or root of the source code
|
||||
CFlags []string
|
||||
LDFlags []string
|
||||
ClangHeaders string
|
||||
config *compileopts.Config
|
||||
clangHeaders string
|
||||
typeChecker types.Config
|
||||
goroot string // synthetic GOROOT
|
||||
workingDir string
|
||||
|
||||
Packages map[string]*Package
|
||||
sorted []*Package
|
||||
fset *token.FileSet
|
||||
|
||||
// Information obtained during parsing.
|
||||
LDFlags []string
|
||||
}
|
||||
|
||||
// PackageJSON is a subset of the JSON struct returned from `go list`.
|
||||
type PackageJSON struct {
|
||||
Dir string
|
||||
ImportPath string
|
||||
ForTest string
|
||||
|
||||
// Source files
|
||||
GoFiles []string
|
||||
CgoFiles []string
|
||||
CFiles []string
|
||||
|
||||
// Dependency information
|
||||
Imports []string
|
||||
ImportMap map[string]string
|
||||
|
||||
// Error information
|
||||
Error *struct {
|
||||
ImportStack []string
|
||||
Pos string
|
||||
Err string
|
||||
}
|
||||
}
|
||||
|
||||
// Package holds a loaded package, its imports, and its parsed files.
|
||||
type Package struct {
|
||||
*Program
|
||||
*packages.Package
|
||||
Files []*ast.File
|
||||
Pkg *types.Package
|
||||
types.Info
|
||||
PackageJSON
|
||||
|
||||
program *Program
|
||||
Files []*ast.File
|
||||
Pkg *types.Package
|
||||
info types.Info
|
||||
}
|
||||
|
||||
// Load loads the given package with all dependencies (including the runtime
|
||||
// package). Call .Parse() afterwards to parse all Go files (including CGo
|
||||
// processing, if necessary).
|
||||
func (p *Program) Load(importPath string) error {
|
||||
if p.Packages == nil {
|
||||
p.Packages = make(map[string]*Package)
|
||||
func Load(config *compileopts.Config, inputPkgs []string, clangHeaders string, typeChecker types.Config) (*Program, error) {
|
||||
goroot, err := GetCachedGoroot(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := &Program{
|
||||
config: config,
|
||||
clangHeaders: clangHeaders,
|
||||
typeChecker: typeChecker,
|
||||
goroot: goroot,
|
||||
workingDir: wd,
|
||||
Packages: make(map[string]*Package),
|
||||
fset: token.NewFileSet(),
|
||||
}
|
||||
|
||||
err := p.loadPackage(importPath)
|
||||
// List the dependencies of this package, in raw JSON format.
|
||||
extraArgs := []string{"-json", "-deps"}
|
||||
if config.TestConfig.CompileTestBinary {
|
||||
extraArgs = append(extraArgs, "-test")
|
||||
}
|
||||
cmd, err := List(config, extraArgs, inputPkgs)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
p.MainPkg = p.sorted[len(p.sorted)-1]
|
||||
if _, ok := p.Packages["runtime"]; !ok {
|
||||
// The runtime package wasn't loaded. Although `go list -deps` seems to
|
||||
// return the full dependency list, there is no way to get those
|
||||
// packages from the go/packages package. Therefore load the runtime
|
||||
// manually and add it to the list of to-be-compiled packages
|
||||
// (duplicates are already filtered).
|
||||
return p.loadPackage("runtime")
|
||||
buf := &bytes.Buffer{}
|
||||
cmd.Stdout = buf
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
|
||||
os.Exit(status.ExitStatus())
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to run `go list`: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Program) loadPackage(importPath string) error {
|
||||
cgoEnabled := "0"
|
||||
if p.Build.CgoEnabled {
|
||||
cgoEnabled = "1"
|
||||
}
|
||||
pkgs, err := packages.Load(&packages.Config{
|
||||
Mode: packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps,
|
||||
Env: append(os.Environ(), "GOROOT="+p.Build.GOROOT, "GOOS="+p.Build.GOOS, "GOARCH="+p.Build.GOARCH, "CGO_ENABLED="+cgoEnabled),
|
||||
BuildFlags: []string{"-tags", strings.Join(p.Build.BuildTags, " ")},
|
||||
Tests: p.Tests,
|
||||
}, importPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var pkg *packages.Package
|
||||
if p.Tests {
|
||||
// We need the second package. Quoting from the docs:
|
||||
// > For example, when using the go command, loading "fmt" with Tests=true
|
||||
// > returns four packages, with IDs "fmt" (the standard package),
|
||||
// > "fmt [fmt.test]" (the package as compiled for the test),
|
||||
// > "fmt_test" (the test functions from source files in package fmt_test),
|
||||
// > and "fmt.test" (the test binary).
|
||||
pkg = pkgs[1]
|
||||
} else {
|
||||
if len(pkgs) != 1 {
|
||||
return fmt.Errorf("expected exactly one package while importing %s, got %d", importPath, len(pkgs))
|
||||
// Parse the returned json from `go list`.
|
||||
decoder := json.NewDecoder(buf)
|
||||
for {
|
||||
pkg := &Package{
|
||||
program: p,
|
||||
info: types.Info{
|
||||
Types: make(map[ast.Expr]types.TypeAndValue),
|
||||
Defs: make(map[*ast.Ident]types.Object),
|
||||
Uses: make(map[*ast.Ident]types.Object),
|
||||
Implicits: make(map[ast.Node]types.Object),
|
||||
Scopes: make(map[ast.Node]*types.Scope),
|
||||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
},
|
||||
}
|
||||
pkg = pkgs[0]
|
||||
}
|
||||
var importError *Errors
|
||||
var addPackages func(pkg *packages.Package)
|
||||
addPackages = func(pkg *packages.Package) {
|
||||
if _, ok := p.Packages[pkg.PkgPath]; ok {
|
||||
return
|
||||
err := decoder.Decode(&pkg.PackageJSON)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
pkg2 := p.newPackage(pkg)
|
||||
p.Packages[pkg.PkgPath] = pkg2
|
||||
if len(pkg.Errors) != 0 {
|
||||
if importError != nil {
|
||||
// There was another error reported already. Do not report
|
||||
// errors from multiple packages at once.
|
||||
return
|
||||
}
|
||||
importError = &Errors{
|
||||
Pkg: pkg2,
|
||||
}
|
||||
for _, err := range pkg.Errors {
|
||||
pos := token.Position{}
|
||||
fields := strings.Split(err.Pos, ":")
|
||||
if len(fields) >= 2 {
|
||||
// There is some file/line/column information.
|
||||
if n, err := strconv.Atoi(fields[len(fields)-2]); err == nil {
|
||||
// Format: filename.go:line:colum
|
||||
pos.Filename = strings.Join(fields[:len(fields)-2], ":")
|
||||
pos.Line = n
|
||||
pos.Column, _ = strconv.Atoi(fields[len(fields)-1])
|
||||
} else {
|
||||
// Format: filename.go:line
|
||||
pos.Filename = strings.Join(fields[:len(fields)-1], ":")
|
||||
pos.Line, _ = strconv.Atoi(fields[len(fields)-1])
|
||||
}
|
||||
pos.Filename = p.getOriginalPath(pos.Filename)
|
||||
if pkg.Error != nil {
|
||||
// There was an error while importing (for example, a circular
|
||||
// dependency).
|
||||
pos := token.Position{}
|
||||
fields := strings.Split(pkg.Error.Pos, ":")
|
||||
if len(fields) >= 2 {
|
||||
// There is some file/line/column information.
|
||||
if n, err := strconv.Atoi(fields[len(fields)-2]); err == nil {
|
||||
// Format: filename.go:line:colum
|
||||
pos.Filename = strings.Join(fields[:len(fields)-2], ":")
|
||||
pos.Line = n
|
||||
pos.Column, _ = strconv.Atoi(fields[len(fields)-1])
|
||||
} else {
|
||||
// Format: filename.go:line
|
||||
pos.Filename = strings.Join(fields[:len(fields)-1], ":")
|
||||
pos.Line, _ = strconv.Atoi(fields[len(fields)-1])
|
||||
}
|
||||
importError.Errs = append(importError.Errs, scanner.Error{
|
||||
Pos: pos,
|
||||
Msg: err.Msg,
|
||||
})
|
||||
pos.Filename = p.getOriginalPath(pos.Filename)
|
||||
}
|
||||
return
|
||||
err := scanner.Error{
|
||||
Pos: pos,
|
||||
Msg: pkg.Error.Err,
|
||||
}
|
||||
if len(pkg.Error.ImportStack) != 0 {
|
||||
return nil, Error{
|
||||
ImportStack: pkg.Error.ImportStack,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get the list of imports (sorted alphabetically).
|
||||
names := make([]string, 0, len(pkg.Imports))
|
||||
for name := range pkg.Imports {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
// Add all the imports.
|
||||
for _, name := range names {
|
||||
addPackages(pkg.Imports[name])
|
||||
}
|
||||
|
||||
p.sorted = append(p.sorted, pkg2)
|
||||
p.sorted = append(p.sorted, pkg)
|
||||
p.Packages[pkg.ImportPath] = pkg
|
||||
}
|
||||
addPackages(pkg)
|
||||
if importError != nil {
|
||||
return *importError
|
||||
}
|
||||
return nil
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// getOriginalPath looks whether this path is in the generated GOROOT and if so,
|
||||
@@ -168,23 +181,23 @@ func (p *Program) loadPackage(importPath string) error {
|
||||
// the input path is returned.
|
||||
func (p *Program) getOriginalPath(path string) string {
|
||||
originalPath := path
|
||||
if strings.HasPrefix(path, p.Build.GOROOT+string(filepath.Separator)) {
|
||||
if strings.HasPrefix(path, p.goroot+string(filepath.Separator)) {
|
||||
// If this file is part of the synthetic GOROOT, try to infer the
|
||||
// original path.
|
||||
relpath := path[len(filepath.Join(p.Build.GOROOT, "src"))+1:]
|
||||
relpath := path[len(filepath.Join(p.goroot, "src"))+1:]
|
||||
realgorootPath := filepath.Join(goenv.Get("GOROOT"), "src", relpath)
|
||||
if _, err := os.Stat(realgorootPath); err == nil {
|
||||
originalPath = realgorootPath
|
||||
}
|
||||
maybeInTinyGoRoot := false
|
||||
for prefix := range pathsToOverride(needsSyscallPackage(p.Build.BuildTags)) {
|
||||
for prefix := range pathsToOverride(needsSyscallPackage(p.config.BuildTags())) {
|
||||
if !strings.HasPrefix(relpath, prefix) {
|
||||
continue
|
||||
}
|
||||
maybeInTinyGoRoot = true
|
||||
}
|
||||
if maybeInTinyGoRoot {
|
||||
tinygoPath := filepath.Join(p.TINYGOROOT, "src", relpath)
|
||||
tinygoPath := filepath.Join(goenv.Get("TINYGOROOT"), "src", relpath)
|
||||
if _, err := os.Stat(tinygoPath); err == nil {
|
||||
originalPath = tinygoPath
|
||||
}
|
||||
@@ -193,28 +206,18 @@ func (p *Program) getOriginalPath(path string) string {
|
||||
return originalPath
|
||||
}
|
||||
|
||||
// newPackage instantiates a new *Package object with initialized members.
|
||||
func (p *Program) newPackage(pkg *packages.Package) *Package {
|
||||
return &Package{
|
||||
Program: p,
|
||||
Package: pkg,
|
||||
Info: types.Info{
|
||||
Types: make(map[ast.Expr]types.TypeAndValue),
|
||||
Defs: make(map[*ast.Ident]types.Object),
|
||||
Uses: make(map[*ast.Ident]types.Object),
|
||||
Implicits: make(map[ast.Node]types.Object),
|
||||
Scopes: make(map[ast.Node]*types.Scope),
|
||||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Sorted returns a list of all packages, sorted in a way that no packages come
|
||||
// before the packages they depend upon.
|
||||
func (p *Program) Sorted() []*Package {
|
||||
return p.sorted
|
||||
}
|
||||
|
||||
// MainPkg returns the last package in the Sorted() slice. This is the main
|
||||
// package of the program.
|
||||
func (p *Program) MainPkg() *Package {
|
||||
return p.sorted[len(p.sorted)-1]
|
||||
}
|
||||
|
||||
// Parse parses all packages and typechecks them.
|
||||
//
|
||||
// The returned error may be an Errors error, which contains a list of errors.
|
||||
@@ -222,22 +225,16 @@ func (p *Program) Sorted() []*Package {
|
||||
// Idempotent.
|
||||
func (p *Program) Parse() error {
|
||||
// Parse all packages.
|
||||
for _, pkg := range p.Sorted() {
|
||||
// TODO: do this in parallel.
|
||||
for _, pkg := range p.sorted {
|
||||
err := pkg.Parse()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if p.Tests {
|
||||
err := p.swapTestMain()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Typecheck all packages.
|
||||
for _, pkg := range p.Sorted() {
|
||||
for _, pkg := range p.sorted {
|
||||
err := pkg.Check()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -247,82 +244,6 @@ func (p *Program) Parse() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Program) swapTestMain() error {
|
||||
var tests []string
|
||||
|
||||
isTestFunc := func(f *ast.FuncDecl) bool {
|
||||
// TODO: improve signature check
|
||||
if strings.HasPrefix(f.Name.Name, "Test") && f.Name.Name != "TestMain" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
for _, f := range p.MainPkg.Files {
|
||||
for i, d := range f.Decls {
|
||||
switch v := d.(type) {
|
||||
case *ast.FuncDecl:
|
||||
if isTestFunc(v) {
|
||||
tests = append(tests, v.Name.Name)
|
||||
}
|
||||
if v.Name.Name == "main" {
|
||||
// Remove main
|
||||
if len(f.Decls) == 1 {
|
||||
f.Decls = make([]ast.Decl, 0)
|
||||
} else {
|
||||
f.Decls[i] = f.Decls[len(f.Decls)-1]
|
||||
f.Decls = f.Decls[:len(f.Decls)-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check if they defined a TestMain and call it instead of testing.TestMain
|
||||
const mainBody = `package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func main () {
|
||||
m := &testing.M{
|
||||
Tests: []testing.TestToCall{
|
||||
{{range .TestFunctions}}
|
||||
{Name: "{{.}}", Func: {{.}}},
|
||||
{{end}}
|
||||
},
|
||||
}
|
||||
|
||||
testing.TestMain(m)
|
||||
}
|
||||
`
|
||||
tmpl := template.Must(template.New("testmain").Parse(mainBody))
|
||||
b := bytes.Buffer{}
|
||||
tmplData := struct {
|
||||
TestFunctions []string
|
||||
}{
|
||||
TestFunctions: tests,
|
||||
}
|
||||
|
||||
err := tmpl.Execute(&b, tmplData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := filepath.Join(p.MainPkg.Dir, "$testmain.go")
|
||||
|
||||
if p.fset == nil {
|
||||
p.fset = token.NewFileSet()
|
||||
}
|
||||
|
||||
newMain, err := parser.ParseFile(p.fset, path, b.Bytes(), parser.AllErrors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.MainPkg.Files = append(p.MainPkg.Files, newMain)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseFile is a wrapper around parser.ParseFile.
|
||||
func (p *Program) parseFile(path string, mode parser.Mode) (*ast.File, error) {
|
||||
if p.fset == nil {
|
||||
@@ -342,14 +263,13 @@ func (p *Program) parseFile(path string, mode parser.Mode) (*ast.File, error) {
|
||||
// Idempotent.
|
||||
func (p *Package) Parse() error {
|
||||
if len(p.Files) != 0 {
|
||||
return nil
|
||||
return nil // nothing to do (?)
|
||||
}
|
||||
|
||||
// Load the AST.
|
||||
// TODO: do this in parallel.
|
||||
if p.PkgPath == "unsafe" {
|
||||
// Special case for the unsafe package. Don't even bother loading
|
||||
// the files.
|
||||
if p.ImportPath == "unsafe" {
|
||||
// Special case for the unsafe package, which is defined internally by
|
||||
// the types package.
|
||||
p.Pkg = types.Unsafe
|
||||
return nil
|
||||
}
|
||||
@@ -369,11 +289,11 @@ func (p *Package) Parse() error {
|
||||
// Idempotent.
|
||||
func (p *Package) Check() error {
|
||||
if p.Pkg != nil {
|
||||
return nil
|
||||
return nil // already typechecked
|
||||
}
|
||||
|
||||
var typeErrors []error
|
||||
checker := p.TypeChecker
|
||||
checker := p.program.typeChecker // make a copy, because it will be modified
|
||||
checker.Error = func(err error) {
|
||||
typeErrors = append(typeErrors, err)
|
||||
}
|
||||
@@ -381,7 +301,7 @@ func (p *Package) Check() error {
|
||||
// Do typechecking of the package.
|
||||
checker.Importer = p
|
||||
|
||||
typesPkg, err := checker.Check(p.PkgPath, p.fset, p.Files, &p.Info)
|
||||
typesPkg, err := checker.Check(p.ImportPath, p.program.fset, p.Files, &p.info)
|
||||
if err != nil {
|
||||
if err, ok := err.(Errors); ok {
|
||||
return err
|
||||
@@ -394,40 +314,46 @@ func (p *Package) Check() error {
|
||||
|
||||
// parseFiles parses the loaded list of files and returns this list.
|
||||
func (p *Package) parseFiles() ([]*ast.File, error) {
|
||||
// TODO: do this concurrently.
|
||||
var files []*ast.File
|
||||
var fileErrs []error
|
||||
|
||||
var cgoFiles []*ast.File
|
||||
for _, file := range p.GoFiles {
|
||||
f, err := p.parseFile(file, parser.ParseComments)
|
||||
// Parse all files (incuding CgoFiles).
|
||||
parseFile := func(file string) {
|
||||
if !filepath.IsAbs(file) {
|
||||
file = filepath.Join(p.Dir, file)
|
||||
}
|
||||
f, err := p.program.parseFile(file, parser.ParseComments)
|
||||
if err != nil {
|
||||
fileErrs = append(fileErrs, err)
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
fileErrs = append(fileErrs, err)
|
||||
continue
|
||||
}
|
||||
for _, importSpec := range f.Imports {
|
||||
if importSpec.Path.Value == `"C"` {
|
||||
cgoFiles = append(cgoFiles, f)
|
||||
}
|
||||
return
|
||||
}
|
||||
files = append(files, f)
|
||||
}
|
||||
if len(cgoFiles) != 0 {
|
||||
cflags := append(p.CFlags, "-I"+filepath.Dir(p.GoFiles[0]))
|
||||
if p.ClangHeaders != "" {
|
||||
cflags = append(cflags, "-Xclang", "-internal-isystem", "-Xclang", p.ClangHeaders)
|
||||
for _, file := range p.GoFiles {
|
||||
parseFile(file)
|
||||
}
|
||||
for _, file := range p.CgoFiles {
|
||||
parseFile(file)
|
||||
}
|
||||
|
||||
// Do CGo processing.
|
||||
if len(p.CgoFiles) != 0 {
|
||||
var cflags []string
|
||||
cflags = append(cflags, p.program.config.CFlags()...)
|
||||
cflags = append(cflags, "-I"+p.Dir)
|
||||
if p.program.clangHeaders != "" {
|
||||
cflags = append(cflags, "-Xclang", "-internal-isystem", "-Xclang", p.program.clangHeaders)
|
||||
}
|
||||
generated, ldflags, errs := cgo.Process(files, p.Program.Dir, p.fset, cflags)
|
||||
generated, ldflags, errs := cgo.Process(files, p.program.workingDir, p.program.fset, cflags)
|
||||
if errs != nil {
|
||||
fileErrs = append(fileErrs, errs...)
|
||||
}
|
||||
files = append(files, generated)
|
||||
p.LDFlags = append(p.LDFlags, ldflags...)
|
||||
p.program.LDFlags = append(p.program.LDFlags, ldflags...)
|
||||
}
|
||||
|
||||
// Only return an error after CGo processing, so that errors in parsing and
|
||||
// CGo can be reported together.
|
||||
if len(fileErrs) != 0 {
|
||||
return nil, Errors{p, fileErrs}
|
||||
}
|
||||
@@ -441,8 +367,13 @@ func (p *Package) Import(to string) (*types.Package, error) {
|
||||
if to == "unsafe" {
|
||||
return types.Unsafe, nil
|
||||
}
|
||||
if _, ok := p.Imports[to]; ok {
|
||||
return p.Packages[p.Imports[to].PkgPath].Pkg, nil
|
||||
if replace, ok := p.ImportMap[to]; ok {
|
||||
// This import path should be replaced by another import path, according
|
||||
// to `go list`.
|
||||
to = replace
|
||||
}
|
||||
if imported, ok := p.program.Packages[to]; ok {
|
||||
return imported.Pkg, nil
|
||||
} else {
|
||||
return nil, errors.New("package not imported: " + to)
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ import (
|
||||
func (p *Program) LoadSSA() *ssa.Program {
|
||||
prog := ssa.NewProgram(p.fset, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug)
|
||||
|
||||
for _, pkg := range p.Sorted() {
|
||||
prog.CreatePackage(pkg.Pkg, pkg.Files, &pkg.Info, true)
|
||||
for _, pkg := range p.sorted {
|
||||
prog.CreatePackage(pkg.Pkg, pkg.Files, &pkg.info, true)
|
||||
}
|
||||
|
||||
return prog
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"go/scanner"
|
||||
"go/types"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
@@ -28,6 +29,12 @@ import (
|
||||
"go.bug.st/serial"
|
||||
)
|
||||
|
||||
var (
|
||||
// This variable is set at build time using -ldflags parameters.
|
||||
// See: https://stackoverflow.com/a/11355611
|
||||
gitSha1 string
|
||||
)
|
||||
|
||||
// commandError is an error type to wrap os/exec.Command errors. This provides
|
||||
// some more information regarding what went wrong while running a command.
|
||||
type commandError struct {
|
||||
@@ -58,33 +65,23 @@ func moveFile(src, dst string) error {
|
||||
return os.Remove(src)
|
||||
}
|
||||
|
||||
// copyFile copies the given file from src to dst. It copies first to a .tmp
|
||||
// file which is then moved over a possibly already existing file at the
|
||||
// destination.
|
||||
// copyFile copies the given file from src to dst. It can copy over
|
||||
// a possibly already existing file at the destination.
|
||||
func copyFile(src, dst string) error {
|
||||
inf, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer inf.Close()
|
||||
outpath := dst + ".tmp"
|
||||
outf, err := os.Create(outpath)
|
||||
source, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
_, err = io.Copy(outf, inf)
|
||||
if err != nil {
|
||||
os.Remove(outpath)
|
||||
return err
|
||||
}
|
||||
|
||||
err = outf.Close()
|
||||
destination, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer destination.Close()
|
||||
|
||||
return os.Rename(dst+".tmp", dst)
|
||||
_, err = io.Copy(destination, source)
|
||||
return err
|
||||
}
|
||||
|
||||
// Build compiles and links the given package and writes it to outpath.
|
||||
@@ -94,10 +91,10 @@ func Build(pkgName, outpath string, options *compileopts.Options) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return builder.Build(pkgName, outpath, config, func(tmppath string) error {
|
||||
if err := os.Rename(tmppath, outpath); err != nil {
|
||||
return builder.Build(pkgName, outpath, config, func(result builder.BuildResult) error {
|
||||
if err := os.Rename(result.Binary, outpath); err != nil {
|
||||
// Moving failed. Do a file copy.
|
||||
inf, err := os.Open(tmppath)
|
||||
inf, err := os.Open(result.Binary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -130,16 +127,11 @@ func Test(pkgName string, options *compileopts.Options) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Add test build tag. This is incorrect: `go test` only looks at the
|
||||
// _test.go file suffix but does not add the test build tag in the process.
|
||||
// However, it's a simple fix right now.
|
||||
// For details: https://github.com/golang/go/issues/21360
|
||||
config.Target.BuildTags = append(config.Target.BuildTags, "test")
|
||||
|
||||
return builder.Build(pkgName, ".elf", config, func(tmppath string) error {
|
||||
cmd := exec.Command(tmppath)
|
||||
return builder.Build(pkgName, ".elf", config, func(result builder.BuildResult) error {
|
||||
cmd := exec.Command(result.Binary)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Dir = result.MainDir
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
// Propagate the exit code
|
||||
@@ -149,7 +141,7 @@ func Test(pkgName string, options *compileopts.Options) error {
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
return &commandError{"failed to run compiled binary", tmppath, err}
|
||||
return &commandError{"failed to run compiled binary", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -193,9 +185,9 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||
return errors.New("unknown flash method: " + flashMethod)
|
||||
}
|
||||
|
||||
return builder.Build(pkgName, fileExt, config, func(tmppath string) error {
|
||||
return builder.Build(pkgName, fileExt, config, func(result builder.BuildResult) error {
|
||||
// do we need port reset to put MCU into bootloader mode?
|
||||
if config.Target.PortReset == "true" {
|
||||
if config.Target.PortReset == "true" && flashMethod != "openocd" {
|
||||
if port == "" {
|
||||
var err error
|
||||
port, err = getDefaultPort()
|
||||
@@ -206,7 +198,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||
|
||||
err := touchSerialPortAt1200bps(port)
|
||||
if err != nil {
|
||||
return &commandError{"failed to reset port", tmppath, err}
|
||||
return &commandError{"failed to reset port", result.Binary, err}
|
||||
}
|
||||
// give the target MCU a chance to restart into bootloader
|
||||
time.Sleep(3 * time.Second)
|
||||
@@ -218,7 +210,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||
// Create the command.
|
||||
flashCmd := config.Target.FlashCommand
|
||||
fileToken := "{" + fileExt[1:] + "}"
|
||||
flashCmd = strings.Replace(flashCmd, fileToken, tmppath, -1)
|
||||
flashCmd = strings.Replace(flashCmd, fileToken, result.Binary, -1)
|
||||
|
||||
if port == "" && strings.Contains(flashCmd, "{port}") {
|
||||
var err error
|
||||
@@ -248,21 +240,21 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||
cmd.Dir = goenv.Get("TINYGOROOT")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return &commandError{"failed to flash", tmppath, err}
|
||||
return &commandError{"failed to flash", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
case "msd":
|
||||
switch fileExt {
|
||||
case ".uf2":
|
||||
err := flashUF2UsingMSD(config.Target.FlashVolume, tmppath)
|
||||
err := flashUF2UsingMSD(config.Target.FlashVolume, result.Binary)
|
||||
if err != nil {
|
||||
return &commandError{"failed to flash", tmppath, err}
|
||||
return &commandError{"failed to flash", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
case ".hex":
|
||||
err := flashHexUsingMSD(config.Target.FlashVolume, tmppath)
|
||||
err := flashHexUsingMSD(config.Target.FlashVolume, result.Binary)
|
||||
if err != nil {
|
||||
return &commandError{"failed to flash", tmppath, err}
|
||||
return &commandError{"failed to flash", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
@@ -273,13 +265,13 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args = append(args, "-c", "program "+tmppath+" reset exit")
|
||||
args = append(args, "-c", "program "+filepath.ToSlash(result.Binary)+" reset exit")
|
||||
cmd := exec.Command("openocd", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return &commandError{"failed to flash", tmppath, err}
|
||||
return &commandError{"failed to flash", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
@@ -304,7 +296,7 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||
return errors.New("gdb not configured in the target specification")
|
||||
}
|
||||
|
||||
return builder.Build(pkgName, "", config, func(tmppath string) error {
|
||||
return builder.Build(pkgName, "", config, func(result builder.BuildResult) error {
|
||||
// Find a good way to run GDB.
|
||||
gdbInterface, openocdInterface := config.Programmer()
|
||||
switch gdbInterface {
|
||||
@@ -367,7 +359,7 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||
gdbCommands = append(gdbCommands, "target remote :1234")
|
||||
|
||||
// Run in an emulator.
|
||||
args := append(config.Target.Emulator[1:], tmppath, "-s", "-S")
|
||||
args := append(config.Target.Emulator[1:], result.Binary, "-s", "-S")
|
||||
daemon = exec.Command(config.Target.Emulator[0], args...)
|
||||
daemon.Stdout = os.Stdout
|
||||
daemon.Stderr = os.Stderr
|
||||
@@ -375,7 +367,7 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||
gdbCommands = append(gdbCommands, "target remote :2345")
|
||||
|
||||
// Run in an emulator.
|
||||
args := append(config.Target.Emulator[1:], tmppath, "-g")
|
||||
args := append(config.Target.Emulator[1:], result.Binary, "-g")
|
||||
daemon = exec.Command(config.Target.Emulator[0], args...)
|
||||
daemon.Stdout = os.Stdout
|
||||
daemon.Stderr = os.Stderr
|
||||
@@ -413,7 +405,7 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||
// Construct and execute a gdb command.
|
||||
// By default: gdb -ex run <binary>
|
||||
// Exit GDB with Ctrl-D.
|
||||
params := []string{tmppath}
|
||||
params := []string{result.Binary}
|
||||
for _, cmd := range gdbCommands {
|
||||
params = append(params, "-ex", cmd)
|
||||
}
|
||||
@@ -423,7 +415,7 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return &commandError{"failed to run gdb with", tmppath, err}
|
||||
return &commandError{"failed to run gdb with", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -439,10 +431,10 @@ func Run(pkgName string, options *compileopts.Options) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return builder.Build(pkgName, ".elf", config, func(tmppath string) error {
|
||||
return builder.Build(pkgName, ".elf", config, func(result builder.BuildResult) error {
|
||||
if len(config.Target.Emulator) == 0 {
|
||||
// Run directly.
|
||||
cmd := exec.Command(tmppath)
|
||||
cmd := exec.Command(result.Binary)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
@@ -451,12 +443,12 @@ func Run(pkgName string, options *compileopts.Options) error {
|
||||
// Workaround for QEMU which always exits with an error.
|
||||
return nil
|
||||
}
|
||||
return &commandError{"failed to run compiled binary", tmppath, err}
|
||||
return &commandError{"failed to run compiled binary", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
// Run in an emulator.
|
||||
args := append(config.Target.Emulator[1:], tmppath)
|
||||
args := append(config.Target.Emulator[1:], result.Binary)
|
||||
cmd := exec.Command(config.Target.Emulator[0], args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
@@ -466,7 +458,7 @@ func Run(pkgName string, options *compileopts.Options) error {
|
||||
// Workaround for QEMU which always exits with an error.
|
||||
return nil
|
||||
}
|
||||
return &commandError{"failed to run emulator with", tmppath, err}
|
||||
return &commandError{"failed to run emulator with", result.Binary, err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -652,36 +644,6 @@ func getDefaultPort() (port string, err error) {
|
||||
return d[0], nil
|
||||
}
|
||||
|
||||
// runGoList runs the `go list` command but using the configuration used for
|
||||
// TinyGo.
|
||||
func runGoList(config *compileopts.Config, flagJSON, flagDeps bool, pkgs []string) error {
|
||||
goroot, err := loader.GetCachedGoroot(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{"list"}
|
||||
if flagJSON {
|
||||
args = append(args, "-json")
|
||||
}
|
||||
if flagDeps {
|
||||
args = append(args, "-deps")
|
||||
}
|
||||
if len(config.BuildTags()) != 0 {
|
||||
args = append(args, "-tags", strings.Join(config.BuildTags(), " "))
|
||||
}
|
||||
args = append(args, pkgs...)
|
||||
cgoEnabled := "0"
|
||||
if config.CgoEnabled() {
|
||||
cgoEnabled = "1"
|
||||
}
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled)
|
||||
cmd.Run()
|
||||
return nil
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintln(os.Stderr, "TinyGo is a Go compiler for small places.")
|
||||
fmt.Fprintln(os.Stderr, "version:", goenv.Version)
|
||||
@@ -755,10 +717,16 @@ func printCompilerError(logln func(...interface{}), err error) {
|
||||
}
|
||||
}
|
||||
case loader.Errors:
|
||||
logln("#", err.Pkg.PkgPath)
|
||||
logln("#", err.Pkg.ImportPath)
|
||||
for _, err := range err.Errs {
|
||||
printCompilerError(logln, err)
|
||||
}
|
||||
case loader.Error:
|
||||
logln(err.Err.Error())
|
||||
logln("package", err.ImportStack[0])
|
||||
for _, pkgPath := range err.ImportStack[1:] {
|
||||
logln("\timports", pkgPath)
|
||||
}
|
||||
case *builder.MultiError:
|
||||
for _, err := range err.Errs {
|
||||
printCompilerError(logln, err)
|
||||
@@ -796,6 +764,7 @@ func main() {
|
||||
tags := flag.String("tags", "", "a space-separated list of extra build tags")
|
||||
target := flag.String("target", "", "LLVM target | .json file with TargetSpec")
|
||||
printSize := flag.String("size", "", "print sizes (none, short, full)")
|
||||
printStacks := flag.Bool("print-stacks", false, "print stack sizes of goroutines")
|
||||
nodebug := flag.Bool("no-debug", false, "disable DWARF debug symbol generation")
|
||||
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
|
||||
port := flag.String("port", "", "flash port")
|
||||
@@ -835,6 +804,7 @@ func main() {
|
||||
VerifyIR: *verifyIR,
|
||||
Debug: !*nodebug,
|
||||
PrintSizes: *printSize,
|
||||
PrintStacks: *printStacks,
|
||||
Tags: *tags,
|
||||
WasmAbi: *wasmAbi,
|
||||
Programmer: *programmer,
|
||||
@@ -952,6 +922,35 @@ func main() {
|
||||
}
|
||||
err := Test(pkgName, options)
|
||||
handleCompilerError(err)
|
||||
case "targets":
|
||||
dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets")
|
||||
entries, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "could not list targets:", err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if !entry.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") {
|
||||
// Only inspect JSON files.
|
||||
continue
|
||||
}
|
||||
path := filepath.Join(dir, entry.Name())
|
||||
spec, err := compileopts.LoadTarget(path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "could not list target:", err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
if spec.FlashMethod == "" && spec.FlashCommand == "" && spec.Emulator == nil {
|
||||
// This doesn't look like a regular target file, but rather like
|
||||
// a parent target (such as targets/cortex-m.json).
|
||||
continue
|
||||
}
|
||||
name := entry.Name()
|
||||
name = name[:len(name)-5]
|
||||
fmt.Println(name)
|
||||
}
|
||||
case "info":
|
||||
if flag.NArg() == 1 {
|
||||
options.Target = flag.Arg(0)
|
||||
@@ -971,12 +970,18 @@ func main() {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
cachedGOROOT, err := loader.GetCachedGoroot(config)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("LLVM triple: %s\n", config.Triple())
|
||||
fmt.Printf("GOOS: %s\n", config.GOOS())
|
||||
fmt.Printf("GOARCH: %s\n", config.GOARCH())
|
||||
fmt.Printf("build tags: %s\n", strings.Join(config.BuildTags(), " "))
|
||||
fmt.Printf("garbage collector: %s\n", config.GC())
|
||||
fmt.Printf("scheduler: %s\n", config.Scheduler())
|
||||
fmt.Printf("cached GOROOT: %s\n", cachedGOROOT)
|
||||
case "list":
|
||||
config, err := builder.NewConfig(options)
|
||||
if err != nil {
|
||||
@@ -984,11 +989,31 @@ func main() {
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
err = runGoList(config, *flagJSON, *flagDeps, flag.Args())
|
||||
var extraArgs []string
|
||||
if *flagJSON {
|
||||
extraArgs = append(extraArgs, "-json")
|
||||
}
|
||||
if *flagDeps {
|
||||
extraArgs = append(extraArgs, "-deps")
|
||||
}
|
||||
cmd, err := loader.List(config, extraArgs, flag.Args())
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to run `go list`:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
|
||||
os.Exit(status.ExitStatus())
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "failed to run `go list`:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "clean":
|
||||
// remove cache directory
|
||||
err := os.RemoveAll(goenv.Get("GOCACHE"))
|
||||
@@ -1003,7 +1028,11 @@ func main() {
|
||||
if s, err := goenv.GorootVersionString(goenv.Get("GOROOT")); err == nil {
|
||||
goversion = s
|
||||
}
|
||||
fmt.Printf("tinygo version %s %s/%s (using go version %s and LLVM version %s)\n", goenv.Version, runtime.GOOS, runtime.GOARCH, goversion, llvm.Version)
|
||||
version := goenv.Version
|
||||
if strings.HasSuffix(goenv.Version, "-dev") && gitSha1 != "" {
|
||||
version += "-" + gitSha1
|
||||
}
|
||||
fmt.Printf("tinygo version %s %s/%s (using go version %s and LLVM version %s)\n", version, runtime.GOOS, runtime.GOARCH, goversion, llvm.Version)
|
||||
case "env":
|
||||
if flag.NArg() == 0 {
|
||||
// Show all environment variables.
|
||||
|
||||
+12
-1
@@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -25,6 +26,8 @@ import (
|
||||
|
||||
const TESTDATA = "testdata"
|
||||
|
||||
var testTarget = flag.String("target", "", "override test target")
|
||||
|
||||
func TestCompiler(t *testing.T) {
|
||||
matches, err := filepath.Glob(filepath.Join(TESTDATA, "*.go"))
|
||||
if err != nil {
|
||||
@@ -44,6 +47,14 @@ func TestCompiler(t *testing.T) {
|
||||
|
||||
sort.Strings(matches)
|
||||
|
||||
if *testTarget != "" {
|
||||
// This makes it possible to run one specific test (instead of all),
|
||||
// which is especially useful to quickly check whether some changes
|
||||
// affect a particular target architecture.
|
||||
runPlatTests(*testTarget, matches, t)
|
||||
return
|
||||
}
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Run("Host", func(t *testing.T) {
|
||||
runPlatTests("", matches, t)
|
||||
@@ -146,7 +157,7 @@ func runTest(path, target string, t *testing.T) {
|
||||
PrintIR: false,
|
||||
DumpSSA: false,
|
||||
VerifyIR: true,
|
||||
Debug: false,
|
||||
Debug: true,
|
||||
PrintSizes: "",
|
||||
WasmAbi: "js",
|
||||
}
|
||||
|
||||
@@ -174,6 +174,11 @@ func EnableIRQ(irq uint32) {
|
||||
NVIC.ISER[irq>>5].Set(1 << (irq & 0x1F))
|
||||
}
|
||||
|
||||
// Disable the given interrupt number.
|
||||
func DisableIRQ(irq uint32) {
|
||||
NVIC.ICER[irq>>5].Set(1 << (irq & 0x1F))
|
||||
}
|
||||
|
||||
// Set the priority of the given interrupt number.
|
||||
// Note that the priority is given as a 0-255 number, where some of the lower
|
||||
// bits are not implemented by the hardware. For example, to set a low interrupt
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
.syntax unified
|
||||
.cfi_sections .debug_frame
|
||||
|
||||
.section .text.HardFault_Handler
|
||||
.global HardFault_Handler
|
||||
.type HardFault_Handler, %function
|
||||
HardFault_Handler:
|
||||
.cfi_startproc
|
||||
// Put the old stack pointer in the first argument, for easy debugging. This
|
||||
// is especially useful on Cortex-M0, which supports far fewer debug
|
||||
// facilities.
|
||||
@@ -19,6 +21,8 @@ HardFault_Handler:
|
||||
|
||||
// Continue handling this error in Go.
|
||||
bl handleHardFault
|
||||
.cfi_endproc
|
||||
.size HardFault_Handler, .-HardFault_Handler
|
||||
|
||||
// This is a convenience function for semihosting support.
|
||||
// At some point, this should be replaced by inline assembly.
|
||||
@@ -26,5 +30,8 @@ HardFault_Handler:
|
||||
.global SemihostingCall
|
||||
.type SemihostingCall, %function
|
||||
SemihostingCall:
|
||||
.cfi_startproc
|
||||
bkpt 0xab
|
||||
bx lr
|
||||
.cfi_endproc
|
||||
.size SemihostingCall, .-SemihostingCall
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
// The following definitions were copied from:
|
||||
// esp-idf/components/xtensa/include/xtensa/corebits.h
|
||||
#define PS_WOE_MASK 0x00040000
|
||||
#define PS_OWB_MASK 0x00000F00
|
||||
#define PS_CALLINC_MASK 0x00030000
|
||||
#define PS_WOE PS_WOE_MASK
|
||||
|
||||
// Only calling it call_start_cpu0 for consistency with ESP-IDF.
|
||||
.section .text.call_start_cpu0
|
||||
1:
|
||||
.long _stack_top
|
||||
.global call_start_cpu0
|
||||
call_start_cpu0:
|
||||
// We need to set the stack pointer to a different value. This is somewhat
|
||||
// complicated in the Xtensa architecture. The code below is a modified
|
||||
// version of the following code:
|
||||
// https://github.com/espressif/esp-idf/blob/c77c4ccf/components/xtensa/include/xt_instr_macros.h#L47
|
||||
|
||||
// Disable WOE.
|
||||
rsr.ps a2
|
||||
movi a3, ~(PS_WOE_MASK)
|
||||
and a2, a2, a3
|
||||
wsr.ps a2
|
||||
rsync
|
||||
|
||||
// Set WINDOWBASE to 1 << WINDOWSTART.
|
||||
rsr.windowbase a2
|
||||
ssl a2
|
||||
movi a2, 1
|
||||
sll a2, a2
|
||||
wsr.windowstart a2
|
||||
rsync
|
||||
|
||||
// Load new stack pointer.
|
||||
l32r sp, 1b
|
||||
|
||||
// Re-enable WOE.
|
||||
rsr.ps a2
|
||||
movi a3, PS_WOE
|
||||
or a2, a2, a3
|
||||
wsr.ps a2
|
||||
rsync
|
||||
|
||||
// Jump to the runtime start function written in Go.
|
||||
j main
|
||||
|
||||
.section .text.tinygo_scanCurrentStack
|
||||
.global tinygo_scanCurrentStack
|
||||
tinygo_scanCurrentStack:
|
||||
// TODO: save callee saved registers on the stack
|
||||
j tinygo_scanstack
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
.section .text.tinygo_scanCurrentStack
|
||||
.global tinygo_scanCurrentStack
|
||||
tinygo_scanCurrentStack:
|
||||
// TODO: save callee saved registers on the stack
|
||||
j tinygo_scanstack
|
||||
@@ -0,0 +1,130 @@
|
||||
#ifdef __riscv_flen
|
||||
#define NREG 48
|
||||
#define LFREG flw
|
||||
#define SFREG fsw
|
||||
#else
|
||||
#define NREG 16
|
||||
#endif
|
||||
|
||||
#if __riscv_xlen==64
|
||||
#define REGSIZE 8
|
||||
#define SREG sd
|
||||
#define LREG ld
|
||||
#else
|
||||
#define REGSIZE 4
|
||||
#define SREG sw
|
||||
#define LREG lw
|
||||
#endif
|
||||
|
||||
.section .text.handleInterruptASM
|
||||
.global handleInterruptASM
|
||||
.type handleInterruptASM,@function
|
||||
handleInterruptASM:
|
||||
// Save and restore all registers, because the hardware only saves/restores
|
||||
// the pc.
|
||||
// Note: we have to do this in assembly because the "interrupt"="machine"
|
||||
// attribute is broken in LLVM: https://bugs.llvm.org/show_bug.cgi?id=42984
|
||||
addi sp, sp, -NREG*REGSIZE
|
||||
SREG ra, 0*REGSIZE(sp)
|
||||
SREG t0, 1*REGSIZE(sp)
|
||||
SREG t1, 2*REGSIZE(sp)
|
||||
SREG t2, 3*REGSIZE(sp)
|
||||
SREG a0, 4*REGSIZE(sp)
|
||||
SREG a1, 5*REGSIZE(sp)
|
||||
SREG a2, 6*REGSIZE(sp)
|
||||
SREG a3, 7*REGSIZE(sp)
|
||||
SREG a4, 8*REGSIZE(sp)
|
||||
SREG a5, 9*REGSIZE(sp)
|
||||
SREG a6, 10*REGSIZE(sp)
|
||||
SREG a7, 11*REGSIZE(sp)
|
||||
SREG t3, 12*REGSIZE(sp)
|
||||
SREG t4, 13*REGSIZE(sp)
|
||||
SREG t5, 14*REGSIZE(sp)
|
||||
SREG t6, 15*REGSIZE(sp)
|
||||
#ifdef __riscv_flen
|
||||
SFREG f0, (0 + 16)*REGSIZE(sp)
|
||||
SFREG f1, (1 + 16)*REGSIZE(sp)
|
||||
SFREG f2, (2 + 16)*REGSIZE(sp)
|
||||
SFREG f3, (3 + 16)*REGSIZE(sp)
|
||||
SFREG f4, (4 + 16)*REGSIZE(sp)
|
||||
SFREG f5, (5 + 16)*REGSIZE(sp)
|
||||
SFREG f6, (6 + 16)*REGSIZE(sp)
|
||||
SFREG f7, (7 + 16)*REGSIZE(sp)
|
||||
SFREG f8, (8 + 16)*REGSIZE(sp)
|
||||
SFREG f9, (9 + 16)*REGSIZE(sp)
|
||||
SFREG f10,(10 + 16)*REGSIZE(sp)
|
||||
SFREG f11,(11 + 16)*REGSIZE(sp)
|
||||
SFREG f12,(12 + 16)*REGSIZE(sp)
|
||||
SFREG f13,(13 + 16)*REGSIZE(sp)
|
||||
SFREG f14,(14 + 16)*REGSIZE(sp)
|
||||
SFREG f15,(15 + 16)*REGSIZE(sp)
|
||||
SFREG f16,(16 + 16)*REGSIZE(sp)
|
||||
SFREG f17,(17 + 16)*REGSIZE(sp)
|
||||
SFREG f18,(18 + 16)*REGSIZE(sp)
|
||||
SFREG f19,(19 + 16)*REGSIZE(sp)
|
||||
SFREG f20,(20 + 16)*REGSIZE(sp)
|
||||
SFREG f21,(21 + 16)*REGSIZE(sp)
|
||||
SFREG f22,(22 + 16)*REGSIZE(sp)
|
||||
SFREG f23,(23 + 16)*REGSIZE(sp)
|
||||
SFREG f24,(24 + 16)*REGSIZE(sp)
|
||||
SFREG f25,(25 + 16)*REGSIZE(sp)
|
||||
SFREG f26,(26 + 16)*REGSIZE(sp)
|
||||
SFREG f27,(27 + 16)*REGSIZE(sp)
|
||||
SFREG f28,(28 + 16)*REGSIZE(sp)
|
||||
SFREG f29,(29 + 16)*REGSIZE(sp)
|
||||
SFREG f30,(30 + 16)*REGSIZE(sp)
|
||||
SFREG f31,(31 + 16)*REGSIZE(sp)
|
||||
#endif
|
||||
call handleInterrupt
|
||||
#ifdef __riscv_flen
|
||||
LFREG f0, (31 + 16)*REGSIZE(sp)
|
||||
LFREG f1, (30 + 16)*REGSIZE(sp)
|
||||
LFREG f2, (29 + 16)*REGSIZE(sp)
|
||||
LFREG f3, (28 + 16)*REGSIZE(sp)
|
||||
LFREG f4, (27 + 16)*REGSIZE(sp)
|
||||
LFREG f5, (26 + 16)*REGSIZE(sp)
|
||||
LFREG f6, (25 + 16)*REGSIZE(sp)
|
||||
LFREG f7, (24 + 16)*REGSIZE(sp)
|
||||
LFREG f8, (23 + 16)*REGSIZE(sp)
|
||||
LFREG f9, (22 + 16)*REGSIZE(sp)
|
||||
LFREG f10,(21 + 16)*REGSIZE(sp)
|
||||
LFREG f11,(20 + 16)*REGSIZE(sp)
|
||||
LFREG f12,(19 + 16)*REGSIZE(sp)
|
||||
LFREG f13,(18 + 16)*REGSIZE(sp)
|
||||
LFREG f14,(17 + 16)*REGSIZE(sp)
|
||||
LFREG f15,(16 + 16)*REGSIZE(sp)
|
||||
LFREG f16,(15 + 16)*REGSIZE(sp)
|
||||
LFREG f17,(14 + 16)*REGSIZE(sp)
|
||||
LFREG f18,(13 + 16)*REGSIZE(sp)
|
||||
LFREG f19,(12 + 16)*REGSIZE(sp)
|
||||
LFREG f20,(11 + 16)*REGSIZE(sp)
|
||||
LFREG f21,(10 + 16)*REGSIZE(sp)
|
||||
LFREG f22,(9 + 16)*REGSIZE(sp)
|
||||
LFREG f23,(8 + 16)*REGSIZE(sp)
|
||||
LFREG f24,(7 + 16)*REGSIZE(sp)
|
||||
LFREG f25,(6 + 16)*REGSIZE(sp)
|
||||
LFREG f26,(5 + 16)*REGSIZE(sp)
|
||||
LFREG f27,(4 + 16)*REGSIZE(sp)
|
||||
LFREG f28,(3 + 16)*REGSIZE(sp)
|
||||
LFREG f29,(2 + 16)*REGSIZE(sp)
|
||||
LFREG f30,(1 + 16)*REGSIZE(sp)
|
||||
LFREG f31,(0 + 16)*REGSIZE(sp)
|
||||
#endif
|
||||
LREG t6, 15*REGSIZE(sp)
|
||||
LREG t5, 14*REGSIZE(sp)
|
||||
LREG t4, 13*REGSIZE(sp)
|
||||
LREG t3, 12*REGSIZE(sp)
|
||||
LREG a7, 11*REGSIZE(sp)
|
||||
LREG a6, 10*REGSIZE(sp)
|
||||
LREG a5, 9*REGSIZE(sp)
|
||||
LREG a4, 8*REGSIZE(sp)
|
||||
LREG a3, 7*REGSIZE(sp)
|
||||
LREG a2, 6*REGSIZE(sp)
|
||||
LREG a1, 5*REGSIZE(sp)
|
||||
LREG a0, 4*REGSIZE(sp)
|
||||
LREG t2, 3*REGSIZE(sp)
|
||||
LREG t1, 2*REGSIZE(sp)
|
||||
LREG t0, 1*REGSIZE(sp)
|
||||
LREG ra, 0*REGSIZE(sp)
|
||||
addi sp, sp, NREG*REGSIZE
|
||||
mret
|
||||
@@ -9,52 +9,12 @@ _start:
|
||||
// Load the globals pointer. The program will load pointers relative to this
|
||||
// register, so it must be set to the right value on startup.
|
||||
// See: https://gnu-mcu-eclipse.github.io/arch/riscv/programmer/#the-gp-global-pointer-register
|
||||
// Linker relaxations must be disabled to avoid the initialization beign
|
||||
// relaxed with an uninitialized global pointer: mv gp, gp
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
// Jump to runtime.main
|
||||
call main
|
||||
|
||||
.section .text.handleInterruptASM
|
||||
.global handleInterruptASM
|
||||
.type handleInterruptASM,@function
|
||||
handleInterruptASM:
|
||||
// Save and restore all registers, because the hardware only saves/restores
|
||||
// the pc.
|
||||
// Note: we have to do this in assembly because the "interrupt"="machine"
|
||||
// attribute is broken in LLVM: https://bugs.llvm.org/show_bug.cgi?id=42984
|
||||
addi sp, sp, -64
|
||||
sw ra, 60(sp)
|
||||
sw t0, 56(sp)
|
||||
sw t1, 52(sp)
|
||||
sw t2, 48(sp)
|
||||
sw a0, 44(sp)
|
||||
sw a1, 40(sp)
|
||||
sw a2, 36(sp)
|
||||
sw a3, 32(sp)
|
||||
sw a4, 28(sp)
|
||||
sw a5, 24(sp)
|
||||
sw a6, 20(sp)
|
||||
sw a7, 16(sp)
|
||||
sw t3, 12(sp)
|
||||
sw t4, 8(sp)
|
||||
sw t5, 4(sp)
|
||||
sw t6, 0(sp)
|
||||
call handleInterrupt
|
||||
lw t6, 0(sp)
|
||||
lw t5, 4(sp)
|
||||
lw t4, 8(sp)
|
||||
lw t3, 12(sp)
|
||||
lw a7, 16(sp)
|
||||
lw a6, 20(sp)
|
||||
lw a5, 24(sp)
|
||||
lw a4, 28(sp)
|
||||
lw a3, 32(sp)
|
||||
lw a2, 36(sp)
|
||||
lw a1, 40(sp)
|
||||
lw a0, 44(sp)
|
||||
lw t2, 48(sp)
|
||||
lw t1, 52(sp)
|
||||
lw t0, 56(sp)
|
||||
lw ra, 60(sp)
|
||||
addi sp, sp, 64
|
||||
mret
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Hand created file. DO NOT DELETE.
|
||||
// atsamd51x bitfield definitions that are not auto-generated by gen-device-svd.go
|
||||
|
||||
// +build sam,atsamd51
|
||||
|
||||
// These are the supported pchctrl function numberings on the atsamd51x
|
||||
// See http://ww1.microchip.com/downloads/en/DeviceDoc/SAM_D5xE5x_Family_Data_Sheet_DS60001507F.pdf
|
||||
// table 14-9
|
||||
|
||||
package sam
|
||||
|
||||
const (
|
||||
PCHCTRL_GCLK_OSCCTRL_DFLL48 = 0 // DFLL48 input clock source
|
||||
PCHCTRL_GCLK_OSCCTRL_FDPLL0 = 1 // Reference clock for FDPLL0
|
||||
PCHCTRL_GCLK_OSCCTRL_FDPLL1 = 2 // Reference clock for FDPLL1
|
||||
PCHCTRL_GCLK_OSCCTRL_FDPLL0_32K = 3 // FDPLL0 = 3 // 32KHz clock for internal lock timer
|
||||
PCHCTRL_GCLK_OSCCTRL_FDPLL1_32K = 3 // FDPLL1 = 3 // 32KHz clock for internal lock timer
|
||||
PCHCTRL_GCLK_SDHC0_SLOW = 3 // SDHC0 = 3 // Slow
|
||||
PCHCTRL_GCLK_SDHC1_SLOW = 3 // SDHC1 = 3 // Slow
|
||||
PCHCTRL_GCLK_SERCOMX_SLOW = 3 // GCLK_SERCOM[0..7]_SLOW = 3
|
||||
PCHCTRL_GCLK_EIC = 4
|
||||
PCHCTRL_GCLK_FREQM_MSR = 5 // FREQM Measure
|
||||
PCHCTRL_GCLK_FREQM_REF = 6 // FREQM Reference
|
||||
PCHCTRL_GCLK_SERCOM0_CORE = 7 // SERCOM0 Core
|
||||
PCHCTRL_GCLK_SERCOM1_CORE = 8 // SERCOM1 Core
|
||||
PCHCTRL_GCLK_TC0 = 9
|
||||
PCHCTRL_GCLK_TC1 = 9 // TC0, TC1
|
||||
PCHCTRL_GCLK_USB = 10 // USB
|
||||
PCHCTRL_GCLK_EVSYS0 = 11
|
||||
PCHCTRL_GCLK_EVSYS1 = 12
|
||||
PCHCTRL_GCLK_EVSYS2 = 13
|
||||
PCHCTRL_GCLK_EVSYS3 = 14
|
||||
PCHCTRL_GCLK_EVSYS4 = 15
|
||||
PCHCTRL_GCLK_EVSYS5 = 16
|
||||
PCHCTRL_GCLK_EVSYS6 = 17
|
||||
PCHCTRL_GCLK_EVSYS7 = 18
|
||||
PCHCTRL_GCLK_EVSYS8 = 19
|
||||
PCHCTRL_GCLK_EVSYS9 = 20
|
||||
PCHCTRL_GCLK_EVSYS10 = 21
|
||||
PCHCTRL_GCLK_EVSYS11 = 22
|
||||
PCHCTRL_GCLK_SERCOM2_CORE = 23 // SERCOM2 Core
|
||||
PCHCTRL_GCLK_SERCOM3_CORE = 24 // SERCOM3 Core
|
||||
PCHCTRL_GCLK_TCC0 = 25
|
||||
PCHCTRL_GCLK_TCC1 = 25 // TCC0, TCC1
|
||||
PCHCTRL_GCLK_TC2 = 26
|
||||
PCHCTRL_GCLK_TC3 = 26 // TC2, TC3
|
||||
PCHCTRL_GCLK_CAN0 = 27 // CAN0
|
||||
PCHCTRL_GCLK_CAN1 = 28 // CAN1
|
||||
PCHCTRL_GCLK_TCC2 = 29
|
||||
PCHCTRL_GCLK_TCC3 = 29 // TCC2, TCC3
|
||||
PCHCTRL_GCLK_TC4 = 30
|
||||
PCHCTRL_GCLK_TC5 = 30 // TC4, TC5
|
||||
PCHCTRL_GCLK_PDEC = 31 // PDEC
|
||||
PCHCTRL_GCLK_AC = 32 // AC
|
||||
PCHCTRL_GCLK_CCL = 33 // CCL
|
||||
PCHCTRL_GCLK_SERCOM4_CORE = 34 // SERCOM4 Core
|
||||
PCHCTRL_GCLK_SERCOM5_CORE = 35 // SERCOM5 Core
|
||||
PCHCTRL_GCLK_SERCOM6_CORE = 36 // SERCOM6 Core
|
||||
PCHCTRL_GCLK_SERCOM7_CORE = 37 // SERCOM7 Core
|
||||
PCHCTRL_GCLK_TCC4 = 38 // TCC4
|
||||
PCHCTRL_GCLK_TC6 = 39
|
||||
PCHCTRL_GCLK_TC7 = 39 // TC6, TC7
|
||||
PCHCTRL_GCLK_ADC0 = 40 // ADC0
|
||||
PCHCTRL_GCLK_ADC1 = 41 // ADC1
|
||||
PCHCTRL_GCLK_DAC = 42 // DAC
|
||||
PCHCTRL_GCLK_I2S0 = 43
|
||||
PCHCTRL_GCLK_I2S1 = 44
|
||||
PCHCTRL_GCLK_SDHC0 = 45 // SDHC0
|
||||
PCHCTRL_GCLK_SDHC1 = 46 // SDHC1
|
||||
PCHCTRL_GCLK_CM4_TRACE = 47 // CM4 Trace
|
||||
)
|
||||
+5
-3
@@ -1,7 +1,9 @@
|
||||
// These are the supported alternate function numberings on the stm32f407
|
||||
// +build stm32,stm32f407
|
||||
// Hand created file. DO NOT DELETE.
|
||||
// STM32FXXX (except stm32f1xx) bitfield definitions that are not
|
||||
// auto-generated by gen-device-svd.go
|
||||
// +build stm32f4
|
||||
|
||||
// Alternate function settings on the stm32f4xx series
|
||||
// Alternate function settings on the stm32f4 series
|
||||
|
||||
package stm32
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// +build circuitplay_express
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
)
|
||||
|
||||
func init() {
|
||||
enable := machine.PA30
|
||||
enable.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
enable.Set(true)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Simplistic example using the DAC on the Circuit Playground Express.
|
||||
//
|
||||
// To actually use the DAC for producing complex waveforms or samples requires a DMA
|
||||
// timer-based playback mechanism which is beyond the scope of this example.
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
speaker := machine.A0
|
||||
speaker.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
|
||||
machine.DAC0.Configure(machine.DACConfig{})
|
||||
|
||||
data := []uint16{0xFFFF, 0x8000, 0x4000, 0x2000, 0x1000, 0x0000}
|
||||
|
||||
for {
|
||||
for _, val := range data {
|
||||
play(val)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func play(val uint16) {
|
||||
for i := 0; i < 100; i++ {
|
||||
machine.DAC0.Set(val)
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
machine.DAC0.Set(0)
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// +build pyportal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
)
|
||||
|
||||
func init() {
|
||||
enable := machine.SPK_SD
|
||||
enable.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
enable.Set(true)
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// This example assumes that an RGB LED is connected to pins 3, 5 and 6 on an Arduino.
|
||||
// Change the values below to use different pins.
|
||||
const (
|
||||
redPin = machine.D3
|
||||
redPin = machine.D4
|
||||
greenPin = machine.D5
|
||||
bluePin = machine.D6
|
||||
)
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"machine"
|
||||
)
|
||||
|
||||
var timerCh = make(chan struct{}, 1)
|
||||
|
||||
func main() {
|
||||
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
|
||||
@@ -12,17 +14,18 @@ func main() {
|
||||
arm.SetupSystemTimer(machine.CPUFrequency() / 10)
|
||||
|
||||
for {
|
||||
machine.LED.Low()
|
||||
<-timerCh
|
||||
machine.LED.High()
|
||||
<-timerCh
|
||||
}
|
||||
}
|
||||
|
||||
var led_state bool
|
||||
|
||||
//export SysTick_Handler
|
||||
func timer_isr() {
|
||||
if led_state {
|
||||
machine.LED.Low()
|
||||
} else {
|
||||
machine.LED.High()
|
||||
select {
|
||||
case timerCh <- struct{}{}:
|
||||
default:
|
||||
// The consumer is running behind.
|
||||
}
|
||||
led_state = !led_state
|
||||
}
|
||||
|
||||
@@ -124,3 +124,130 @@ func IndexString(str, sub string) int {
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// The following code has been copied from the Go 1.15 release tree.
|
||||
|
||||
// PrimeRK is the prime base used in Rabin-Karp algorithm.
|
||||
const PrimeRK = 16777619
|
||||
|
||||
// HashStrBytes returns the hash and the appropriate multiplicative
|
||||
// factor for use in Rabin-Karp algorithm.
|
||||
func HashStrBytes(sep []byte) (uint32, uint32) {
|
||||
hash := uint32(0)
|
||||
for i := 0; i < len(sep); i++ {
|
||||
hash = hash*PrimeRK + uint32(sep[i])
|
||||
}
|
||||
var pow, sq uint32 = 1, PrimeRK
|
||||
for i := len(sep); i > 0; i >>= 1 {
|
||||
if i&1 != 0 {
|
||||
pow *= sq
|
||||
}
|
||||
sq *= sq
|
||||
}
|
||||
return hash, pow
|
||||
}
|
||||
|
||||
// HashStr returns the hash and the appropriate multiplicative
|
||||
// factor for use in Rabin-Karp algorithm.
|
||||
func HashStr(sep string) (uint32, uint32) {
|
||||
hash := uint32(0)
|
||||
for i := 0; i < len(sep); i++ {
|
||||
hash = hash*PrimeRK + uint32(sep[i])
|
||||
}
|
||||
var pow, sq uint32 = 1, PrimeRK
|
||||
for i := len(sep); i > 0; i >>= 1 {
|
||||
if i&1 != 0 {
|
||||
pow *= sq
|
||||
}
|
||||
sq *= sq
|
||||
}
|
||||
return hash, pow
|
||||
}
|
||||
|
||||
// HashStrRevBytes returns the hash of the reverse of sep and the
|
||||
// appropriate multiplicative factor for use in Rabin-Karp algorithm.
|
||||
func HashStrRevBytes(sep []byte) (uint32, uint32) {
|
||||
hash := uint32(0)
|
||||
for i := len(sep) - 1; i >= 0; i-- {
|
||||
hash = hash*PrimeRK + uint32(sep[i])
|
||||
}
|
||||
var pow, sq uint32 = 1, PrimeRK
|
||||
for i := len(sep); i > 0; i >>= 1 {
|
||||
if i&1 != 0 {
|
||||
pow *= sq
|
||||
}
|
||||
sq *= sq
|
||||
}
|
||||
return hash, pow
|
||||
}
|
||||
|
||||
// HashStrRev returns the hash of the reverse of sep and the
|
||||
// appropriate multiplicative factor for use in Rabin-Karp algorithm.
|
||||
func HashStrRev(sep string) (uint32, uint32) {
|
||||
hash := uint32(0)
|
||||
for i := len(sep) - 1; i >= 0; i-- {
|
||||
hash = hash*PrimeRK + uint32(sep[i])
|
||||
}
|
||||
var pow, sq uint32 = 1, PrimeRK
|
||||
for i := len(sep); i > 0; i >>= 1 {
|
||||
if i&1 != 0 {
|
||||
pow *= sq
|
||||
}
|
||||
sq *= sq
|
||||
}
|
||||
return hash, pow
|
||||
}
|
||||
|
||||
// IndexRabinKarpBytes uses the Rabin-Karp search algorithm to return the index of the
|
||||
// first occurence of substr in s, or -1 if not present.
|
||||
func IndexRabinKarpBytes(s, sep []byte) int {
|
||||
// Rabin-Karp search
|
||||
hashsep, pow := HashStrBytes(sep)
|
||||
n := len(sep)
|
||||
var h uint32
|
||||
for i := 0; i < n; i++ {
|
||||
h = h*PrimeRK + uint32(s[i])
|
||||
}
|
||||
if h == hashsep && Equal(s[:n], sep) {
|
||||
return 0
|
||||
}
|
||||
for i := n; i < len(s); {
|
||||
h *= PrimeRK
|
||||
h += uint32(s[i])
|
||||
h -= pow * uint32(s[i-n])
|
||||
i++
|
||||
if h == hashsep && Equal(s[i-n:i], sep) {
|
||||
return i - n
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// IndexRabinKarp uses the Rabin-Karp search algorithm to return the index of the
|
||||
// first occurence of substr in s, or -1 if not present.
|
||||
func IndexRabinKarp(s, substr string) int {
|
||||
// Rabin-Karp search
|
||||
hashss, pow := HashStr(substr)
|
||||
n := len(substr)
|
||||
var h uint32
|
||||
for i := 0; i < n; i++ {
|
||||
h = h*PrimeRK + uint32(s[i])
|
||||
}
|
||||
if h == hashss && s[:n] == substr {
|
||||
return 0
|
||||
}
|
||||
for i := n; i < len(s); {
|
||||
h *= PrimeRK
|
||||
h += uint32(s[i])
|
||||
h -= pow * uint32(s[i-n])
|
||||
i++
|
||||
if h == hashss && s[i-n:i] == substr {
|
||||
return i - n
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package task
|
||||
|
||||
import "runtime/interrupt"
|
||||
|
||||
const asserts = false
|
||||
|
||||
// Queue is a FIFO container of tasks.
|
||||
@@ -10,7 +12,9 @@ type Queue struct {
|
||||
|
||||
// Push a task onto the queue.
|
||||
func (q *Queue) Push(t *Task) {
|
||||
i := interrupt.Disable()
|
||||
if asserts && t.Next != nil {
|
||||
interrupt.Restore(i)
|
||||
panic("runtime: pushing a task to a queue with a non-nil Next pointer")
|
||||
}
|
||||
if q.tail != nil {
|
||||
@@ -21,12 +25,15 @@ func (q *Queue) Push(t *Task) {
|
||||
if q.head == nil {
|
||||
q.head = t
|
||||
}
|
||||
interrupt.Restore(i)
|
||||
}
|
||||
|
||||
// Pop a task off of the queue.
|
||||
func (q *Queue) Pop() *Task {
|
||||
i := interrupt.Disable()
|
||||
t := q.head
|
||||
if t == nil {
|
||||
interrupt.Restore(i)
|
||||
return nil
|
||||
}
|
||||
q.head = t.Next
|
||||
@@ -34,11 +41,13 @@ func (q *Queue) Pop() *Task {
|
||||
q.tail = nil
|
||||
}
|
||||
t.Next = nil
|
||||
interrupt.Restore(i)
|
||||
return t
|
||||
}
|
||||
|
||||
// Append pops the contents of another queue and pushes them onto the end of this queue.
|
||||
func (q *Queue) Append(other *Queue) {
|
||||
i := interrupt.Disable()
|
||||
if q.head == nil {
|
||||
q.head = other.head
|
||||
} else {
|
||||
@@ -46,6 +55,15 @@ func (q *Queue) Append(other *Queue) {
|
||||
}
|
||||
q.tail = other.tail
|
||||
other.head, other.tail = nil, nil
|
||||
interrupt.Restore(i)
|
||||
}
|
||||
|
||||
// Empty checks if the queue is empty.
|
||||
func (q *Queue) Empty() bool {
|
||||
i := interrupt.Disable()
|
||||
empty := q.head == nil
|
||||
interrupt.Restore(i)
|
||||
return empty
|
||||
}
|
||||
|
||||
// Stack is a LIFO container of tasks.
|
||||
@@ -57,19 +75,24 @@ type Stack struct {
|
||||
|
||||
// Push a task onto the stack.
|
||||
func (s *Stack) Push(t *Task) {
|
||||
i := interrupt.Disable()
|
||||
if asserts && t.Next != nil {
|
||||
interrupt.Restore(i)
|
||||
panic("runtime: pushing a task to a stack with a non-nil Next pointer")
|
||||
}
|
||||
s.top, t.Next = t, s.top
|
||||
interrupt.Restore(i)
|
||||
}
|
||||
|
||||
// Pop a task off of the stack.
|
||||
func (s *Stack) Pop() *Task {
|
||||
i := interrupt.Disable()
|
||||
t := s.top
|
||||
if t != nil {
|
||||
s.top = t.Next
|
||||
t.Next = nil
|
||||
}
|
||||
interrupt.Restore(i)
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -89,10 +112,13 @@ func (t *Task) tail() *Task {
|
||||
// Queue moves the contents of the stack into a queue.
|
||||
// Elements can be popped from the queue in the same order that they would be popped from the stack.
|
||||
func (s *Stack) Queue() Queue {
|
||||
i := interrupt.Disable()
|
||||
head := s.top
|
||||
s.top = nil
|
||||
return Queue{
|
||||
q := Queue{
|
||||
head: head,
|
||||
tail: head.tail(),
|
||||
}
|
||||
interrupt.Restore(i)
|
||||
return q
|
||||
}
|
||||
|
||||
@@ -18,3 +18,8 @@ type Task struct {
|
||||
// state is the underlying running state of the task.
|
||||
state state
|
||||
}
|
||||
|
||||
// getGoroutineStackSize is a compiler intrinsic that returns the stack size for
|
||||
// the given function and falls back to the default stack size. It is replaced
|
||||
// with a load from a special section just before codegen.
|
||||
func getGoroutineStackSize(fn uintptr) uintptr
|
||||
|
||||
@@ -67,7 +67,7 @@ func createTask() *Task {
|
||||
// start invokes a function in a new goroutine. Calls to this are inserted by the compiler.
|
||||
// The created goroutine starts running immediately.
|
||||
// This is implemented inside the compiler.
|
||||
func start(fn uintptr, args unsafe.Pointer)
|
||||
func start(fn uintptr, args unsafe.Pointer, stackSize uintptr)
|
||||
|
||||
// Current returns the current active task.
|
||||
// This is implemented inside the compiler.
|
||||
|
||||
@@ -17,7 +17,7 @@ func Current() *Task {
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func start(fn uintptr, args unsafe.Pointer) {
|
||||
func start(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
||||
// The compiler will error if this is reachable.
|
||||
runtimePanic("scheduler is disabled")
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (t *Task) Resume() {
|
||||
}
|
||||
|
||||
// initialize the state and prepare to call the specified function with the specified argument bundle.
|
||||
func (s *state) initialize(fn uintptr, args unsafe.Pointer) {
|
||||
func (s *state) initialize(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
||||
// Create a stack.
|
||||
stack := make([]uintptr, stackSize/unsafe.Sizeof(uintptr(0)))
|
||||
|
||||
@@ -67,9 +67,9 @@ func runqueuePushBack(*Task)
|
||||
|
||||
// start creates and starts a new goroutine with the given function and arguments.
|
||||
// The new goroutine is scheduled to run later.
|
||||
func start(fn uintptr, args unsafe.Pointer) {
|
||||
func start(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
||||
t := &Task{}
|
||||
t.state.initialize(fn, args)
|
||||
t.state.initialize(fn, args, stackSize)
|
||||
runqueuePushBack(t)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ package task
|
||||
|
||||
import "unsafe"
|
||||
|
||||
const stackSize = 256
|
||||
|
||||
// calleeSavedRegs is the list of registers that must be saved and restored when
|
||||
// switching between tasks. Also see scheduler_avr.S that relies on the
|
||||
// exact layout of this struct.
|
||||
|
||||
@@ -4,8 +4,6 @@ package task
|
||||
|
||||
import "unsafe"
|
||||
|
||||
const stackSize = 1024
|
||||
|
||||
// calleeSavedRegs is the list of registers that must be saved and restored when
|
||||
// switching between tasks. Also see scheduler_cortexm.S that relies on the
|
||||
// exact layout of this struct.
|
||||
|
||||
@@ -49,7 +49,7 @@ const (
|
||||
// Digital pins
|
||||
D0 Pin = PE0
|
||||
D1 Pin = PE1
|
||||
D2 Pin = PE6
|
||||
D2 Pin = PE4
|
||||
D3 Pin = PE5
|
||||
D4 Pin = PG5
|
||||
D5 Pin = PE3
|
||||
|
||||
@@ -66,15 +66,15 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = D13 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_MOSI_PIN Pin = D11 // MOSI: SERCOM1/PAD[0]
|
||||
SPI0_MISO_PIN Pin = D12 // MISO: SERCOM1/PAD[3]
|
||||
SPI0_SCK_PIN Pin = D13 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_SDO_PIN Pin = D11 // SDO: SERCOM1/PAD[0]
|
||||
SPI0_SDI_PIN Pin = D12 // SDI: SERCOM1/PAD[3]
|
||||
)
|
||||
|
||||
// NINA-W102 Pins
|
||||
const (
|
||||
NINA_MOSI Pin = PA12
|
||||
NINA_MISO Pin = PA13
|
||||
NINA_SDO Pin = PA12
|
||||
NINA_SDI Pin = PA13
|
||||
NINA_CS Pin = PA14
|
||||
NINA_SCK Pin = PA15
|
||||
NINA_GPIO0 Pin = PA27
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
// +build sam,atsamd21,arduino_zero
|
||||
|
||||
package machine
|
||||
|
||||
// used to reset into bootloader
|
||||
const RESET_MAGIC_VALUE = 0x07738135
|
||||
|
||||
// GPIO Pins - Digital Low
|
||||
const (
|
||||
D0 = PA11 // RX
|
||||
D1 = PA10 // TX
|
||||
D2 = PA14
|
||||
D3 = PA09 // PWM available
|
||||
D4 = PA08 // PWM available
|
||||
D5 = PA15 // PWM available
|
||||
D6 = PA20 // PWM available
|
||||
D7 = PA21
|
||||
)
|
||||
|
||||
// GPIO Pins - Digital High
|
||||
const (
|
||||
D8 = PA06 // PWM available
|
||||
D9 = PA07 // PWM available
|
||||
D10 = PA18 // PWM available
|
||||
D11 = PA16 // PWM available
|
||||
D12 = PA19 // PWM available
|
||||
D13 = PA17 // PWM available
|
||||
)
|
||||
|
||||
// LEDs on the Arduino Zero
|
||||
const (
|
||||
LED = LED1
|
||||
LED1 Pin = D13
|
||||
LED2 Pin = PA27 // TX LED
|
||||
LED3 Pin = PB03 // RX LED
|
||||
)
|
||||
|
||||
// ADC pins
|
||||
const (
|
||||
AREF Pin = PA03
|
||||
ADC0 Pin = PA02
|
||||
ADC1 Pin = PB08
|
||||
ADC2 Pin = PB09
|
||||
ADC3 Pin = PA04
|
||||
ADC4 Pin = PA05
|
||||
ADC5 Pin = PB02
|
||||
)
|
||||
|
||||
// SPI pins - EDBG connected
|
||||
const (
|
||||
SPI0_SDO_PIN Pin = PA16 // MOSI: SERCOM1/PAD[0]
|
||||
SPI0_SDI_PIN Pin = PA19 // MISO: SERCOM1/PAD[2]
|
||||
SPI0_SCK_PIN Pin = PA17 // SCK: SERCOM1/PAD[3]
|
||||
)
|
||||
|
||||
// SPI pins (Legacy ICSP)
|
||||
const (
|
||||
SPI1_SDO_PIN Pin = PB10 // MOSI: SERCOM4/PAD[2] - Pin 4
|
||||
SPI1_SDI_PIN Pin = PA12 // MISO: SERCOM4/PAD[0] - Pin 1
|
||||
SPI1_SCK_PIN Pin = PB11 // SCK: SERCOM4/PAD[3] - Pin 3
|
||||
)
|
||||
|
||||
// I2C pins - EDBG connected
|
||||
const (
|
||||
SDA_PIN Pin = PA22 // SDA: SERCOM3/PAD[0] - Pin 20
|
||||
SCL_PIN Pin = PA23 // SCL: SERCOM3/PAD[1] - Pin 21
|
||||
)
|
||||
|
||||
// I2S pins - might not be exposed
|
||||
const (
|
||||
I2S_SCK_PIN Pin = PA10
|
||||
I2S_SD_PIN Pin = PA07
|
||||
I2S_WS_PIN Pin = PA11
|
||||
)
|
||||
|
||||
// UART0 pins - EDBG connected
|
||||
const (
|
||||
UART_RX_PIN Pin = D0
|
||||
UART_TX_PIN Pin = D1
|
||||
)
|
||||
|
||||
// 'native' USB port pins
|
||||
const (
|
||||
USBCDC_DM_PIN Pin = PA24
|
||||
USBCDC_DP_PIN Pin = PA25
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
const (
|
||||
usb_STRING_PRODUCT = "Arduino Zero"
|
||||
usb_STRING_MANUFACTURER = "Arduino LLC"
|
||||
|
||||
usb_VID uint16 = 0x2341
|
||||
usb_PID uint16 = 0x804d
|
||||
)
|
||||
|
||||
// 32.768 KHz Crystal
|
||||
const (
|
||||
XIN32 Pin = PA00
|
||||
XOUT32 Pin = PA01
|
||||
)
|
||||
@@ -65,18 +65,22 @@ var (
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART1,
|
||||
}
|
||||
UART1 = &UART0
|
||||
UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART2,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART1, UART0.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA5
|
||||
SPI0_MOSI_PIN = PA7
|
||||
SPI0_MISO_PIN = PA6
|
||||
SPI0_SCK_PIN = PA5
|
||||
SPI0_SDO_PIN = PA7
|
||||
SPI0_SDI_PIN = PA6
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package machine
|
||||
|
||||
const HasLowFrequencyCrystal = true
|
||||
const HasLowFrequencyCrystal = false
|
||||
|
||||
// GPIO Pins
|
||||
const (
|
||||
@@ -72,9 +72,9 @@ const (
|
||||
|
||||
// SPI pins (internal flash)
|
||||
const (
|
||||
SPI0_SCK_PIN = P0_19 // SCK
|
||||
SPI0_MOSI_PIN = P0_21 // MOSI
|
||||
SPI0_MISO_PIN = P0_23 // MISO
|
||||
SPI0_SCK_PIN = P0_19 // SCK
|
||||
SPI0_SDO_PIN = P0_21 // SDO
|
||||
SPI0_SDI_PIN = P0_23 // SDI
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -77,9 +77,9 @@ const (
|
||||
|
||||
// SPI pins (internal flash)
|
||||
const (
|
||||
SPI0_SCK_PIN = PA21 // SCK: SERCOM3/PAD[3]
|
||||
SPI0_MOSI_PIN = PA20 // MOSI: SERCOM3/PAD[2]
|
||||
SPI0_MISO_PIN = PA16 // MISO: SERCOM3/PAD[0]
|
||||
SPI0_SCK_PIN = PA21 // SCK: SERCOM3/PAD[3]
|
||||
SPI0_SDO_PIN = PA20 // SDO: SERCOM3/PAD[2]
|
||||
SPI0_SDI_PIN = PA16 // SDI: SERCOM3/PAD[0]
|
||||
)
|
||||
|
||||
// I2S pins
|
||||
|
||||
@@ -78,7 +78,7 @@ const (
|
||||
|
||||
// 240x240 ST7789 display is connected to these pins (use RowOffset = 80)
|
||||
TFT_SCK = D29
|
||||
TFT_MOSI = D30
|
||||
TFT_SDO = D30
|
||||
TFT_CS = D31
|
||||
TFT_DC = D32
|
||||
TFT_RESET = D33
|
||||
@@ -116,9 +116,9 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = D13 // SCK
|
||||
SPI0_MOSI_PIN = D15 // MOSI
|
||||
SPI0_MISO_PIN = D14 // MISO
|
||||
SPI0_SCK_PIN = D13 // SCK
|
||||
SPI0_SDO_PIN = D15 // SDO
|
||||
SPI0_SDI_PIN = D14 // SDI
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// +build esp32_wroom_32
|
||||
|
||||
package machine
|
||||
|
||||
// Blue LED on the ESP32-WROOM-32 module.
|
||||
const LED = Pin(2)
|
||||
@@ -83,9 +83,9 @@ var (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PB11 // SCK: SERCOM4/PAD[3]
|
||||
SPI0_MOSI_PIN = PB10 // MOSI: SERCOM4/PAD[2]
|
||||
SPI0_MISO_PIN = PA12 // MISO: SERCOM4/PAD[0]
|
||||
SPI0_SCK_PIN = PB11 // SCK: SERCOM4/PAD[3]
|
||||
SPI0_SDO_PIN = PB10 // SDO: SERCOM4/PAD[2]
|
||||
SPI0_SDI_PIN = PA12 // SDI: SERCOM4/PAD[0]
|
||||
)
|
||||
|
||||
// SPI on the Feather M0.
|
||||
|
||||
@@ -63,9 +63,9 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = D25 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_MOSI_PIN = D24 // MOSI: SERCOM1/PAD[3]
|
||||
SPI0_MISO_PIN = D23 // MISO: SERCOM1/PAD[2]
|
||||
SPI0_SCK_PIN = D25 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_SDO_PIN = D24 // SDO: SERCOM1/PAD[3]
|
||||
SPI0_SDI_PIN = D23 // SDI: SERCOM1/PAD[2]
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// +build feather_nrf52840
|
||||
|
||||
package machine
|
||||
|
||||
const HasLowFrequencyCrystal = true
|
||||
|
||||
// GPIO Pins
|
||||
const (
|
||||
D0 = P0_25 // UART TX
|
||||
D1 = P0_24 // UART RX
|
||||
D2 = P0_10 // NFC2
|
||||
D3 = P1_15 // LED1
|
||||
D4 = P1_10 // LED2
|
||||
D5 = P1_08
|
||||
D6 = P0_07
|
||||
D7 = P1_02 // Button
|
||||
D8 = P0_16 // NeoPixel
|
||||
D9 = P0_26
|
||||
D10 = P0_27
|
||||
D11 = P0_06
|
||||
D12 = P0_08
|
||||
D13 = P1_09
|
||||
D14 = P0_04 // A0
|
||||
D15 = P0_05 // A1
|
||||
D16 = P0_30 // A2
|
||||
D17 = P0_28 // A3
|
||||
D18 = P0_02 // A4
|
||||
D19 = P0_03 // A5
|
||||
D20 = P0_29 // Battery
|
||||
D21 = P0_31 // AREF
|
||||
D22 = P0_12 // I2C SDA
|
||||
D23 = P0_11 // I2C SCL
|
||||
D24 = P0_15 // SPI MISO
|
||||
D25 = P0_13 // SPI MOSI
|
||||
D26 = P0_14 // SPI SCK
|
||||
D27 = P0_19 // QSPI CLK
|
||||
D28 = P0_20 // QSPI CS
|
||||
D29 = P0_17 // QSPI Data 0
|
||||
D30 = P0_22 // QSPI Data 1
|
||||
D31 = P0_23 // QSPI Data 2
|
||||
D32 = P0_21 // QSPI Data 3
|
||||
D33 = P0_09 // NFC1 (test point on bottom of board)
|
||||
)
|
||||
|
||||
// Analog Pins
|
||||
const (
|
||||
A0 = D14
|
||||
A1 = D15
|
||||
A2 = D16
|
||||
A3 = D17
|
||||
A4 = D18
|
||||
A5 = D19
|
||||
A6 = D20 // Battery
|
||||
A7 = D21 // ARef
|
||||
)
|
||||
|
||||
const (
|
||||
LED = D3
|
||||
LED1 = LED
|
||||
LED2 = D4
|
||||
NEOPIXEL = D8
|
||||
BUTTON = D7
|
||||
|
||||
QSPI_SCK = D27
|
||||
QSPI_CS = D28
|
||||
QSPI_DATA0 = D29
|
||||
QSPI_DATA1 = D30
|
||||
QSPI_DATA2 = D31
|
||||
QSPI_DATA3 = D32
|
||||
)
|
||||
|
||||
// UART0 pins (logical UART1)
|
||||
const (
|
||||
UART_RX_PIN = D0
|
||||
UART_TX_PIN = D1
|
||||
)
|
||||
|
||||
// UART0 is the USB device
|
||||
var (
|
||||
UART0 = USB
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
const (
|
||||
SDA_PIN = D22 // I2C0 external
|
||||
SCL_PIN = D23 // I2C0 external
|
||||
)
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = D26 // SCK
|
||||
SPI0_SDO_PIN = D25 // SDO
|
||||
SPI0_SDI_PIN = D24 // SDI
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
const (
|
||||
usb_STRING_PRODUCT = "Feather nRF52840 Express"
|
||||
usb_STRING_MANUFACTURER = "Adafruit Industries LLC"
|
||||
)
|
||||
|
||||
var (
|
||||
usb_VID uint16 = 0x239A
|
||||
usb_PID uint16 = 0x802A
|
||||
)
|
||||
@@ -0,0 +1,213 @@
|
||||
// +build feather_stm32f405
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/stm32"
|
||||
"runtime/interrupt"
|
||||
)
|
||||
|
||||
const (
|
||||
NUM_DIGITAL_IO_PINS = 39
|
||||
NUM_ANALOG_IO_PINS = 7
|
||||
)
|
||||
|
||||
// Digital pins
|
||||
const (
|
||||
// Arduino pin = MCU port pin // primary functions (alternate functions)
|
||||
D0 = PB11 // USART3 RX, PWM TIM2_CH4 (I2C2 SDA)
|
||||
D1 = PB10 // USART3 TX, PWM TIM2_CH3 (I2C2 SCL, I2S2 BCK)
|
||||
D2 = PB3 // GPIO, SPI3 FLASH SCK
|
||||
D3 = PB4 // GPIO, SPI3 FLASH MISO
|
||||
D4 = PB5 // GPIO, SPI3 FLASH MOSI
|
||||
D5 = PC7 // GPIO, PWM TIM3_CH2 (USART6 RX, I2S3 MCK)
|
||||
D6 = PC6 // GPIO, PWM TIM3_CH1 (USART6 TX, I2S2 MCK)
|
||||
D7 = PA15 // GPIO, SPI3 FLASH CS
|
||||
D8 = PC0 // GPIO, Neopixel
|
||||
D9 = PB8 // GPIO, PWM TIM4_CH3 (CAN1 RX, I2C1 SCL)
|
||||
D10 = PB9 // GPIO, PWM TIM4_CH4 (CAN1 TX, I2C1 SDA, I2S2 WSL)
|
||||
D11 = PC3 // GPIO (I2S2 SD, SPI2 MOSI)
|
||||
D12 = PC2 // GPIO (I2S2ext SD, SPI2 MISO)
|
||||
D13 = PC1 // GPIO, Builtin LED
|
||||
D14 = PB7 // I2C1 SDA, PWM TIM4_CH2 (USART1 RX)
|
||||
D15 = PB6 // I2C1 SCL, PWM TIM4_CH1 (USART1 TX, CAN2 TX)
|
||||
D16 = PA4 // A0 (DAC OUT1)
|
||||
D17 = PA5 // A1 (DAC OUT2, SPI1 SCK)
|
||||
D18 = PA6 // A2, PWM TIM3_CH1 (SPI1 MISO)
|
||||
D19 = PA7 // A3, PWM TIM3_CH2 (SPI1 MOSI)
|
||||
D20 = PC4 // A4
|
||||
D21 = PC5 // A5
|
||||
D22 = PA3 // A6
|
||||
D23 = PB13 // SPI2 SCK, PWM TIM1_CH1N (I2S2 BCK, CAN2 TX)
|
||||
D24 = PB14 // SPI2 MISO, PWM TIM1_CH2N (I2S2ext SD)
|
||||
D25 = PB15 // SPI2 MOSI, PWM TIM1_CH3N (I2S2 SD)
|
||||
D26 = PC8 // SDIO
|
||||
D27 = PC9 // SDIO
|
||||
D28 = PC10 // SDIO
|
||||
D29 = PC11 // SDIO
|
||||
D30 = PC12 // SDIO
|
||||
D31 = PD2 // SDIO
|
||||
D32 = PB12 // SD Detect
|
||||
D33 = PC14 // OSC32
|
||||
D34 = PC15 // OSC32
|
||||
D35 = PA11 // USB D+
|
||||
D36 = PA12 // USB D-
|
||||
D37 = PA13 // SWDIO
|
||||
D38 = PA14 // SWCLK
|
||||
)
|
||||
|
||||
// Analog pins
|
||||
const (
|
||||
A0 = D16 // ADC12 IN4
|
||||
A1 = D17 // ADC12 IN5
|
||||
A2 = D18 // ADC12 IN6
|
||||
A3 = D19 // ADC12 IN7
|
||||
A4 = D20 // ADC12 IN14
|
||||
A5 = D21 // ADC12 IN15
|
||||
A6 = D22 // VBAT
|
||||
)
|
||||
|
||||
func init() {
|
||||
initLED()
|
||||
initUART()
|
||||
initSPI()
|
||||
initI2C()
|
||||
}
|
||||
|
||||
// -- LEDs ---------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
NUM_BOARD_LED = 1
|
||||
NUM_BOARD_NEOPIXEL = 1
|
||||
|
||||
LED_RED = D13
|
||||
LED_NEOPIXEL = D8
|
||||
LED_BUILTIN = LED_RED
|
||||
LED = LED_BUILTIN
|
||||
)
|
||||
|
||||
func initLED() {}
|
||||
|
||||
// -- UART ---------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
// #===========#==========#==============#============#=======#=======#
|
||||
// | Interface | Hardware | Bus(Freq) | RX/TX Pins | AltFn | Alias |
|
||||
// #===========#==========#==============#============#=======#=======#
|
||||
// | UART1 | USART3 | APB1(42 MHz) | D0/D1 | 7 | ~ |
|
||||
// | UART2 | USART6 | APB2(84 MHz) | D5/D6 | 8 | ~ |
|
||||
// | UART3 | USART1 | APB2(84 MHz) | D14/D15 | 7 | ~ |
|
||||
// | --------- | -------- | ------------ | ---------- | ----- | ----- |
|
||||
// | UART0 | USART3 | APB1(42 MHz) | D0/D1 | 7 | UART1 |
|
||||
// #===========#==========#==============#============#=======#=======#
|
||||
NUM_UART_INTERFACES = 3
|
||||
|
||||
UART1_RX_PIN = D0 // UART1 = hardware: USART3
|
||||
UART1_TX_PIN = D1 //
|
||||
|
||||
UART2_RX_PIN = D5 // UART2 = hardware: USART6
|
||||
UART2_TX_PIN = D6 //
|
||||
|
||||
UART3_RX_PIN = D14 // UART3 = hardware: USART1
|
||||
UART3_TX_PIN = D15 //
|
||||
|
||||
UART0_RX_PIN = UART1_RX_PIN // UART0 = alias: UART1
|
||||
UART0_TX_PIN = UART1_TX_PIN //
|
||||
|
||||
UART_RX_PIN = UART0_RX_PIN // default/primary UART pins
|
||||
UART_TX_PIN = UART0_TX_PIN //
|
||||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART3,
|
||||
AltFuncSelector: stm32.AF7_USART1_2_3,
|
||||
}
|
||||
UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART6,
|
||||
AltFuncSelector: stm32.AF8_USART4_5_6,
|
||||
}
|
||||
UART3 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART1,
|
||||
AltFuncSelector: stm32.AF7_USART1_2_3,
|
||||
}
|
||||
UART0 = UART1
|
||||
)
|
||||
|
||||
func initUART() {
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART3, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(stm32.IRQ_USART6, UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(stm32.IRQ_USART1, UART3.handleInterrupt)
|
||||
}
|
||||
|
||||
// -- SPI ----------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
// #===========#==========#==============#==================#=======#=======#
|
||||
// | Interface | Hardware | Bus(Freq) | SCK/SDI/SDO Pins | AltFn | Alias |
|
||||
// #===========#==========#==============#==================#=======#=======#
|
||||
// | SPI1 | SPI2 | APB1(42 MHz) | D23/D24/D25 | 5 | ~ |
|
||||
// | SPI2 | SPI3 | APB1(42 MHz) | D2/D3/D4 | 6 | ~ |
|
||||
// | SPI3 | SPI1 | APB2(84 MHz) | D17/D18/D19 | 5 | ~ |
|
||||
// | --------- | -------- | ------------ | ---------------- | ----- | ----- |
|
||||
// | SPI0 | SPI2 | APB1(42 MHz) | D23/D24/D25 | 5 | SPI1 |
|
||||
// #===========#==========#==============#==================#=======#=======#
|
||||
NUM_SPI_INTERFACES = 3
|
||||
|
||||
SPI1_SCK_PIN = D23 //
|
||||
SPI1_SDI_PIN = D24 // SPI1 = hardware: SPI2
|
||||
SPI1_SDO_PIN = D25 //
|
||||
|
||||
SPI2_SCK_PIN = D2 //
|
||||
SPI2_SDI_PIN = D3 // SPI2 = hardware: SPI3
|
||||
SPI2_SDO_PIN = D4 //
|
||||
|
||||
SPI3_SCK_PIN = D17 //
|
||||
SPI3_SDI_PIN = D18 // SPI3 = hardware: SPI1
|
||||
SPI3_SDO_PIN = D19 //
|
||||
|
||||
SPI0_SCK_PIN = SPI1_SCK_PIN //
|
||||
SPI0_SDI_PIN = SPI1_SDI_PIN // SPI0 = alias: SPI1
|
||||
SPI0_SDO_PIN = SPI1_SDO_PIN //
|
||||
|
||||
SPI_SCK_PIN = SPI0_SCK_PIN //
|
||||
SPI_SDI_PIN = SPI0_SDI_PIN // default/primary SPI pins
|
||||
SPI_SDO_PIN = SPI0_SDO_PIN //
|
||||
)
|
||||
|
||||
func initSPI() {}
|
||||
|
||||
// -- I2C ----------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
// #===========#==========#==============#==============#=======#=======#
|
||||
// | Interface | Hardware | Bus(Freq) | SDA/SCL Pins | AltFn | Alias |
|
||||
// #===========#==========#==============#==============#=======#=======#
|
||||
// | I2C1 | I2C1 | | D14/D15 | | ~ |
|
||||
// | I2C2 | I2C2 | | D0/D1 | | ~ |
|
||||
// | I2C3 | I2C1 | | D9/D10 | | ~ |
|
||||
// | --------- | -------- | ------------ | ------------ | ----- | ----- |
|
||||
// | I2C0 | I2C1 | | D14/D15 | | I2C1 |
|
||||
// #===========#==========#==============#==============#=======#=======#
|
||||
NUM_I2C_INTERFACES = 3
|
||||
|
||||
I2C1_SDA_PIN = D14 // I2C1 = hardware: I2C1
|
||||
I2C1_SCL_PIN = D15 //
|
||||
|
||||
I2C2_SDA_PIN = D0 // I2C2 = hardware: I2C2
|
||||
I2C2_SCL_PIN = D1 //
|
||||
|
||||
I2C3_SDA_PIN = D9 // I2C3 = hardware: I2C1
|
||||
I2C3_SCL_PIN = D10 // (interface duplicated on second pair of pins)
|
||||
|
||||
I2C0_SDA_PIN = I2C1_SDA_PIN // I2C0 = alias: I2C1
|
||||
I2C0_SCL_PIN = I2C1_SCL_PIN //
|
||||
|
||||
I2C_SDA_PIN = I2C0_SDA_PIN // default/primary I2C pins
|
||||
I2C_SCL_PIN = I2C0_SCL_PIN //
|
||||
)
|
||||
|
||||
func initI2C() {}
|
||||
@@ -43,13 +43,13 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = NoPin
|
||||
SPI0_MOSI_PIN = NoPin
|
||||
SPI0_MISO_PIN = NoPin
|
||||
SPI0_SCK_PIN = NoPin
|
||||
SPI0_SDO_PIN = NoPin
|
||||
SPI0_SDI_PIN = NoPin
|
||||
|
||||
SPI1_SCK_PIN = D13
|
||||
SPI1_MOSI_PIN = D11
|
||||
SPI1_MISO_PIN = D12
|
||||
SPI1_SCK_PIN = D13
|
||||
SPI1_SDO_PIN = D11
|
||||
SPI1_SDI_PIN = D12
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
|
||||
@@ -83,9 +83,9 @@ var (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PB11 // SCK: SERCOM4/PAD[3]
|
||||
SPI0_MOSI_PIN = PB10 // MOSI: SERCOM4/PAD[2]
|
||||
SPI0_MISO_PIN = PA12 // MISO: SERCOM4/PAD[0]
|
||||
SPI0_SCK_PIN = PB11 // SCK: SERCOM4/PAD[3]
|
||||
SPI0_SDO_PIN = PB10 // SDO: SERCOM4/PAD[2]
|
||||
SPI0_SDI_PIN = PA12 // SDI: SERCOM4/PAD[0]
|
||||
)
|
||||
|
||||
// SPI on the ItsyBitsy M0.
|
||||
@@ -98,10 +98,10 @@ var (
|
||||
|
||||
// "Internal" SPI pins; SPI flash is attached to these on ItsyBitsy M0
|
||||
const (
|
||||
SPI1_CS_PIN = PA27
|
||||
SPI1_SCK_PIN = PB23
|
||||
SPI1_MOSI_PIN = PB22
|
||||
SPI1_MISO_PIN = PB03
|
||||
SPI1_CS_PIN = PA27
|
||||
SPI1_SCK_PIN = PB23
|
||||
SPI1_SDO_PIN = PB22
|
||||
SPI1_SDI_PIN = PB03
|
||||
)
|
||||
|
||||
// "Internal" SPI on Sercom 5
|
||||
|
||||
@@ -62,9 +62,9 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA01 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_MOSI_PIN = PA00 // MOSI: SERCOM1/PAD[0]
|
||||
SPI0_MISO_PIN = PB23 // MISO: SERCOM1/PAD[3]
|
||||
SPI0_SCK_PIN = PA01 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_SDO_PIN = PA00 // SDO: SERCOM1/PAD[0]
|
||||
SPI0_SDI_PIN = PB23 // SDI: SERCOM1/PAD[3]
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// +build itsybitsy_nrf52840
|
||||
|
||||
package machine
|
||||
|
||||
const HasLowFrequencyCrystal = true
|
||||
|
||||
// GPIO Pins
|
||||
const (
|
||||
D0 = P0_25 // UART TX
|
||||
D1 = P0_24 // UART RX
|
||||
D2 = P1_02
|
||||
D3 = P0_06 // LED1
|
||||
D4 = P0_29 // Button
|
||||
D5 = P0_27
|
||||
D6 = P1_09 // DotStar Clock
|
||||
D7 = P1_08
|
||||
D8 = P0_08 // DotStar Data
|
||||
D9 = P0_07
|
||||
D10 = P0_05
|
||||
D11 = P0_26
|
||||
D12 = P0_11
|
||||
D13 = P0_12
|
||||
D14 = P0_04 // A0
|
||||
D15 = P0_30 // A1
|
||||
D16 = P0_28 // A2
|
||||
D17 = P0_31 // A3
|
||||
D18 = P0_02 // A4
|
||||
D19 = P0_03 // A5
|
||||
D20 = P0_05 // A6
|
||||
D21 = P0_16 // I2C SDA
|
||||
D22 = P0_14 // I2C SCL
|
||||
D23 = P0_20 // SPI SDI
|
||||
D24 = P0_15 // SPI SDO
|
||||
D25 = P0_13 // SPI SCK
|
||||
D26 = P0_19 // QSPI SCK
|
||||
D27 = P0_23 // QSPI CS
|
||||
D28 = P0_21 // QSPI Data 0
|
||||
D29 = P0_22 // QSPI Data 1
|
||||
D30 = P1_00 // QSPI Data 2
|
||||
D31 = P0_17 // QSPI Data 3
|
||||
)
|
||||
|
||||
// Analog Pins
|
||||
const (
|
||||
A0 = D14
|
||||
A1 = D15
|
||||
A2 = D16
|
||||
A3 = D17
|
||||
A4 = D18
|
||||
A5 = D19
|
||||
A6 = D20
|
||||
)
|
||||
|
||||
const (
|
||||
LED = D3
|
||||
LED1 = LED
|
||||
BUTTON = D4
|
||||
|
||||
QSPI_SCK = D26
|
||||
QSPI_CS = D27
|
||||
QSPI_DATA0 = D28
|
||||
QSPI_DATA1 = D29
|
||||
QSPI_DATA2 = D30
|
||||
QSPI_DATA3 = D31
|
||||
)
|
||||
|
||||
// UART0 pins (logical UART1)
|
||||
const (
|
||||
UART_RX_PIN = D0
|
||||
UART_TX_PIN = D1
|
||||
)
|
||||
|
||||
// UART0 is the USB device
|
||||
var (
|
||||
UART0 = USB
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
const (
|
||||
SDA_PIN = D21 // I2C0 external
|
||||
SCL_PIN = D22 // I2C0 external
|
||||
)
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = D25
|
||||
SPI0_SDO_PIN = D24
|
||||
SPI0_SDI_PIN = D23
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
const (
|
||||
usb_STRING_PRODUCT = "Adafruit ItsyBitsy nRF52840 Express"
|
||||
usb_STRING_MANUFACTURER = "Adafruit"
|
||||
)
|
||||
|
||||
var (
|
||||
usb_VID uint16 = 0x239A
|
||||
usb_PID uint16 = 0x8051
|
||||
)
|
||||
@@ -0,0 +1,354 @@
|
||||
// +build maixbit
|
||||
|
||||
// Chip datasheet: https://s3.cn-north-1.amazonaws.com.cn/dl.kendryte.com/documents/kendryte_datasheet_20181011163248_en.pdf
|
||||
|
||||
package machine
|
||||
|
||||
// K210 IO pins.
|
||||
const (
|
||||
P00 Pin = 0
|
||||
P01 Pin = 1
|
||||
P02 Pin = 2
|
||||
P03 Pin = 3
|
||||
P04 Pin = 4
|
||||
P05 Pin = 5
|
||||
P06 Pin = 6
|
||||
P07 Pin = 7
|
||||
P08 Pin = 8
|
||||
P09 Pin = 9
|
||||
P10 Pin = 10
|
||||
P11 Pin = 11
|
||||
P12 Pin = 12
|
||||
P13 Pin = 13
|
||||
P14 Pin = 14
|
||||
P15 Pin = 15
|
||||
P16 Pin = 16
|
||||
P17 Pin = 17
|
||||
P18 Pin = 18
|
||||
P19 Pin = 19
|
||||
P20 Pin = 20
|
||||
P21 Pin = 21
|
||||
P22 Pin = 22
|
||||
P23 Pin = 23
|
||||
P24 Pin = 24
|
||||
P25 Pin = 25
|
||||
P26 Pin = 26
|
||||
P27 Pin = 27
|
||||
P28 Pin = 28
|
||||
P29 Pin = 29
|
||||
P30 Pin = 30
|
||||
P31 Pin = 31
|
||||
P32 Pin = 32
|
||||
P33 Pin = 33
|
||||
P34 Pin = 34
|
||||
P35 Pin = 35
|
||||
P36 Pin = 36
|
||||
P37 Pin = 37
|
||||
P38 Pin = 38
|
||||
P39 Pin = 39
|
||||
P40 Pin = 40
|
||||
P41 Pin = 41
|
||||
P42 Pin = 42
|
||||
P43 Pin = 43
|
||||
P44 Pin = 44
|
||||
P45 Pin = 45
|
||||
P46 Pin = 46
|
||||
P47 Pin = 47
|
||||
)
|
||||
|
||||
type FPIOAFunction uint8
|
||||
|
||||
// Every pin on the Kendryte K210 is assigned to an FPIOA function.
|
||||
// Each pin can be configured with every function below.
|
||||
const (
|
||||
FUNC_JTAG_TCLK FPIOAFunction = 0 // JTAG Test Clock
|
||||
FUNC_JTAG_TDI FPIOAFunction = 1 // JTAG Test Data In
|
||||
FUNC_JTAG_TMS FPIOAFunction = 2 // JTAG Test Mode Select
|
||||
FUNC_JTAG_TDO FPIOAFunction = 3 // JTAG Test Data Out
|
||||
FUNC_SPI0_D0 FPIOAFunction = 4 // SPI0 Data 0
|
||||
FUNC_SPI0_D1 FPIOAFunction = 5 // SPI0 Data 1
|
||||
FUNC_SPI0_D2 FPIOAFunction = 6 // SPI0 Data 2
|
||||
FUNC_SPI0_D3 FPIOAFunction = 7 // SPI0 Data 3
|
||||
FUNC_SPI0_D4 FPIOAFunction = 8 // SPI0 Data 4
|
||||
FUNC_SPI0_D5 FPIOAFunction = 9 // SPI0 Data 5
|
||||
FUNC_SPI0_D6 FPIOAFunction = 10 // SPI0 Data 6
|
||||
FUNC_SPI0_D7 FPIOAFunction = 11 // SPI0 Data 7
|
||||
FUNC_SPI0_SS0 FPIOAFunction = 12 // SPI0 Chip Select 0
|
||||
FUNC_SPI0_SS1 FPIOAFunction = 13 // SPI0 Chip Select 1
|
||||
FUNC_SPI0_SS2 FPIOAFunction = 14 // SPI0 Chip Select 2
|
||||
FUNC_SPI0_SS3 FPIOAFunction = 15 // SPI0 Chip Select 3
|
||||
FUNC_SPI0_ARB FPIOAFunction = 16 // SPI0 Arbitration
|
||||
FUNC_SPI0_SCLK FPIOAFunction = 17 // SPI0 Serial Clock
|
||||
FUNC_UARTHS_RX FPIOAFunction = 18 // UART High speed Receiver
|
||||
FUNC_UARTHS_TX FPIOAFunction = 19 // UART High speed Transmitter
|
||||
FUNC_RESV6 FPIOAFunction = 20 // Reserved function
|
||||
FUNC_RESV7 FPIOAFunction = 21 // Reserved function
|
||||
FUNC_CLK_SPI1 FPIOAFunction = 22 // Clock SPI1
|
||||
FUNC_CLK_I2C1 FPIOAFunction = 23 // Clock I2C1
|
||||
FUNC_GPIOHS0 FPIOAFunction = 24 // GPIO High speed 0
|
||||
FUNC_GPIOHS1 FPIOAFunction = 25 // GPIO High speed 1
|
||||
FUNC_GPIOHS2 FPIOAFunction = 26 // GPIO High speed 2
|
||||
FUNC_GPIOHS3 FPIOAFunction = 27 // GPIO High speed 3
|
||||
FUNC_GPIOHS4 FPIOAFunction = 28 // GPIO High speed 4
|
||||
FUNC_GPIOHS5 FPIOAFunction = 29 // GPIO High speed 5
|
||||
FUNC_GPIOHS6 FPIOAFunction = 30 // GPIO High speed 6
|
||||
FUNC_GPIOHS7 FPIOAFunction = 31 // GPIO High speed 7
|
||||
FUNC_GPIOHS8 FPIOAFunction = 32 // GPIO High speed 8
|
||||
FUNC_GPIOHS9 FPIOAFunction = 33 // GPIO High speed 9
|
||||
FUNC_GPIOHS10 FPIOAFunction = 34 // GPIO High speed 10
|
||||
FUNC_GPIOHS11 FPIOAFunction = 35 // GPIO High speed 11
|
||||
FUNC_GPIOHS12 FPIOAFunction = 36 // GPIO High speed 12
|
||||
FUNC_GPIOHS13 FPIOAFunction = 37 // GPIO High speed 13
|
||||
FUNC_GPIOHS14 FPIOAFunction = 38 // GPIO High speed 14
|
||||
FUNC_GPIOHS15 FPIOAFunction = 39 // GPIO High speed 15
|
||||
FUNC_GPIOHS16 FPIOAFunction = 40 // GPIO High speed 16
|
||||
FUNC_GPIOHS17 FPIOAFunction = 41 // GPIO High speed 17
|
||||
FUNC_GPIOHS18 FPIOAFunction = 42 // GPIO High speed 18
|
||||
FUNC_GPIOHS19 FPIOAFunction = 43 // GPIO High speed 19
|
||||
FUNC_GPIOHS20 FPIOAFunction = 44 // GPIO High speed 20
|
||||
FUNC_GPIOHS21 FPIOAFunction = 45 // GPIO High speed 21
|
||||
FUNC_GPIOHS22 FPIOAFunction = 46 // GPIO High speed 22
|
||||
FUNC_GPIOHS23 FPIOAFunction = 47 // GPIO High speed 23
|
||||
FUNC_GPIOHS24 FPIOAFunction = 48 // GPIO High speed 24
|
||||
FUNC_GPIOHS25 FPIOAFunction = 49 // GPIO High speed 25
|
||||
FUNC_GPIOHS26 FPIOAFunction = 50 // GPIO High speed 26
|
||||
FUNC_GPIOHS27 FPIOAFunction = 51 // GPIO High speed 27
|
||||
FUNC_GPIOHS28 FPIOAFunction = 52 // GPIO High speed 28
|
||||
FUNC_GPIOHS29 FPIOAFunction = 53 // GPIO High speed 29
|
||||
FUNC_GPIOHS30 FPIOAFunction = 54 // GPIO High speed 30
|
||||
FUNC_GPIOHS31 FPIOAFunction = 55 // GPIO High speed 31
|
||||
FUNC_GPIO0 FPIOAFunction = 56 // GPIO pin 0
|
||||
FUNC_GPIO1 FPIOAFunction = 57 // GPIO pin 1
|
||||
FUNC_GPIO2 FPIOAFunction = 58 // GPIO pin 2
|
||||
FUNC_GPIO3 FPIOAFunction = 59 // GPIO pin 3
|
||||
FUNC_GPIO4 FPIOAFunction = 60 // GPIO pin 4
|
||||
FUNC_GPIO5 FPIOAFunction = 61 // GPIO pin 5
|
||||
FUNC_GPIO6 FPIOAFunction = 62 // GPIO pin 6
|
||||
FUNC_GPIO7 FPIOAFunction = 63 // GPIO pin 7
|
||||
FUNC_UART1_RX FPIOAFunction = 64 // UART1 Receiver
|
||||
FUNC_UART1_TX FPIOAFunction = 65 // UART1 Transmitter
|
||||
FUNC_UART2_RX FPIOAFunction = 66 // UART2 Receiver
|
||||
FUNC_UART2_TX FPIOAFunction = 67 // UART2 Transmitter
|
||||
FUNC_UART3_RX FPIOAFunction = 68 // UART3 Receiver
|
||||
FUNC_UART3_TX FPIOAFunction = 69 // UART3 Transmitter
|
||||
FUNC_SPI1_D0 FPIOAFunction = 70 // SPI1 Data 0
|
||||
FUNC_SPI1_D1 FPIOAFunction = 71 // SPI1 Data 1
|
||||
FUNC_SPI1_D2 FPIOAFunction = 72 // SPI1 Data 2
|
||||
FUNC_SPI1_D3 FPIOAFunction = 73 // SPI1 Data 3
|
||||
FUNC_SPI1_D4 FPIOAFunction = 74 // SPI1 Data 4
|
||||
FUNC_SPI1_D5 FPIOAFunction = 75 // SPI1 Data 5
|
||||
FUNC_SPI1_D6 FPIOAFunction = 76 // SPI1 Data 6
|
||||
FUNC_SPI1_D7 FPIOAFunction = 77 // SPI1 Data 7
|
||||
FUNC_SPI1_SS0 FPIOAFunction = 78 // SPI1 Chip Select 0
|
||||
FUNC_SPI1_SS1 FPIOAFunction = 79 // SPI1 Chip Select 1
|
||||
FUNC_SPI1_SS2 FPIOAFunction = 80 // SPI1 Chip Select 2
|
||||
FUNC_SPI1_SS3 FPIOAFunction = 81 // SPI1 Chip Select 3
|
||||
FUNC_SPI1_ARB FPIOAFunction = 82 // SPI1 Arbitration
|
||||
FUNC_SPI1_SCLK FPIOAFunction = 83 // SPI1 Serial Clock
|
||||
FUNC_SPI_PERIPHERAL_D0 FPIOAFunction = 84 // SPI Peripheral Data 0
|
||||
FUNC_SPI_PERIPHERAL_SS FPIOAFunction = 85 // SPI Peripheral Select
|
||||
FUNC_SPI_PERIPHERAL_SCLK FPIOAFunction = 86 // SPI Peripheral Serial Clock
|
||||
FUNC_I2S0_MCLK FPIOAFunction = 87 // I2S0 Main Clock
|
||||
FUNC_I2S0_SCLK FPIOAFunction = 88 // I2S0 Serial Clock(BCLK)
|
||||
FUNC_I2S0_WS FPIOAFunction = 89 // I2S0 Word Select(LRCLK)
|
||||
FUNC_I2S0_IN_D0 FPIOAFunction = 90 // I2S0 Serial Data Input 0
|
||||
FUNC_I2S0_IN_D1 FPIOAFunction = 91 // I2S0 Serial Data Input 1
|
||||
FUNC_I2S0_IN_D2 FPIOAFunction = 92 // I2S0 Serial Data Input 2
|
||||
FUNC_I2S0_IN_D3 FPIOAFunction = 93 // I2S0 Serial Data Input 3
|
||||
FUNC_I2S0_OUT_D0 FPIOAFunction = 94 // I2S0 Serial Data Output 0
|
||||
FUNC_I2S0_OUT_D1 FPIOAFunction = 95 // I2S0 Serial Data Output 1
|
||||
FUNC_I2S0_OUT_D2 FPIOAFunction = 96 // I2S0 Serial Data Output 2
|
||||
FUNC_I2S0_OUT_D3 FPIOAFunction = 97 // I2S0 Serial Data Output 3
|
||||
FUNC_I2S1_MCLK FPIOAFunction = 98 // I2S1 Main Clock
|
||||
FUNC_I2S1_SCLK FPIOAFunction = 99 // I2S1 Serial Clock(BCLK)
|
||||
FUNC_I2S1_WS FPIOAFunction = 100 // I2S1 Word Select(LRCLK)
|
||||
FUNC_I2S1_IN_D0 FPIOAFunction = 101 // I2S1 Serial Data Input 0
|
||||
FUNC_I2S1_IN_D1 FPIOAFunction = 102 // I2S1 Serial Data Input 1
|
||||
FUNC_I2S1_IN_D2 FPIOAFunction = 103 // I2S1 Serial Data Input 2
|
||||
FUNC_I2S1_IN_D3 FPIOAFunction = 104 // I2S1 Serial Data Input 3
|
||||
FUNC_I2S1_OUT_D0 FPIOAFunction = 105 // I2S1 Serial Data Output 0
|
||||
FUNC_I2S1_OUT_D1 FPIOAFunction = 106 // I2S1 Serial Data Output 1
|
||||
FUNC_I2S1_OUT_D2 FPIOAFunction = 107 // I2S1 Serial Data Output 2
|
||||
FUNC_I2S1_OUT_D3 FPIOAFunction = 108 // I2S1 Serial Data Output 3
|
||||
FUNC_I2S2_MCLK FPIOAFunction = 109 // I2S2 Main Clock
|
||||
FUNC_I2S2_SCLK FPIOAFunction = 110 // I2S2 Serial Clock(BCLK)
|
||||
FUNC_I2S2_WS FPIOAFunction = 111 // I2S2 Word Select(LRCLK)
|
||||
FUNC_I2S2_IN_D0 FPIOAFunction = 112 // I2S2 Serial Data Input 0
|
||||
FUNC_I2S2_IN_D1 FPIOAFunction = 113 // I2S2 Serial Data Input 1
|
||||
FUNC_I2S2_IN_D2 FPIOAFunction = 114 // I2S2 Serial Data Input 2
|
||||
FUNC_I2S2_IN_D3 FPIOAFunction = 115 // I2S2 Serial Data Input 3
|
||||
FUNC_I2S2_OUT_D0 FPIOAFunction = 116 // I2S2 Serial Data Output 0
|
||||
FUNC_I2S2_OUT_D1 FPIOAFunction = 117 // I2S2 Serial Data Output 1
|
||||
FUNC_I2S2_OUT_D2 FPIOAFunction = 118 // I2S2 Serial Data Output 2
|
||||
FUNC_I2S2_OUT_D3 FPIOAFunction = 119 // I2S2 Serial Data Output 3
|
||||
FUNC_RESV0 FPIOAFunction = 120 // Reserved function
|
||||
FUNC_RESV1 FPIOAFunction = 121 // Reserved function
|
||||
FUNC_RESV2 FPIOAFunction = 122 // Reserved function
|
||||
FUNC_RESV3 FPIOAFunction = 123 // Reserved function
|
||||
FUNC_RESV4 FPIOAFunction = 124 // Reserved function
|
||||
FUNC_RESV5 FPIOAFunction = 125 // Reserved function
|
||||
FUNC_I2C0_SCLK FPIOAFunction = 126 // I2C0 Serial Clock
|
||||
FUNC_I2C0_SDA FPIOAFunction = 127 // I2C0 Serial Data
|
||||
FUNC_I2C1_SCLK FPIOAFunction = 128 // I2C1 Serial Clock
|
||||
FUNC_I2C1_SDA FPIOAFunction = 129 // I2C1 Serial Data
|
||||
FUNC_I2C2_SCLK FPIOAFunction = 130 // I2C2 Serial Clock
|
||||
FUNC_I2C2_SDA FPIOAFunction = 131 // I2C2 Serial Data
|
||||
FUNC_CMOS_XCLK FPIOAFunction = 132 // DVP System Clock
|
||||
FUNC_CMOS_RST FPIOAFunction = 133 // DVP System Reset
|
||||
FUNC_CMOS_PWDN FPIOAFunction = 134 // DVP Power Down Mode
|
||||
FUNC_CMOS_VSYNC FPIOAFunction = 135 // DVP Vertical Sync
|
||||
FUNC_CMOS_HREF FPIOAFunction = 136 // DVP Horizontal Reference output
|
||||
FUNC_CMOS_PCLK FPIOAFunction = 137 // Pixel Clock
|
||||
FUNC_CMOS_D0 FPIOAFunction = 138 // Data Bit 0
|
||||
FUNC_CMOS_D1 FPIOAFunction = 139 // Data Bit 1
|
||||
FUNC_CMOS_D2 FPIOAFunction = 140 // Data Bit 2
|
||||
FUNC_CMOS_D3 FPIOAFunction = 141 // Data Bit 3
|
||||
FUNC_CMOS_D4 FPIOAFunction = 142 // Data Bit 4
|
||||
FUNC_CMOS_D5 FPIOAFunction = 143 // Data Bit 5
|
||||
FUNC_CMOS_D6 FPIOAFunction = 144 // Data Bit 6
|
||||
FUNC_CMOS_D7 FPIOAFunction = 145 // Data Bit 7
|
||||
FUNC_SCCB_SCLK FPIOAFunction = 146 // SCCB Serial Clock
|
||||
FUNC_SCCB_SDA FPIOAFunction = 147 // SCCB Serial Data
|
||||
FUNC_UART1_CTS FPIOAFunction = 148 // UART1 Clear To Send
|
||||
FUNC_UART1_DSR FPIOAFunction = 149 // UART1 Data Set Ready
|
||||
FUNC_UART1_DCD FPIOAFunction = 150 // UART1 Data Carrier Detect
|
||||
FUNC_UART1_RI FPIOAFunction = 151 // UART1 Ring Indicator
|
||||
FUNC_UART1_SIR_IN FPIOAFunction = 152 // UART1 Serial Infrared Input
|
||||
FUNC_UART1_DTR FPIOAFunction = 153 // UART1 Data Terminal Ready
|
||||
FUNC_UART1_RTS FPIOAFunction = 154 // UART1 Request To Send
|
||||
FUNC_UART1_OUT2 FPIOAFunction = 155 // UART1 User-designated Output 2
|
||||
FUNC_UART1_OUT1 FPIOAFunction = 156 // UART1 User-designated Output 1
|
||||
FUNC_UART1_SIR_OUT FPIOAFunction = 157 // UART1 Serial Infrared Output
|
||||
FUNC_UART1_BAUD FPIOAFunction = 158 // UART1 Transmit Clock Output
|
||||
FUNC_UART1_RE FPIOAFunction = 159 // UART1 Receiver Output Enable
|
||||
FUNC_UART1_DE FPIOAFunction = 160 // UART1 Driver Output Enable
|
||||
FUNC_UART1_RS485_EN FPIOAFunction = 161 // UART1 RS485 Enable
|
||||
FUNC_UART2_CTS FPIOAFunction = 162 // UART2 Clear To Send
|
||||
FUNC_UART2_DSR FPIOAFunction = 163 // UART2 Data Set Ready
|
||||
FUNC_UART2_DCD FPIOAFunction = 164 // UART2 Data Carrier Detect
|
||||
FUNC_UART2_RI FPIOAFunction = 165 // UART2 Ring Indicator
|
||||
FUNC_UART2_SIR_IN FPIOAFunction = 166 // UART2 Serial Infrared Input
|
||||
FUNC_UART2_DTR FPIOAFunction = 167 // UART2 Data Terminal Ready
|
||||
FUNC_UART2_RTS FPIOAFunction = 168 // UART2 Request To Send
|
||||
FUNC_UART2_OUT2 FPIOAFunction = 169 // UART2 User-designated Output 2
|
||||
FUNC_UART2_OUT1 FPIOAFunction = 170 // UART2 User-designated Output 1
|
||||
FUNC_UART2_SIR_OUT FPIOAFunction = 171 // UART2 Serial Infrared Output
|
||||
FUNC_UART2_BAUD FPIOAFunction = 172 // UART2 Transmit Clock Output
|
||||
FUNC_UART2_RE FPIOAFunction = 173 // UART2 Receiver Output Enable
|
||||
FUNC_UART2_DE FPIOAFunction = 174 // UART2 Driver Output Enable
|
||||
FUNC_UART2_RS485_EN FPIOAFunction = 175 // UART2 RS485 Enable
|
||||
FUNC_UART3_CTS FPIOAFunction = 176 // UART3 Clear To Send
|
||||
FUNC_UART3_DSR FPIOAFunction = 177 // UART3 Data Set Ready
|
||||
FUNC_UART3_DCD FPIOAFunction = 178 // UART3 Data Carrier Detect
|
||||
FUNC_UART3_RI FPIOAFunction = 179 // UART3 Ring Indicator
|
||||
FUNC_UART3_SIR_IN FPIOAFunction = 180 // UART3 Serial Infrared Input
|
||||
FUNC_UART3_DTR FPIOAFunction = 181 // UART3 Data Terminal Ready
|
||||
FUNC_UART3_RTS FPIOAFunction = 182 // UART3 Request To Send
|
||||
FUNC_UART3_OUT2 FPIOAFunction = 183 // UART3 User-designated Output 2
|
||||
FUNC_UART3_OUT1 FPIOAFunction = 184 // UART3 User-designated Output 1
|
||||
FUNC_UART3_SIR_OUT FPIOAFunction = 185 // UART3 Serial Infrared Output
|
||||
FUNC_UART3_BAUD FPIOAFunction = 186 // UART3 Transmit Clock Output
|
||||
FUNC_UART3_RE FPIOAFunction = 187 // UART3 Receiver Output Enable
|
||||
FUNC_UART3_DE FPIOAFunction = 188 // UART3 Driver Output Enable
|
||||
FUNC_UART3_RS485_EN FPIOAFunction = 189 // UART3 RS485 Enable
|
||||
FUNC_TIMER0_TOGGLE1 FPIOAFunction = 190 // TIMER0 Toggle Output 1
|
||||
FUNC_TIMER0_TOGGLE2 FPIOAFunction = 191 // TIMER0 Toggle Output 2
|
||||
FUNC_TIMER0_TOGGLE3 FPIOAFunction = 192 // TIMER0 Toggle Output 3
|
||||
FUNC_TIMER0_TOGGLE4 FPIOAFunction = 193 // TIMER0 Toggle Output 4
|
||||
FUNC_TIMER1_TOGGLE1 FPIOAFunction = 194 // TIMER1 Toggle Output 1
|
||||
FUNC_TIMER1_TOGGLE2 FPIOAFunction = 195 // TIMER1 Toggle Output 2
|
||||
FUNC_TIMER1_TOGGLE3 FPIOAFunction = 196 // TIMER1 Toggle Output 3
|
||||
FUNC_TIMER1_TOGGLE4 FPIOAFunction = 197 // TIMER1 Toggle Output 4
|
||||
FUNC_TIMER2_TOGGLE1 FPIOAFunction = 198 // TIMER2 Toggle Output 1
|
||||
FUNC_TIMER2_TOGGLE2 FPIOAFunction = 199 // TIMER2 Toggle Output 2
|
||||
FUNC_TIMER2_TOGGLE3 FPIOAFunction = 200 // TIMER2 Toggle Output 3
|
||||
FUNC_TIMER2_TOGGLE4 FPIOAFunction = 201 // TIMER2 Toggle Output 4
|
||||
FUNC_CLK_SPI2 FPIOAFunction = 202 // Clock SPI2
|
||||
FUNC_CLK_I2C2 FPIOAFunction = 203 // Clock I2C2
|
||||
FUNC_INTERNAL0 FPIOAFunction = 204 // Internal function signal 0
|
||||
FUNC_INTERNAL1 FPIOAFunction = 205 // Internal function signal 1
|
||||
FUNC_INTERNAL2 FPIOAFunction = 206 // Internal function signal 2
|
||||
FUNC_INTERNAL3 FPIOAFunction = 207 // Internal function signal 3
|
||||
FUNC_INTERNAL4 FPIOAFunction = 208 // Internal function signal 4
|
||||
FUNC_INTERNAL5 FPIOAFunction = 209 // Internal function signal 5
|
||||
FUNC_INTERNAL6 FPIOAFunction = 210 // Internal function signal 6
|
||||
FUNC_INTERNAL7 FPIOAFunction = 211 // Internal function signal 7
|
||||
FUNC_INTERNAL8 FPIOAFunction = 212 // Internal function signal 8
|
||||
FUNC_INTERNAL9 FPIOAFunction = 213 // Internal function signal 9
|
||||
FUNC_INTERNAL10 FPIOAFunction = 214 // Internal function signal 10
|
||||
FUNC_INTERNAL11 FPIOAFunction = 215 // Internal function signal 11
|
||||
FUNC_INTERNAL12 FPIOAFunction = 216 // Internal function signal 12
|
||||
FUNC_INTERNAL13 FPIOAFunction = 217 // Internal function signal 13
|
||||
FUNC_INTERNAL14 FPIOAFunction = 218 // Internal function signal 14
|
||||
FUNC_INTERNAL15 FPIOAFunction = 219 // Internal function signal 15
|
||||
FUNC_INTERNAL16 FPIOAFunction = 220 // Internal function signal 16
|
||||
FUNC_INTERNAL17 FPIOAFunction = 221 // Internal function signal 17
|
||||
FUNC_CONSTANT FPIOAFunction = 222 // Constant function
|
||||
FUNC_INTERNAL18 FPIOAFunction = 223 // Internal function signal 18
|
||||
FUNC_DEBUG0 FPIOAFunction = 224 // Debug function 0
|
||||
FUNC_DEBUG1 FPIOAFunction = 225 // Debug function 1
|
||||
FUNC_DEBUG2 FPIOAFunction = 226 // Debug function 2
|
||||
FUNC_DEBUG3 FPIOAFunction = 227 // Debug function 3
|
||||
FUNC_DEBUG4 FPIOAFunction = 228 // Debug function 4
|
||||
FUNC_DEBUG5 FPIOAFunction = 229 // Debug function 5
|
||||
FUNC_DEBUG6 FPIOAFunction = 230 // Debug function 6
|
||||
FUNC_DEBUG7 FPIOAFunction = 231 // Debug function 7
|
||||
FUNC_DEBUG8 FPIOAFunction = 232 // Debug function 8
|
||||
FUNC_DEBUG9 FPIOAFunction = 233 // Debug function 9
|
||||
FUNC_DEBUG10 FPIOAFunction = 234 // Debug function 10
|
||||
FUNC_DEBUG11 FPIOAFunction = 235 // Debug function 11
|
||||
FUNC_DEBUG12 FPIOAFunction = 236 // Debug function 12
|
||||
FUNC_DEBUG13 FPIOAFunction = 237 // Debug function 13
|
||||
FUNC_DEBUG14 FPIOAFunction = 238 // Debug function 14
|
||||
FUNC_DEBUG15 FPIOAFunction = 239 // Debug function 15
|
||||
FUNC_DEBUG16 FPIOAFunction = 240 // Debug function 16
|
||||
FUNC_DEBUG17 FPIOAFunction = 241 // Debug function 17
|
||||
FUNC_DEBUG18 FPIOAFunction = 242 // Debug function 18
|
||||
FUNC_DEBUG19 FPIOAFunction = 243 // Debug function 19
|
||||
FUNC_DEBUG20 FPIOAFunction = 244 // Debug function 20
|
||||
FUNC_DEBUG21 FPIOAFunction = 245 // Debug function 21
|
||||
FUNC_DEBUG22 FPIOAFunction = 246 // Debug function 22
|
||||
FUNC_DEBUG23 FPIOAFunction = 247 // Debug function 23
|
||||
FUNC_DEBUG24 FPIOAFunction = 248 // Debug function 24
|
||||
FUNC_DEBUG25 FPIOAFunction = 249 // Debug function 25
|
||||
FUNC_DEBUG26 FPIOAFunction = 250 // Debug function 26
|
||||
FUNC_DEBUG27 FPIOAFunction = 251 // Debug function 27
|
||||
FUNC_DEBUG28 FPIOAFunction = 252 // Debug function 28
|
||||
FUNC_DEBUG29 FPIOAFunction = 253 // Debug function 29
|
||||
FUNC_DEBUG30 FPIOAFunction = 254 // Debug function 30
|
||||
FUNC_DEBUG31 FPIOAFunction = 255 // Debug function 31
|
||||
)
|
||||
|
||||
// These are the default FPIOA values for each function.
|
||||
// (source: https://github.com/kendryte/kendryte-standalone-sdk/blob/develop/lib/drivers/fpioa.c#L69)
|
||||
var fpioaFuncDefaults [256]uint32 = [256]uint32{
|
||||
0x00900000, 0x00900001, 0x00900002, 0x00001f03, 0x00b03f04, 0x00b03f05, 0x00b03f06, 0x00b03f07, 0x00b03f08,
|
||||
0x00b03f09, 0x00b03f0a, 0x00b03f0b, 0x00001f0c, 0x00001f0d, 0x00001f0e, 0x00001f0f, 0x03900010, 0x00001f11,
|
||||
0x00900012, 0x00001f13, 0x00900014, 0x00900015, 0x00001f16, 0x00001f17, 0x00901f18, 0x00901f19, 0x00901f1a,
|
||||
0x00901f1b, 0x00901f1c, 0x00901f1d, 0x00901f1e, 0x00901f1f, 0x00901f20, 0x00901f21, 0x00901f22, 0x00901f23,
|
||||
0x00901f24, 0x00901f25, 0x00901f26, 0x00901f27, 0x00901f28, 0x00901f29, 0x00901f2a, 0x00901f2b, 0x00901f2c,
|
||||
0x00901f2d, 0x00901f2e, 0x00901f2f, 0x00901f30, 0x00901f31, 0x00901f32, 0x00901f33, 0x00901f34, 0x00901f35,
|
||||
0x00901f36, 0x00901f37, 0x00901f38, 0x00901f39, 0x00901f3a, 0x00901f3b, 0x00901f3c, 0x00901f3d, 0x00901f3e,
|
||||
0x00901f3f, 0x00900040, 0x00001f41, 0x00900042, 0x00001f43, 0x00900044, 0x00001f45, 0x00b03f46, 0x00b03f47,
|
||||
0x00b03f48, 0x00b03f49, 0x00b03f4a, 0x00b03f4b, 0x00b03f4c, 0x00b03f4d, 0x00001f4e, 0x00001f4f, 0x00001f50,
|
||||
0x00001f51, 0x03900052, 0x00001f53, 0x00b03f54, 0x00900055, 0x00900056, 0x00001f57, 0x00001f58, 0x00001f59,
|
||||
0x0090005a, 0x0090005b, 0x0090005c, 0x0090005d, 0x00001f5e, 0x00001f5f, 0x00001f60, 0x00001f61, 0x00001f62,
|
||||
0x00001f63, 0x00001f64, 0x00900065, 0x00900066, 0x00900067, 0x00900068, 0x00001f69, 0x00001f6a, 0x00001f6b,
|
||||
0x00001f6c, 0x00001f6d, 0x00001f6e, 0x00001f6f, 0x00900070, 0x00900071, 0x00900072, 0x00900073, 0x00001f74,
|
||||
0x00001f75, 0x00001f76, 0x00001f77, 0x00000078, 0x00000079, 0x0000007a, 0x0000007b, 0x0000007c, 0x0000007d,
|
||||
0x0099107e, 0x0099107f, 0x00991080, 0x00991081, 0x00991082, 0x00991083, 0x00001f84, 0x00001f85, 0x00001f86,
|
||||
0x00900087, 0x00900088, 0x00900089, 0x0090008a, 0x0090008b, 0x0090008c, 0x0090008d, 0x0090008e, 0x0090008f,
|
||||
0x00900090, 0x00900091, 0x00993092, 0x00993093, 0x00900094, 0x00900095, 0x00900096, 0x00900097, 0x00900098,
|
||||
0x00001f99, 0x00001f9a, 0x00001f9b, 0x00001f9c, 0x00001f9d, 0x00001f9e, 0x00001f9f, 0x00001fa0, 0x00001fa1,
|
||||
0x009000a2, 0x009000a3, 0x009000a4, 0x009000a5, 0x009000a6, 0x00001fa7, 0x00001fa8, 0x00001fa9, 0x00001faa,
|
||||
0x00001fab, 0x00001fac, 0x00001fad, 0x00001fae, 0x00001faf, 0x009000b0, 0x009000b1, 0x009000b2, 0x009000b3,
|
||||
0x009000b4, 0x00001fb5, 0x00001fb6, 0x00001fb7, 0x00001fb8, 0x00001fb9, 0x00001fba, 0x00001fbb, 0x00001fbc,
|
||||
0x00001fbd, 0x00001fbe, 0x00001fbf, 0x00001fc0, 0x00001fc1, 0x00001fc2, 0x00001fc3, 0x00001fc4, 0x00001fc5,
|
||||
0x00001fc6, 0x00001fc7, 0x00001fc8, 0x00001fc9, 0x00001fca, 0x00001fcb, 0x00001fcc, 0x00001fcd, 0x00001fce,
|
||||
0x00001fcf, 0x00001fd0, 0x00001fd1, 0x00001fd2, 0x00001fd3, 0x00001fd4, 0x009000d5, 0x009000d6, 0x009000d7,
|
||||
0x009000d8, 0x009100d9, 0x00991fda, 0x009000db, 0x009000dc, 0x009000dd, 0x000000de, 0x009000df, 0x00001fe0,
|
||||
0x00001fe1, 0x00001fe2, 0x00001fe3, 0x00001fe4, 0x00001fe5, 0x00001fe6, 0x00001fe7, 0x00001fe8, 0x00001fe9,
|
||||
0x00001fea, 0x00001feb, 0x00001fec, 0x00001fed, 0x00001fee, 0x00001fef, 0x00001ff0, 0x00001ff1, 0x00001ff2,
|
||||
0x00001ff3, 0x00001ff4, 0x00001ff5, 0x00001ff6, 0x00001ff7, 0x00001ff8, 0x00001ff9, 0x00001ffa, 0x00001ffb,
|
||||
0x00001ffc, 0x00001ffd, 0x00001ffe, 0x00001fff,
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// +build maixbit
|
||||
|
||||
package machine
|
||||
|
||||
// Pins on the MAix Bit.
|
||||
const (
|
||||
D0 = P00 // JTAG_TCLK
|
||||
D1 = P01 // JTAG_TDI
|
||||
D2 = P02 // JTAG_TMS
|
||||
D3 = P03 // JTAG_TDO
|
||||
D4 = P04 // UARTHS_RX
|
||||
D5 = P05 // UARTHS_TX
|
||||
D6 = P06 // RESV0
|
||||
D7 = P07 // RESV0
|
||||
D8 = P08 // GPIO1
|
||||
D9 = P09 // GPIO2
|
||||
D10 = P10 // GPIO3
|
||||
D11 = P11 // GPIO4
|
||||
D12 = P12 // GPIO5
|
||||
D13 = P13 // GPIO6
|
||||
D14 = P14 // GPIO7
|
||||
D15 = P15 // GPIO8
|
||||
D16 = P16 // GPIOHS0
|
||||
D17 = P17 // GPIOHS1
|
||||
D18 = P18 // GPIOHS2
|
||||
D19 = P19 // GPIOHS3
|
||||
D20 = P20 // GPIOHS4
|
||||
D21 = P21 // GPIOHS5
|
||||
D22 = P22 // GPIOHS6
|
||||
D23 = P23 // GPIOHS7
|
||||
D24 = P24 // GPIOHS8
|
||||
D25 = P25 // GPIOHS9
|
||||
D26 = P26 // GPIOHS10 / SPI0_SDI
|
||||
D27 = P27 // GPIOHS11 / SPI0_SCLK
|
||||
D28 = P28 // GPIOHS12 / SPI0_SDO
|
||||
D29 = P29 // GPIOHS13
|
||||
D30 = P30 // GPIOHS14
|
||||
D31 = P31 // GPIOHS15
|
||||
D32 = P32 // GPIOHS16
|
||||
D33 = P33 // GPIOHS17
|
||||
D34 = P34 // GPIOHS18
|
||||
D35 = P35 // GPIOHS19
|
||||
)
|
||||
|
||||
const (
|
||||
LED = LED1
|
||||
LED1 = LED_RED
|
||||
LED2 = LED_GREEN
|
||||
LED3 = LED_BLUE
|
||||
LED_RED = D13
|
||||
LED_GREEN = D12
|
||||
LED_BLUE = D14
|
||||
)
|
||||
|
||||
// Default pins for UARTHS.
|
||||
const (
|
||||
UART_TX_PIN = D5
|
||||
UART_RX_PIN = D4
|
||||
)
|
||||
|
||||
// SPI pins.
|
||||
const (
|
||||
SPI0_SCK_PIN = D27
|
||||
SPI0_SDO_PIN = D28
|
||||
SPI0_SDI_PIN = D26
|
||||
)
|
||||
|
||||
// I2C pins.
|
||||
const (
|
||||
I2C0_SDA_PIN = D34
|
||||
I2C0_SCL_PIN = D35
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
// +build k210,maixbit
|
||||
|
||||
package machine
|
||||
|
||||
import "device/kendryte"
|
||||
|
||||
// SPI on the MAix Bit.
|
||||
var (
|
||||
SPI0 = SPI{
|
||||
Bus: kendryte.SPI0,
|
||||
}
|
||||
SPI1 = SPI{
|
||||
Bus: kendryte.SPI1,
|
||||
}
|
||||
)
|
||||
|
||||
// I2C on the MAix Bit.
|
||||
var (
|
||||
I2C0 = I2C{
|
||||
Bus: kendryte.I2C0,
|
||||
}
|
||||
I2C1 = I2C{
|
||||
Bus: kendryte.I2C1,
|
||||
}
|
||||
I2C2 = I2C{
|
||||
Bus: kendryte.I2C2,
|
||||
}
|
||||
)
|
||||
@@ -75,19 +75,19 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA13 // SCK: SERCOM2/PAD[1]
|
||||
SPI0_MOSI_PIN = PA12 // MOSI: SERCOM2/PAD[0]
|
||||
SPI0_MISO_PIN = PA14 // MISO: SERCOM2/PAD[2]
|
||||
SPI0_SCK_PIN = PA13 // SCK: SERCOM2/PAD[1]
|
||||
SPI0_SDO_PIN = PA12 // SDO: SERCOM2/PAD[0]
|
||||
SPI0_SDI_PIN = PA14 // SDI: SERCOM2/PAD[2]
|
||||
|
||||
NINA_MOSI = SPI0_MOSI_PIN
|
||||
NINA_MISO = SPI0_MISO_PIN
|
||||
NINA_SCK = SPI0_SCK_PIN
|
||||
NINA_SDO = SPI0_SDO_PIN
|
||||
NINA_SDI = SPI0_SDI_PIN
|
||||
NINA_SCK = SPI0_SCK_PIN
|
||||
)
|
||||
|
||||
const (
|
||||
SPI1_SCK_PIN = D12 // MISO: SERCOM1/PAD[1]
|
||||
SPI1_MOSI_PIN = D11 // MOSI: SERCOM1/PAD[3]
|
||||
SPI1_MISO_PIN = D13 // SCK: SERCOM1/PAD[0]
|
||||
SPI1_SCK_PIN = D12 // SDI: SERCOM1/PAD[1]
|
||||
SPI1_SDO_PIN = D11 // SDO: SERCOM1/PAD[3]
|
||||
SPI1_SDI_PIN = D13 // SCK: SERCOM1/PAD[0]
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -33,9 +33,9 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 23 // P13 on the board
|
||||
SPI0_MOSI_PIN Pin = 21 // P15 on the board
|
||||
SPI0_MISO_PIN Pin = 22 // P14 on the board
|
||||
SPI0_SCK_PIN Pin = 23 // P13 on the board
|
||||
SPI0_SDO_PIN Pin = 21 // P15 on the board
|
||||
SPI0_SDI_PIN Pin = 22 // P14 on the board
|
||||
)
|
||||
|
||||
// GPIO/Analog pins
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// +build nodemcu
|
||||
|
||||
// Pinout for the NodeMCU dev kit.
|
||||
|
||||
package machine
|
||||
|
||||
// GPIO pins on the NodeMCU board.
|
||||
const (
|
||||
D0 Pin = 16
|
||||
D1 Pin = 5
|
||||
D2 Pin = 4
|
||||
D3 Pin = 0
|
||||
D4 Pin = 2
|
||||
D5 Pin = 14
|
||||
D6 Pin = 12
|
||||
D7 Pin = 13
|
||||
D8 Pin = 15
|
||||
)
|
||||
|
||||
// Onboard blue LED (on the AI-Thinker module).
|
||||
const LED = D4
|
||||
@@ -31,9 +31,9 @@ const (
|
||||
|
||||
// SPI pins (unused)
|
||||
const (
|
||||
SPI0_SCK_PIN = NoPin
|
||||
SPI0_MOSI_PIN = NoPin
|
||||
SPI0_MISO_PIN = NoPin
|
||||
SPI0_SCK_PIN = NoPin
|
||||
SPI0_SDO_PIN = NoPin
|
||||
SPI0_SDI_PIN = NoPin
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -113,9 +113,9 @@ func init() {
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA5
|
||||
SPI0_MISO_PIN = PA6
|
||||
SPI0_MOSI_PIN = PA7
|
||||
SPI0_SCK_PIN = PA5
|
||||
SPI0_SDI_PIN = PA6
|
||||
SPI0_SDO_PIN = PA7
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
|
||||
@@ -34,8 +34,8 @@ const (
|
||||
D8 Pin = 35
|
||||
D9 Pin = 6 // Also TX
|
||||
D10 Pin = 8 // Also RX
|
||||
D11 Pin = 46 // Also MISO
|
||||
D12 Pin = 45 // Also MOSI
|
||||
D11 Pin = 46 // Also SDI
|
||||
D12 Pin = 45 // Also SDO
|
||||
D13 Pin = 47 // Also SCK
|
||||
)
|
||||
|
||||
@@ -58,16 +58,16 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_MOSI_PIN Pin = 45
|
||||
SPI0_MISO_PIN Pin = 46
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_SDO_PIN Pin = 45
|
||||
SPI0_SDI_PIN Pin = 46
|
||||
)
|
||||
|
||||
// Internal 4MB SPI Flash
|
||||
const (
|
||||
SPI1_SCK_PIN Pin = 19
|
||||
SPI1_MOSI_PIN Pin = 20
|
||||
SPI1_MISO_PIN Pin = 21
|
||||
SPI1_SDO_PIN Pin = 20
|
||||
SPI1_SDI_PIN Pin = 21
|
||||
SPI1_CS_PIN Pin = 17
|
||||
SPI1_WP_PIN Pin = 22
|
||||
SPI1_HOLD_PIN Pin = 23
|
||||
|
||||
@@ -34,8 +34,8 @@ const (
|
||||
D8 Pin = 35
|
||||
D9 Pin = 6 // Also TX
|
||||
D10 Pin = 8 // Also RX
|
||||
D11 Pin = 46 // Also MISO
|
||||
D12 Pin = 45 // Also MOSI
|
||||
D11 Pin = 46 // Also SDI
|
||||
D12 Pin = 45 // Also SDO
|
||||
D13 Pin = 47 // Also SCK
|
||||
)
|
||||
|
||||
@@ -63,16 +63,16 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_MOSI_PIN Pin = 45
|
||||
SPI0_MISO_PIN Pin = 46
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_SDO_PIN Pin = 45
|
||||
SPI0_SDI_PIN Pin = 46
|
||||
)
|
||||
|
||||
// Internal 4MB SPI Flash
|
||||
const (
|
||||
SPI1_SCK_PIN Pin = 19
|
||||
SPI1_MOSI_PIN Pin = 20
|
||||
SPI1_MISO_PIN Pin = 21
|
||||
SPI1_SDO_PIN Pin = 20
|
||||
SPI1_SDI_PIN Pin = 21
|
||||
SPI1_CS_PIN Pin = 17
|
||||
SPI1_WP_PIN Pin = 22
|
||||
SPI1_HOLD_PIN Pin = 23
|
||||
|
||||
@@ -34,8 +34,8 @@ const (
|
||||
D8 Pin = 35
|
||||
D9 Pin = 6 // Also TX
|
||||
D10 Pin = 8 // Also RX
|
||||
D11 Pin = 46 // Also MISO
|
||||
D12 Pin = 45 // Also MOSI
|
||||
D11 Pin = 46 // Also SDI
|
||||
D12 Pin = 45 // Also SDO
|
||||
D13 Pin = 47 // Also SCK
|
||||
)
|
||||
|
||||
@@ -58,16 +58,16 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_MOSI_PIN Pin = 45
|
||||
SPI0_MISO_PIN Pin = 46
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_SDO_PIN Pin = 45
|
||||
SPI0_SDI_PIN Pin = 46
|
||||
)
|
||||
|
||||
// Internal 4MB SPI Flash
|
||||
const (
|
||||
SPI1_SCK_PIN Pin = 19
|
||||
SPI1_MOSI_PIN Pin = 20
|
||||
SPI1_MISO_PIN Pin = 21
|
||||
SPI1_SDO_PIN Pin = 20
|
||||
SPI1_SDI_PIN Pin = 21
|
||||
SPI1_CS_PIN Pin = 17
|
||||
SPI1_WP_PIN Pin = 22
|
||||
SPI1_HOLD_PIN Pin = 23
|
||||
|
||||
@@ -33,7 +33,7 @@ const (
|
||||
|
||||
// SPI pins (unused)
|
||||
const (
|
||||
SPI0_SCK_PIN = NoPin
|
||||
SPI0_MOSI_PIN = NoPin
|
||||
SPI0_MISO_PIN = NoPin
|
||||
SPI0_SCK_PIN = NoPin
|
||||
SPI0_SDO_PIN = NoPin
|
||||
SPI0_SDI_PIN = NoPin
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 25
|
||||
SPI0_MOSI_PIN Pin = 23
|
||||
SPI0_MISO_PIN Pin = 24
|
||||
SPI0_SCK_PIN Pin = 25
|
||||
SPI0_SDO_PIN Pin = 23
|
||||
SPI0_SDI_PIN Pin = 24
|
||||
)
|
||||
|
||||
@@ -46,9 +46,9 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 47 // P1.15
|
||||
SPI0_MOSI_PIN Pin = 45 // P1.13
|
||||
SPI0_MISO_PIN Pin = 46 // P1.14
|
||||
SPI0_SCK_PIN Pin = 47 // P1.15
|
||||
SPI0_SDO_PIN Pin = 45 // P1.13
|
||||
SPI0_SDI_PIN Pin = 46 // P1.14
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -27,9 +27,9 @@ const (
|
||||
|
||||
// SPI pins for the PineTime.
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 2
|
||||
SPI0_MOSI_PIN Pin = 3
|
||||
SPI0_MISO_PIN Pin = 4
|
||||
SPI0_SCK_PIN Pin = 2
|
||||
SPI0_SDO_PIN Pin = 3
|
||||
SPI0_SDI_PIN Pin = 4
|
||||
)
|
||||
|
||||
// I2C pins for the PineTime.
|
||||
@@ -51,7 +51,7 @@ const VIBRATOR_PIN Pin = 16
|
||||
// http://files.pine64.org/doc/PineTime/PineTime%20Port%20Assignment%20rev1.0.pdf
|
||||
const (
|
||||
LCD_SCK = SPI0_SCK_PIN
|
||||
LCD_SDI = SPI0_MOSI_PIN
|
||||
LCD_SDI = SPI0_SDO_PIN
|
||||
LCD_RS Pin = 18
|
||||
LCD_CS Pin = 25
|
||||
LCD_RESET Pin = 26
|
||||
|
||||
@@ -91,16 +91,16 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_MOSI_PIN = PB23 // MOSI: SERCOM1/PAD[3]
|
||||
SPI0_MISO_PIN = PB22 // MISO: SERCOM1/PAD[2]
|
||||
SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_SDO_PIN = PB23 // SDO: SERCOM1/PAD[3]
|
||||
SPI0_SDI_PIN = PB22 // SDI: SERCOM1/PAD[2]
|
||||
)
|
||||
|
||||
// TFT SPI pins
|
||||
const (
|
||||
SPI1_SCK_PIN = PB13 // SCK: SERCOM4/PAD[1]
|
||||
SPI1_MOSI_PIN = PB15 // MOSI: SERCOM4/PAD[3]
|
||||
SPI1_MISO_PIN = NoPin
|
||||
SPI1_SCK_PIN = PB13 // SCK: SERCOM4/PAD[1]
|
||||
SPI1_SDO_PIN = PB15 // SDO: SERCOM4/PAD[3]
|
||||
SPI1_SDI_PIN = NoPin
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -107,9 +107,9 @@ var (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_MOSI_PIN = PB23 // MOSI: SERCOM1/PAD[3]
|
||||
SPI0_MISO_PIN = PB22 // MISO: SERCOM1/PAD[2]
|
||||
SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_SDO_PIN = PB23 // SDO: SERCOM1/PAD[3]
|
||||
SPI0_SDI_PIN = PB22 // SDI: SERCOM1/PAD[2]
|
||||
)
|
||||
|
||||
// SPI on the PyGamer.
|
||||
@@ -122,9 +122,9 @@ var (
|
||||
|
||||
// TFT SPI pins
|
||||
const (
|
||||
SPI1_SCK_PIN = PB13 // SCK: SERCOM4/PAD[1]
|
||||
SPI1_MOSI_PIN = PB15 // MOSI: SERCOM4/PAD[3]
|
||||
SPI1_MISO_PIN = NoPin
|
||||
SPI1_SCK_PIN = PB13 // SCK: SERCOM4/PAD[1]
|
||||
SPI1_SDO_PIN = PB15 // SDO: SERCOM4/PAD[3]
|
||||
SPI1_SDI_PIN = NoPin
|
||||
)
|
||||
|
||||
// TFT SPI on the PyGamer.
|
||||
|
||||
@@ -26,9 +26,9 @@ const (
|
||||
D26 = PB09 // TFT_WR
|
||||
D27 = PB02 // SDA
|
||||
D28 = PB03 // SCL
|
||||
D29 = PA12 // MOSI
|
||||
D29 = PA12 // SDO
|
||||
D30 = PA13 // SCK
|
||||
D31 = PA14 // MISO
|
||||
D31 = PA14 // SDI
|
||||
D32 = PB30 // SD_CS
|
||||
D33 = PA01 // SD_CARD_DETECT
|
||||
D34 = PA16 // LCD_DATA0
|
||||
@@ -114,13 +114,13 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = PA13 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_MOSI_PIN = PA12 // MOSI: SERCOM1/PAD[3]
|
||||
SPI0_MISO_PIN = PA14 // MISO: SERCOM1/PAD[2]
|
||||
SPI0_SCK_PIN = PA13 // SCK: SERCOM1/PAD[1]
|
||||
SPI0_SDO_PIN = PA12 // SDO: SERCOM1/PAD[3]
|
||||
SPI0_SDI_PIN = PA14 // SDI: SERCOM1/PAD[2]
|
||||
|
||||
NINA_MOSI = SPI0_MOSI_PIN
|
||||
NINA_MISO = SPI0_MISO_PIN
|
||||
NINA_SCK = SPI0_SCK_PIN
|
||||
NINA_SDO = SPI0_SDO_PIN
|
||||
NINA_SDI = SPI0_SDI_PIN
|
||||
NINA_SCK = SPI0_SCK_PIN
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
EPD_DC_PIN Pin = 16
|
||||
EPD_CS_PIN Pin = 17
|
||||
EPD_SCK_PIN Pin = 19
|
||||
EPD_MOSI_PIN Pin = 20
|
||||
EPD_SDO_PIN Pin = 20
|
||||
POWER_SUPPLY_PIN Pin = 32
|
||||
)
|
||||
|
||||
@@ -43,9 +43,9 @@ const (
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_MOSI_PIN Pin = 45
|
||||
SPI0_MISO_PIN Pin = 46
|
||||
SPI0_SCK_PIN Pin = 47
|
||||
SPI0_SDO_PIN Pin = 45
|
||||
SPI0_SDI_PIN Pin = 46
|
||||
)
|
||||
|
||||
// PowerSupplyActive enables the supply voltages for nRF52840 and peripherals (true) or only for nRF52840 (false)
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
// +build bluepill nucleof103rb stm32f4disco
|
||||
// +build bluepill nucleof103rb stm32f4
|
||||
|
||||
package machine
|
||||
|
||||
// Peripheral abstraction layer for the stm32.
|
||||
|
||||
const (
|
||||
portA Pin = iota * 16
|
||||
portB
|
||||
portC
|
||||
portD
|
||||
portE
|
||||
portF
|
||||
portG
|
||||
portH
|
||||
)
|
||||
|
||||
@@ -7,96 +7,6 @@ import (
|
||||
"runtime/interrupt"
|
||||
)
|
||||
|
||||
const (
|
||||
PA0 = portA + 0
|
||||
PA1 = portA + 1
|
||||
PA2 = portA + 2
|
||||
PA3 = portA + 3
|
||||
PA4 = portA + 4
|
||||
PA5 = portA + 5
|
||||
PA6 = portA + 6
|
||||
PA7 = portA + 7
|
||||
PA8 = portA + 8
|
||||
PA9 = portA + 9
|
||||
PA10 = portA + 10
|
||||
PA11 = portA + 11
|
||||
PA12 = portA + 12
|
||||
PA13 = portA + 13
|
||||
PA14 = portA + 14
|
||||
PA15 = portA + 15
|
||||
|
||||
PB0 = portB + 0
|
||||
PB1 = portB + 1
|
||||
PB2 = portB + 2
|
||||
PB3 = portB + 3
|
||||
PB4 = portB + 4
|
||||
PB5 = portB + 5
|
||||
PB6 = portB + 6
|
||||
PB7 = portB + 7
|
||||
PB8 = portB + 8
|
||||
PB9 = portB + 9
|
||||
PB10 = portB + 10
|
||||
PB11 = portB + 11
|
||||
PB12 = portB + 12
|
||||
PB13 = portB + 13
|
||||
PB14 = portB + 14
|
||||
PB15 = portB + 15
|
||||
|
||||
PC0 = portC + 0
|
||||
PC1 = portC + 1
|
||||
PC2 = portC + 2
|
||||
PC3 = portC + 3
|
||||
PC4 = portC + 4
|
||||
PC5 = portC + 5
|
||||
PC6 = portC + 6
|
||||
PC7 = portC + 7
|
||||
PC8 = portC + 8
|
||||
PC9 = portC + 9
|
||||
PC10 = portC + 10
|
||||
PC11 = portC + 11
|
||||
PC12 = portC + 12
|
||||
PC13 = portC + 13
|
||||
PC14 = portC + 14
|
||||
PC15 = portC + 15
|
||||
|
||||
PD0 = portD + 0
|
||||
PD1 = portD + 1
|
||||
PD2 = portD + 2
|
||||
PD3 = portD + 3
|
||||
PD4 = portD + 4
|
||||
PD5 = portD + 5
|
||||
PD6 = portD + 6
|
||||
PD7 = portD + 7
|
||||
PD8 = portD + 8
|
||||
PD9 = portD + 9
|
||||
PD10 = portD + 10
|
||||
PD11 = portD + 11
|
||||
PD12 = portD + 12
|
||||
PD13 = portD + 13
|
||||
PD14 = portD + 14
|
||||
PD15 = portD + 15
|
||||
|
||||
PE0 = portE + 0
|
||||
PE1 = portE + 1
|
||||
PE2 = portE + 2
|
||||
PE3 = portE + 3
|
||||
PE4 = portE + 4
|
||||
PE5 = portE + 5
|
||||
PE6 = portE + 6
|
||||
PE7 = portE + 7
|
||||
PE8 = portE + 8
|
||||
PE9 = portE + 9
|
||||
PE10 = portE + 10
|
||||
PE11 = portE + 11
|
||||
PE12 = portE + 12
|
||||
PE13 = portE + 13
|
||||
PE14 = portE + 14
|
||||
PE15 = portE + 15
|
||||
|
||||
PH0 = portH + 0
|
||||
PH1 = portH + 1
|
||||
)
|
||||
|
||||
const (
|
||||
LED = LED_BUILTIN
|
||||
LED1 = LED_GREEN
|
||||
@@ -132,12 +42,12 @@ func init() {
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI1_SCK_PIN = PA5
|
||||
SPI1_MISO_PIN = PA6
|
||||
SPI1_MOSI_PIN = PA7
|
||||
SPI0_SCK_PIN = SPI1_SCK_PIN
|
||||
SPI0_MISO_PIN = SPI1_MISO_PIN
|
||||
SPI0_MOSI_PIN = SPI1_MOSI_PIN
|
||||
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
|
||||
)
|
||||
|
||||
// MEMs accelerometer
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
// +build nxp,mk66f18,teensy36
|
||||
|
||||
package machine
|
||||
|
||||
// CPUFrequency returns the frequency of the ARM core clock (180MHz)
|
||||
func CPUFrequency() uint32 { return 180000000 }
|
||||
|
||||
// ClockFrequency returns the frequency of the external oscillator (16MHz)
|
||||
func ClockFrequency() uint32 { return 16000000 }
|
||||
|
||||
// LED on the Teensy
|
||||
const LED = PC05
|
||||
|
||||
// digital IO
|
||||
const (
|
||||
D00 = PB16
|
||||
D01 = PB17
|
||||
D02 = PD00
|
||||
D03 = PA12
|
||||
D04 = PA13
|
||||
D05 = PD07
|
||||
D06 = PD04
|
||||
D07 = PD02
|
||||
D08 = PD03
|
||||
D09 = PC03
|
||||
D10 = PC04
|
||||
D11 = PC06
|
||||
D12 = PC07
|
||||
D13 = PC05
|
||||
D14 = PD01
|
||||
D15 = PC00
|
||||
D16 = PB00
|
||||
D17 = PB01
|
||||
D18 = PB03
|
||||
D19 = PB02
|
||||
D20 = PD05
|
||||
D21 = PD06
|
||||
D22 = PC01
|
||||
D23 = PC02
|
||||
D24 = PE26
|
||||
D25 = PA05
|
||||
D26 = PA14
|
||||
D27 = PA15
|
||||
D28 = PA16
|
||||
D29 = PB18
|
||||
D30 = PB19
|
||||
D31 = PB10
|
||||
D32 = PB11
|
||||
D33 = PE24
|
||||
D34 = PE25
|
||||
D35 = PC08
|
||||
D36 = PC09
|
||||
D37 = PC10
|
||||
D38 = PC11
|
||||
D39 = PA17
|
||||
D40 = PA28
|
||||
D41 = PA29
|
||||
D42 = PA26
|
||||
D43 = PB20
|
||||
D44 = PB22
|
||||
D45 = PB23
|
||||
D46 = PB21
|
||||
D47 = PD08
|
||||
D48 = PD09
|
||||
D49 = PB04
|
||||
D50 = PB05
|
||||
D51 = PD14
|
||||
D52 = PD13
|
||||
D53 = PD12
|
||||
D54 = PD15
|
||||
D55 = PD11
|
||||
D56 = PE10
|
||||
D57 = PE11
|
||||
D58 = PE00
|
||||
D59 = PE01
|
||||
D60 = PE02
|
||||
D61 = PE03
|
||||
D62 = PE04
|
||||
D63 = PE05
|
||||
)
|
||||
|
||||
var (
|
||||
TeensyUART1 = &UART0
|
||||
TeensyUART2 = &UART1
|
||||
TeensyUART3 = &UART2
|
||||
TeensyUART4 = &UART3
|
||||
TeensyUART5 = &UART4
|
||||
)
|
||||
|
||||
const (
|
||||
defaultUART0RX = D00
|
||||
defaultUART0TX = D01
|
||||
defaultUART1RX = D09
|
||||
defaultUART1TX = D10
|
||||
defaultUART2RX = D07
|
||||
defaultUART2TX = D08
|
||||
defaultUART3RX = D31
|
||||
defaultUART3TX = D32
|
||||
defaultUART4RX = D34
|
||||
defaultUART4TX = D33
|
||||
)
|
||||
@@ -60,9 +60,9 @@ func init() {
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = D3
|
||||
SPI0_MOSI_PIN = D4
|
||||
SPI0_MISO_PIN = D2
|
||||
SPI0_SCK_PIN = D3
|
||||
SPI0_SDO_PIN = D4
|
||||
SPI0_SDI_PIN = D2
|
||||
)
|
||||
|
||||
// SPI on the Trinket M0.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user