diff --git a/Makefile b/Makefile index 3e334245..3ea259fe 100644 --- a/Makefile +++ b/Makefile @@ -209,6 +209,8 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=microbit examples/microbit-blink @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=microbit-v2 examples/microbit-blink + @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=pca10040 examples/pininterrupt @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=pca10040 examples/serial diff --git a/src/machine/board_microbit-v2.go b/src/machine/board_microbit-v2.go new file mode 100644 index 00000000..60be7d75 --- /dev/null +++ b/src/machine/board_microbit-v2.go @@ -0,0 +1,114 @@ +// +build microbit_v2 + +package machine + +// The micro:bit does not have a 32kHz crystal on board. +const HasLowFrequencyCrystal = false + +const ( + LED = P13 + LED1 = LED +) + +// Buttons on the micro:bit v2 (A and B) +const ( + BUTTON Pin = BUTTONA + BUTTONA Pin = P5 + BUTTONB Pin = P11 +) + +// UART pins +const ( + UART_TX_PIN Pin = P34 + UART_RX_PIN Pin = P33 +) + +// ADC pins +const ( + ADC0 Pin = P0 + ADC1 Pin = P1 + ADC2 Pin = P2 +) + +// I2C0 (internal) pins +const ( + SDA_PIN Pin = SDA0_PIN + SCL_PIN Pin = SCL0_PIN + SDA0_PIN Pin = P30 + SCL0_PIN Pin = P31 +) + +// I2C1 (external) pins +const ( + SDA1_PIN Pin = P20 + SCL1_PIN Pin = P19 +) + +// SPI pins +const ( + SPI0_SCK_PIN Pin = P13 + SPI0_SDO_PIN Pin = P15 + SPI0_SDI_PIN Pin = P14 +) + +// GPIO/Analog pins +const ( + P0 Pin = 2 + P1 Pin = 3 + P2 Pin = 4 + P3 Pin = 31 + P4 Pin = 28 + P5 Pin = 14 + P6 Pin = 37 + P7 Pin = 11 + P8 Pin = 10 + P9 Pin = 9 + P10 Pin = 30 + P11 Pin = 23 + P12 Pin = 12 + P13 Pin = 17 + P14 Pin = 1 + P15 Pin = 13 + P16 Pin = 34 + P19 Pin = 26 + P20 Pin = 32 + P21 Pin = 21 + P22 Pin = 22 + P23 Pin = 15 + P24 Pin = 24 + P25 Pin = 19 + P26 Pin = 36 + P27 Pin = 0 + P28 Pin = 20 + P29 Pin = 5 + P30 Pin = 16 + P31 Pin = 8 + P32 Pin = 25 + P33 Pin = 40 + P34 Pin = 6 +) + +// LED matrix pins +const ( + LED_COL_1 Pin = P4 + LED_COL_2 Pin = P7 + LED_COL_3 Pin = P3 + LED_COL_4 Pin = P6 + LED_COL_5 Pin = P10 + LED_ROW_1 Pin = P21 + LED_ROW_2 Pin = P22 + LED_ROW_3 Pin = P23 + LED_ROW_4 Pin = P24 + LED_ROW_5 Pin = P25 +) + +// USB CDC identifiers +const ( + usb_STRING_PRODUCT = "BBC micro:bit V2" + usb_STRING_MANUFACTURER = "BBC" +) + +var ( + usb_VID uint16 = 0x0d28 + usb_PID uint16 = 0x0204 +) diff --git a/src/machine/machine_nrf52833.go b/src/machine/machine_nrf52833.go new file mode 100644 index 00000000..cb124ffe --- /dev/null +++ b/src/machine/machine_nrf52833.go @@ -0,0 +1,89 @@ +// +build nrf52833 + +package machine + +import ( + "device/nrf" +) + +// Hardware pins +const ( + P0_00 Pin = 0 + P0_01 Pin = 1 + P0_02 Pin = 2 + P0_03 Pin = 3 + P0_04 Pin = 4 + P0_05 Pin = 5 + P0_06 Pin = 6 + P0_07 Pin = 7 + P0_08 Pin = 8 + P0_09 Pin = 9 + P0_10 Pin = 10 + P0_11 Pin = 11 + P0_12 Pin = 12 + P0_13 Pin = 13 + P0_14 Pin = 14 + P0_15 Pin = 15 + P0_16 Pin = 16 + P0_17 Pin = 17 + P0_18 Pin = 18 + P0_19 Pin = 19 + P0_20 Pin = 20 + P0_21 Pin = 21 + P0_22 Pin = 22 + P0_23 Pin = 23 + P0_24 Pin = 24 + P0_25 Pin = 25 + P0_26 Pin = 26 + P0_27 Pin = 27 + P0_28 Pin = 28 + P0_29 Pin = 29 + P0_30 Pin = 30 + P0_31 Pin = 31 + P1_00 Pin = 32 + P1_01 Pin = 33 + P1_02 Pin = 34 + P1_03 Pin = 35 + P1_04 Pin = 36 + P1_05 Pin = 37 + P1_06 Pin = 38 + P1_07 Pin = 39 + P1_08 Pin = 40 + P1_09 Pin = 41 + P1_10 Pin = 42 + P1_11 Pin = 43 + P1_12 Pin = 44 + P1_13 Pin = 45 + P1_14 Pin = 46 + P1_15 Pin = 47 +) + +var ( + UART0 = NRF_UART0 +) + +// Get peripheral and pin number for this GPIO pin. +func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) { + if p >= 32 { + return nrf.P1, uint32(p - 32) + } else { + return nrf.P0, uint32(p) + } +} + +func (uart UART) setPins(tx, rx Pin) { + nrf.UART0.PSEL.TXD.Set(uint32(tx)) + nrf.UART0.PSEL.RXD.Set(uint32(rx)) +} + +func (i2c I2C) setPins(scl, sda Pin) { + i2c.Bus.PSEL.SCL.Set(uint32(scl)) + i2c.Bus.PSEL.SDA.Set(uint32(sda)) +} + +// PWM +var ( + pwmChannelPins = [4]uint32{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF} + pwms = [4]*nrf.PWM_Type{nrf.PWM0, nrf.PWM1, nrf.PWM2, nrf.PWM3} + pwmChannelSequence [4]uint16 +) diff --git a/src/machine/machine_nrf528xx.go b/src/machine/machine_nrf528xx.go index 76409522..f4a825ae 100644 --- a/src/machine/machine_nrf528xx.go +++ b/src/machine/machine_nrf528xx.go @@ -1,4 +1,4 @@ -// +build nrf52 nrf52840 +// +build nrf52 nrf52840 nrf52833 package machine diff --git a/targets/microbit-v2.json b/targets/microbit-v2.json new file mode 100644 index 00000000..33a9392e --- /dev/null +++ b/targets/microbit-v2.json @@ -0,0 +1,8 @@ +{ + "inherits": ["nrf52833"], + "build-tags": ["microbit_v2"], + "flash-method": "msd", + "openocd-interface": "cmsis-dap", + "msd-volume-name": "MICROBIT", + "msd-firmware-name": "firmware.hex" +} diff --git a/targets/nrf52833.json b/targets/nrf52833.json new file mode 100644 index 00000000..a1c88a6f --- /dev/null +++ b/targets/nrf52833.json @@ -0,0 +1,17 @@ +{ + "inherits": ["cortex-m4"], + "build-tags": ["nrf52833", "nrf"], + "cflags": [ + "-Qunused-arguments", + "-DNRF52833_XXAA", + "-I{root}/lib/CMSIS/CMSIS/Include", + "-I{root}/lib/nrfx/mdk" + ], + "linkerscript": "targets/nrf52833.ld", + "extra-files": [ + "lib/nrfx/mdk/system_nrf52833.c", + "src/device/nrf/nrf52833.s" + ], + "openocd-transport": "swd", + "openocd-target": "nrf52" +} diff --git a/targets/nrf52833.ld b/targets/nrf52833.ld new file mode 100644 index 00000000..99cfc119 --- /dev/null +++ b/targets/nrf52833.ld @@ -0,0 +1,10 @@ + +MEMORY +{ + FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 0x80000 + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x20000 +} + +_stack_size = 4K; + +INCLUDE "targets/arm.ld"