Skip to content

Commit

Permalink
microbit: WIP on getting Microbit to work with TinyGo
Browse files Browse the repository at this point in the history
Signed-off-by: Ron Evans <ron@hybridgroup.com>
  • Loading branch information
deadprogram committed Sep 28, 2018
1 parent 6e9ce73 commit 7e5afe3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
10 changes: 9 additions & 1 deletion Makefile
Expand Up @@ -15,6 +15,11 @@ else ifeq ($(TARGET),pca10040)
OBJCOPY = arm-none-eabi-objcopy
TGOFLAGS += -target $(TARGET)

else ifeq ($(TARGET),microbit)
# BBC:Microbit: nRF51 board
OBJCOPY = arm-none-eabi-objcopy
TGOFLAGS += -target $(TARGET)

else ifeq ($(TARGET),bluepill)
# "blue pill" development board
# See: https://wiki.stm32duino.com/index.php?title=Blue_Pill
Expand All @@ -41,7 +46,10 @@ run-blinky2: build/blinky2

ifeq ($(TARGET),pca10040)
flash-%: build/%.hex
nrfjprog -f nrf52 --sectorerase --program $< --reset
/home/ron/bin/nrfjprog/nrfjprog -f nrf52 --sectorerase --program $< --reset
else ifeq ($(TARGET),microbit)
flash-%: build/%.hex
/home/ron/bin/nrfjprog/nrfjprog -f nrf51 --sectorerase --program $< --reset
else ifeq ($(TARGET),arduino)
flash-%: build/%.hex
avrdude -c arduino -p atmega328p -P /dev/ttyACM0 -U flash:w:$<
Expand Down
40 changes: 40 additions & 0 deletions src/machine/board_microbit.go
@@ -0,0 +1,40 @@
// +build nrf,microbit

package machine

import "device/nrf"

// LEDs on the BBC:Microbit (nRF51 dev board)
const (
LED = LED1
LED1 = 1
)

// Buttons on the BBC:Microbit (nRF51 dev board)
const (
BUTTON = BUTTON1
BUTTON1 = 5
BUTTON2 = 11
)

func SetLEDS(on bool) {
nrf.GPIO.DIRSET = nrf.RegValue(0xfff0)
// v = 0 // All pins to GND so no LED lid
// | MASK_LED_ROW_0
// | MASK_LED_ROW_1
// | MASK_LED_ROW_2
// | MASK_LED_COL_0
// | MASK_LED_COL_1
// | MASK_LED_COL_2
// | MASK_LED_COL_3
// | MASK_LED_COL_4
// | MASK_LED_COL_5
// | MASK_LED_COL_6
// | MASK_LED_COL_7
// | MASK_LED_COL_8
if on {
nrf.GPIO.OUTSET = nrf.RegValue(0xfff0)
} else {
nrf.GPIO.OUTCLR = nrf.RegValue(0xfff0)
}
}
8 changes: 4 additions & 4 deletions src/machine/machine_nrf.go
Expand Up @@ -18,20 +18,20 @@ const (
// Configure this pin with the given configuration.
func (p GPIO) Configure(config GPIOConfig) {
cfg := config.Mode | nrf.GPIO_PIN_CNF_DRIVE_S0S1 | nrf.GPIO_PIN_CNF_SENSE_Disabled
nrf.P0.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
nrf.GPIO.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
}

// Set the pin to high or low.
// Warning: only use this on an output pin!
func (p GPIO) Set(high bool) {
if high {
nrf.P0.OUTSET = 1 << p.Pin
nrf.GPIO.OUTSET = 1 << p.Pin
} else {
nrf.P0.OUTCLR = 1 << p.Pin
nrf.GPIO.OUTCLR = 1 << p.Pin
}
}

// Get returns the current value of a GPIO pin.
func (p GPIO) Get() bool {
return (nrf.P0.IN>>p.Pin)&1 != 0
return (nrf.GPIO.IN>>p.Pin)&1 != 0
}
7 changes: 4 additions & 3 deletions src/runtime/runtime_nrf.go
Expand Up @@ -28,9 +28,10 @@ func init() {

func initUART() {
nrf.UART0.ENABLE = nrf.UART_ENABLE_ENABLE_Enabled
nrf.UART0.BAUDRATE = nrf.UART_BAUDRATE_BAUDRATE_Baud115200
nrf.UART0.BAUDRATE = nrf.UART_BAUDRATE_BAUDRATE_Baud9600
nrf.UART0.TASKS_STARTTX = 1
nrf.UART0.PSELTXD = 6 // pin 6 for NRF52840-DK
nrf.UART0.PSELTXD = 24 // pin 6 for NRF52840-DK
nrf.UART0.PSELRXD = 25 // pin 6 for NRF52840-DK
}

func initLFCLK() {
Expand All @@ -48,10 +49,10 @@ func initRTC() {
}

func putchar(c byte) {
nrf.UART0.EVENTS_TXDRDY = 0
nrf.UART0.TXD = nrf.RegValue(c)
for nrf.UART0.EVENTS_TXDRDY == 0 {
}
nrf.UART0.EVENTS_TXDRDY = 0
}

func sleepTicks(d timeUnit) {
Expand Down
8 changes: 8 additions & 0 deletions targets/microbit.json
@@ -0,0 +1,8 @@
{
"llvm-target": "armv7em-none-eabi",
"build-tags": ["microbit", "nrf51", "nrf", "arm", "js", "wasm"],
"linker": "arm-none-eabi-gcc",
"pre-link-args": ["-nostdlib", "-nostartfiles", "-mcpu=cortex-m4", "-mthumb", "-T", "targets/nrf51.ld", "-Wl,--gc-sections", "-fno-exceptions", "-fno-unwind-tables", "-ffunction-sections", "-fdata-sections", "-Os", "-DNRF51", "-DS110", "-DNRF51_S110", "-Ilib/CMSIS/CMSIS/Include", "lib/nrfx/mdk/system_nrf51.c", "src/device/nrf/nrf51.s"],
"objcopy": "arm-none-eabi-objcopy",
"flash": "nrfjprog -f nrf51 --sectorerase --program {hex} --reset"
}
10 changes: 10 additions & 0 deletions targets/nrf51.ld
@@ -0,0 +1,10 @@

MEMORY
{
FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 256K /* .text */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
}

_stack_size = 2K;

INCLUDE "targets/arm.ld"

0 comments on commit 7e5afe3

Please sign in to comment.