Skip to content

Commit f73d89b

Browse files
committed
Minimal NXP/Teensy support
1 parent aa3481e commit f73d89b

File tree

12 files changed

+754
-8
lines changed

12 files changed

+754
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ src/device/avr/*.ld
55
src/device/avr/*.s
66
src/device/nrf/*.go
77
src/device/nrf/*.s
8+
src/device/nxp/*.go
9+
src/device/nxp/*.s
810
src/device/sam/*.go
911
src/device/sam/*.s
1012
src/device/sifive/*.go

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ else
5151
LLVM_OPTION += '-DLLVM_ENABLE_ASSERTIONS=OFF'
5252
endif
5353

54-
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-avr
54+
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr
5555

5656
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
5757

@@ -118,7 +118,7 @@ fmt-check:
118118
@unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1
119119

120120

121-
gen-device: gen-device-avr gen-device-nrf gen-device-sam gen-device-sifive gen-device-stm32
121+
gen-device: gen-device-avr gen-device-nrf gen-device-nxp gen-device-sam gen-device-sifive gen-device-stm32
122122

123123
gen-device-avr:
124124
$(GO) build -o ./build/gen-device-avr ./tools/gen-device-avr/
@@ -133,6 +133,10 @@ gen-device-nrf: build/gen-device-svd
133133
./build/gen-device-svd -source=https://github.com/NordicSemiconductor/nrfx/tree/master/mdk lib/nrfx/mdk/ src/device/nrf/
134134
GO111MODULE=off $(GO) fmt ./src/device/nrf
135135

136+
gen-device-nxp: build/gen-device-svd
137+
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/NXP lib/cmsis-svd/data/NXP/ src/device/nxp/
138+
GO111MODULE=off $(GO) fmt ./src/device/nxp
139+
136140
gen-device-sam: build/gen-device-svd
137141
./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/Atmel lib/cmsis-svd/data/Atmel/ src/device/sam/
138142
GO111MODULE=off $(GO) fmt ./src/device/sam

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,5 @@ The original reasoning was: if [Python](https://micropython.org/) can run on mic
140140
This project is licensed under the BSD 3-clause license, just like the [Go project](https://golang.org/LICENSE) itself.
141141

142142
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.
143+
144+
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.

src/machine/board_teensy36.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// +build nxp,mk66f18,teensy36
2+
3+
package machine
4+
5+
import (
6+
"device/nxp"
7+
)
8+
9+
//go:keep
10+
//go:section .flashconfig
11+
var FlashConfig = [16]byte{
12+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
13+
0xFF, 0xFF, 0xFF, 0xFF, 0xDE, 0xF9, 0xFF, 0xFF,
14+
}
15+
16+
func CPUFrequency() uint32 {
17+
return 180000000
18+
}
19+
20+
// LED on the Teensy
21+
const LED Pin = 13
22+
23+
var _pinRegisters [64]pinRegisters
24+
25+
func init() {
26+
_pinRegisters[13].Bit = 5
27+
_pinRegisters[13].PCR = &nxp.PORTC.PCR5
28+
_pinRegisters[13].PDOR = nxp.GPIOC.PDOR.Bit(5)
29+
_pinRegisters[13].PSOR = nxp.GPIOC.PSOR.Bit(5)
30+
_pinRegisters[13].PCOR = nxp.GPIOC.PCOR.Bit(5)
31+
_pinRegisters[13].PTOR = nxp.GPIOC.PTOR.Bit(5)
32+
_pinRegisters[13].PDIR = nxp.GPIOC.PDIR.Bit(5)
33+
_pinRegisters[13].PDDR = nxp.GPIOC.PDDR.Bit(5)
34+
}
35+
36+
//go:inline
37+
func (p Pin) registers() pinRegisters {
38+
return _pinRegisters[p]
39+
}

src/machine/machine_nxp.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// +build nxp
2+
3+
package machine
4+
5+
import (
6+
"device/arm"
7+
"device/nxp"
8+
)
9+
10+
type PinMode uint8
11+
12+
const (
13+
PinInput PinMode = iota
14+
PinOutput
15+
)
16+
17+
// Stop enters STOP (deep sleep) mode
18+
func Stop() {
19+
// set SLEEPDEEP to enable deep sleep
20+
nxp.SystemControl.SCR.SetBits(nxp.SystemControl_SCR_SLEEPDEEP)
21+
22+
// enter STOP mode
23+
arm.Asm("wfi")
24+
}
25+
26+
// Wait enters WAIT (sleep) mode
27+
func Wait() {
28+
// clear SLEEPDEEP bit to disable deep sleep
29+
nxp.SystemControl.SCR.ClearBits(nxp.SystemControl_SCR_SLEEPDEEP)
30+
31+
// enter WAIT mode
32+
arm.Asm("wfi")
33+
}

src/machine/machine_nxpmk66f18.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// +build nxp,mk66f18
2+
3+
package machine
4+
5+
import (
6+
"device/nxp"
7+
"runtime/volatile"
8+
)
9+
10+
const (
11+
PortControlRegisterSRE = nxp.PORT_PCR0_SRE
12+
PortControlRegisterDSE = nxp.PORT_PCR0_DSE
13+
PortControlRegisterODE = nxp.PORT_PCR0_ODE
14+
)
15+
16+
func PortControlRegisterMUX(v uint8) uint32 {
17+
return (uint32(v) << nxp.PORT_PCR0_MUX_Pos) & nxp.PORT_PCR0_MUX_Msk
18+
}
19+
20+
type pinRegisters struct {
21+
Bit uintptr
22+
PCR *volatile.Register32
23+
PDOR *volatile.BitRegister
24+
PSOR *volatile.BitRegister
25+
PCOR *volatile.BitRegister
26+
PTOR *volatile.BitRegister
27+
PDIR *volatile.BitRegister
28+
PDDR *volatile.BitRegister
29+
}
30+
31+
// Configure this pin with the given configuration.
32+
func (p Pin) Configure(config PinConfig) {
33+
switch config.Mode {
34+
case PinInput:
35+
panic("todo")
36+
37+
case PinOutput:
38+
p.registers().PDDR.Set()
39+
p.registers().PCR.SetBits(PortControlRegisterSRE | PortControlRegisterDSE | PortControlRegisterMUX(1))
40+
p.registers().PCR.ClearBits(PortControlRegisterODE)
41+
}
42+
}
43+
44+
// Set changes the value of the GPIO pin. The pin must be configured as output.
45+
func (p Pin) Set(value bool) {
46+
if value {
47+
p.registers().PSOR.Set()
48+
} else {
49+
p.registers().PCOR.Set()
50+
}
51+
}
52+
53+
// Get returns the current value of a GPIO pin.
54+
func (p Pin) Get() bool {
55+
return p.registers().PDIR.Get()
56+
}

src/runtime/runtime_nxp.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// +build nxp
2+
3+
package runtime
4+
5+
type timeUnit int64

0 commit comments

Comments
 (0)