With the help of Chillance on GitHub.
Этот коммит содержится в:
Ayke van Laethem 2018-10-06 13:53:58 +02:00
родитель f9edf7cc5c
коммит daf92226d8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED
8 изменённых файлов: 121 добавлений и 11 удалений

Просмотреть файл

@ -24,5 +24,6 @@ script:
- tinygo build -o blinky2 examples/blinky2 - tinygo build -o blinky2 examples/blinky2
- tinygo build -o test.nrf.elf -target=pca10040 examples/test - tinygo build -o test.nrf.elf -target=pca10040 examples/test
- tinygo build -o blinky1.nrf51.elf -target=microbit examples/echo - tinygo build -o blinky1.nrf51.elf -target=microbit examples/echo
- tinygo build -o test.nrf.elf -target=nrf52840-mdk examples/blinky1
- tinygo build -o blinky1.stm32.elf -target=bluepill examples/blinky1 - tinygo build -o blinky1.stm32.elf -target=bluepill examples/blinky1
- tinygo build -o blinky1.avr.o -target=arduino examples/blinky1 # TODO: avr-as/avr-gcc doesn't work - tinygo build -o blinky1.avr.o -target=arduino examples/blinky1 # TODO: avr-as/avr-gcc doesn't work

25
src/machine/board_nrf52840-mdk.go Обычный файл
Просмотреть файл

@ -0,0 +1,25 @@
// +build nrf52840_mdk
package machine
const HasLowFrequencyCrystal = true
// LEDs on the nrf52840-mdk (nRF52840 dev board)
const (
LED = LED_GREEN
LED_GREEN = 22
LED_RED = 23
LED_BLUE = 24
)
// UART pins
const (
UART_TX_PIN = 20
UART_RX_PIN = 19
)
// I2C pins (unused)
const (
SDA_PIN = 0xff
SCL_PIN = 0xff
)

Просмотреть файл

@ -70,8 +70,7 @@ func (uart UART) Configure(config UARTConfig) {
uart.SetBaudRate(config.BaudRate) uart.SetBaudRate(config.BaudRate)
// Set TX and RX pins from board. // Set TX and RX pins from board.
nrf.UART0.PSELTXD = UART_TX_PIN uart.setPins(UART_TX_PIN, UART_RX_PIN)
nrf.UART0.PSELRXD = UART_RX_PIN
nrf.UART0.ENABLE = nrf.UART_ENABLE_ENABLE_Enabled nrf.UART0.ENABLE = nrf.UART_ENABLE_ENABLE_Enabled
nrf.UART0.TASKS_STARTTX = 1 nrf.UART0.TASKS_STARTTX = 1
@ -165,8 +164,7 @@ func (i2c I2C) Configure(config I2CConfig) {
} }
i2c.Bus.ENABLE = nrf.TWI_ENABLE_ENABLE_Enabled i2c.Bus.ENABLE = nrf.TWI_ENABLE_ENABLE_Enabled
i2c.Bus.PSELSCL = nrf.RegValue(config.SCL) i2c.setPins(config.SCL, config.SDA)
i2c.Bus.PSELSDA = nrf.RegValue(config.SDA)
} }
// WriteTo writes a slice of data bytes to a peripheral with a specific address. // WriteTo writes a slice of data bytes to a peripheral with a specific address.

Просмотреть файл

@ -11,7 +11,17 @@ func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
return nrf.GPIO, p.Pin return nrf.GPIO, p.Pin
} }
func (uart UART) setPins(tx, rx uint32) {
nrf.UART0.PSELTXD = nrf.RegValue(tx)
nrf.UART0.PSELRXD = nrf.RegValue(rx)
}
//go:export UART0_IRQHandler //go:export UART0_IRQHandler
func handleUART0() { func handleUART0() {
UART0.handleInterrupt() UART0.handleInterrupt()
} }
func (i2c I2C) setPins(scl, sda uint8) {
i2c.Bus.PSELSCL = nrf.RegValue(scl)
i2c.Bus.PSELSDA = nrf.RegValue(sda)
}

Просмотреть файл

@ -12,11 +12,21 @@ func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
return nrf.P0, p.Pin return nrf.P0, p.Pin
} }
func (uart UART) setPins(tx, rx uint32) {
nrf.UART0.PSELTXD = nrf.RegValue(tx)
nrf.UART0.PSELRXD = nrf.RegValue(rx)
}
//go:export UARTE0_UART0_IRQHandler //go:export UARTE0_UART0_IRQHandler
func handleUART0() { func handleUART0() {
UART0.handleInterrupt() UART0.handleInterrupt()
} }
func (i2c I2C) setPins(scl, sda uint8) {
i2c.Bus.PSELSCL = nrf.RegValue(scl)
i2c.Bus.PSELSDA = nrf.RegValue(sda)
}
// InitADC initializes the registers needed for ADC. // InitADC initializes the registers needed for ADC.
func InitADC() { func InitADC() {
return // no specific setup on nrf52 machine. return // no specific setup on nrf52 machine.

31
src/machine/machine_nrf52840.go Обычный файл
Просмотреть файл

@ -0,0 +1,31 @@
// +build nrf52840
package machine
import (
"device/nrf"
)
// Get peripheral and pin number for this GPIO pin.
func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
if p.Pin >= 32 {
return nrf.P1, p.Pin - 32
} else {
return nrf.P0, p.Pin
}
}
func (uart UART) setPins(tx, rx uint32) {
nrf.UART0.PSEL.TXD = nrf.RegValue(tx)
nrf.UART0.PSEL.RXD = nrf.RegValue(rx)
}
//go:export UARTE0_UART0_IRQHandler
func handleUART0() {
UART0.handleInterrupt()
}
func (i2c I2C) setPins(scl, sda uint8) {
i2c.Bus.PSEL.SCL = nrf.RegValue(scl)
i2c.Bus.PSEL.SDA = nrf.RegValue(sda)
}

25
targets/nrf52840-mdk.json Обычный файл
Просмотреть файл

@ -0,0 +1,25 @@
{
"llvm-target": "armv7em-none-eabi",
"build-tags": ["nrf52840_mdk", "nrf52840", "nrf", "arm", "js", "wasm"],
"linker": "arm-none-eabi-gcc",
"pre-link-args": [
"-nostdlib",
"-nostartfiles",
"-mcpu=cortex-m4",
"-mthumb",
"-T", "targets/nrf52840.ld",
"-Wl,--gc-sections",
"-fno-exceptions", "-fno-unwind-tables",
"-ffunction-sections", "-fdata-sections",
"-Os",
"-DNRF52840_XXAA",
"-Ilib/CMSIS/CMSIS/Include",
"lib/nrfx/mdk/system_nrf52840.c",
"src/device/nrf/nrf52840.s"
],
"objcopy": "arm-none-eabi-objcopy",
"flash": "openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg -c 'program {hex} reset exit'",
"ocd-daemon": ["openocd", "-f", "interface/cmsis-dap.cfg", "-f", "target/nrf51.cfg"],
"gdb": "arm-none-eabi-gdb",
"gdb-initial-cmds": ["target remote :3333", "monitor halt", "load", "monitor reset", "c"]
}

10
targets/nrf52840.ld Обычный файл
Просмотреть файл

@ -0,0 +1,10 @@
MEMORY
{
FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 1M
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
}
_stack_size = 4K;
INCLUDE "targets/arm.ld"