Skip to content

Commit 6ec8687

Browse files
committed
machine/microbit-v2: add initial support based on work done by @alankrantas thank you!
Signed-off-by: deadprogram <[email protected]>
1 parent 0866451 commit 6ec8687

File tree

7 files changed

+241
-1
lines changed

7 files changed

+241
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ smoketest:
209209
@$(MD5SUM) test.hex
210210
$(TINYGO) build -size short -o test.hex -target=microbit examples/microbit-blink
211211
@$(MD5SUM) test.hex
212+
$(TINYGO) build -size short -o test.hex -target=microbit-v2 examples/microbit-blink
213+
@$(MD5SUM) test.hex
212214
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/pininterrupt
213215
@$(MD5SUM) test.hex
214216
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/serial

src/machine/board_microbit-v2.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// +build microbit_v2
2+
3+
package machine
4+
5+
// The micro:bit does not have a 32kHz crystal on board.
6+
const HasLowFrequencyCrystal = false
7+
8+
const (
9+
LED = P13
10+
LED1 = LED
11+
)
12+
13+
// Buttons on the micro:bit v2 (A and B)
14+
const (
15+
BUTTON Pin = BUTTONA
16+
BUTTONA Pin = P5
17+
BUTTONB Pin = P11
18+
)
19+
20+
// UART pins
21+
const (
22+
UART_TX_PIN Pin = P34
23+
UART_RX_PIN Pin = P33
24+
)
25+
26+
// ADC pins
27+
const (
28+
ADC0 Pin = P0
29+
ADC1 Pin = P1
30+
ADC2 Pin = P2
31+
)
32+
33+
// I2C0 (internal) pins
34+
const (
35+
SDA_PIN Pin = SDA0_PIN
36+
SCL_PIN Pin = SCL0_PIN
37+
SDA0_PIN Pin = P30
38+
SCL0_PIN Pin = P31
39+
)
40+
41+
// I2C1 (external) pins
42+
const (
43+
SDA1_PIN Pin = P20
44+
SCL1_PIN Pin = P19
45+
)
46+
47+
// SPI pins
48+
const (
49+
SPI0_SCK_PIN Pin = P13
50+
SPI0_SDO_PIN Pin = P15
51+
SPI0_SDI_PIN Pin = P14
52+
)
53+
54+
// GPIO/Analog pins
55+
const (
56+
P0 Pin = 2
57+
P1 Pin = 3
58+
P2 Pin = 4
59+
P3 Pin = 31
60+
P4 Pin = 28
61+
P5 Pin = 14
62+
P6 Pin = 37
63+
P7 Pin = 11
64+
P8 Pin = 10
65+
P9 Pin = 9
66+
P10 Pin = 30
67+
P11 Pin = 23
68+
P12 Pin = 12
69+
P13 Pin = 17
70+
P14 Pin = 1
71+
P15 Pin = 13
72+
P16 Pin = 34
73+
P19 Pin = 26
74+
P20 Pin = 32
75+
P21 Pin = 21
76+
P22 Pin = 22
77+
P23 Pin = 15
78+
P24 Pin = 24
79+
P25 Pin = 19
80+
P26 Pin = 36
81+
P27 Pin = 0
82+
P28 Pin = 20
83+
P29 Pin = 5
84+
P30 Pin = 16
85+
P31 Pin = 8
86+
P32 Pin = 25
87+
P33 Pin = 40
88+
P34 Pin = 6
89+
)
90+
91+
// LED matrix pins
92+
const (
93+
LED_COL_1 Pin = P4
94+
LED_COL_2 Pin = P7
95+
LED_COL_3 Pin = P3
96+
LED_COL_4 Pin = P6
97+
LED_COL_5 Pin = P10
98+
LED_ROW_1 Pin = P21
99+
LED_ROW_2 Pin = P22
100+
LED_ROW_3 Pin = P23
101+
LED_ROW_4 Pin = P24
102+
LED_ROW_5 Pin = P25
103+
)
104+
105+
// USB CDC identifiers
106+
const (
107+
usb_STRING_PRODUCT = "BBC micro:bit V2"
108+
usb_STRING_MANUFACTURER = "BBC"
109+
)
110+
111+
var (
112+
usb_VID uint16 = 0x0d28
113+
usb_PID uint16 = 0x0204
114+
)

src/machine/machine_nrf52833.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// +build nrf52833
2+
3+
package machine
4+
5+
import (
6+
"device/nrf"
7+
)
8+
9+
// Hardware pins
10+
const (
11+
P0_00 Pin = 0
12+
P0_01 Pin = 1
13+
P0_02 Pin = 2
14+
P0_03 Pin = 3
15+
P0_04 Pin = 4
16+
P0_05 Pin = 5
17+
P0_06 Pin = 6
18+
P0_07 Pin = 7
19+
P0_08 Pin = 8
20+
P0_09 Pin = 9
21+
P0_10 Pin = 10
22+
P0_11 Pin = 11
23+
P0_12 Pin = 12
24+
P0_13 Pin = 13
25+
P0_14 Pin = 14
26+
P0_15 Pin = 15
27+
P0_16 Pin = 16
28+
P0_17 Pin = 17
29+
P0_18 Pin = 18
30+
P0_19 Pin = 19
31+
P0_20 Pin = 20
32+
P0_21 Pin = 21
33+
P0_22 Pin = 22
34+
P0_23 Pin = 23
35+
P0_24 Pin = 24
36+
P0_25 Pin = 25
37+
P0_26 Pin = 26
38+
P0_27 Pin = 27
39+
P0_28 Pin = 28
40+
P0_29 Pin = 29
41+
P0_30 Pin = 30
42+
P0_31 Pin = 31
43+
P1_00 Pin = 32
44+
P1_01 Pin = 33
45+
P1_02 Pin = 34
46+
P1_03 Pin = 35
47+
P1_04 Pin = 36
48+
P1_05 Pin = 37
49+
P1_06 Pin = 38
50+
P1_07 Pin = 39
51+
P1_08 Pin = 40
52+
P1_09 Pin = 41
53+
P1_10 Pin = 42
54+
P1_11 Pin = 43
55+
P1_12 Pin = 44
56+
P1_13 Pin = 45
57+
P1_14 Pin = 46
58+
P1_15 Pin = 47
59+
)
60+
61+
var (
62+
UART0 = NRF_UART0
63+
)
64+
65+
// Get peripheral and pin number for this GPIO pin.
66+
func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
67+
if p >= 32 {
68+
return nrf.P1, uint32(p - 32)
69+
} else {
70+
return nrf.P0, uint32(p)
71+
}
72+
}
73+
74+
func (uart UART) setPins(tx, rx Pin) {
75+
nrf.UART0.PSEL.TXD.Set(uint32(tx))
76+
nrf.UART0.PSEL.RXD.Set(uint32(rx))
77+
}
78+
79+
func (i2c I2C) setPins(scl, sda Pin) {
80+
i2c.Bus.PSEL.SCL.Set(uint32(scl))
81+
i2c.Bus.PSEL.SDA.Set(uint32(sda))
82+
}
83+
84+
// PWM
85+
var (
86+
pwmChannelPins = [4]uint32{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}
87+
pwms = [4]*nrf.PWM_Type{nrf.PWM0, nrf.PWM1, nrf.PWM2, nrf.PWM3}
88+
pwmChannelSequence [4]uint16
89+
)

src/machine/machine_nrf528xx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build nrf52 nrf52840
1+
// +build nrf52 nrf52840 nrf52833
22

33
package machine
44

targets/microbit-v2.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"inherits": ["nrf52833"],
3+
"build-tags": ["microbit_v2"],
4+
"flash-method": "msd",
5+
"openocd-interface": "cmsis-dap",
6+
"msd-volume-name": "MICROBIT",
7+
"msd-firmware-name": "firmware.hex"
8+
}

targets/nrf52833.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"inherits": ["cortex-m4"],
3+
"build-tags": ["nrf52833", "nrf"],
4+
"cflags": [
5+
"-Qunused-arguments",
6+
"-DNRF52833_XXAA",
7+
"-I{root}/lib/CMSIS/CMSIS/Include",
8+
"-I{root}/lib/nrfx/mdk"
9+
],
10+
"linkerscript": "targets/nrf52833.ld",
11+
"extra-files": [
12+
"lib/nrfx/mdk/system_nrf52833.c",
13+
"src/device/nrf/nrf52833.s"
14+
],
15+
"openocd-transport": "swd",
16+
"openocd-target": "nrf52"
17+
}

targets/nrf52833.ld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
MEMORY
3+
{
4+
FLASH_TEXT (rw) : ORIGIN = 0x00000000, LENGTH = 0x80000
5+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x20000
6+
}
7+
8+
_stack_size = 4K;
9+
10+
INCLUDE "targets/arm.ld"

0 commit comments

Comments
 (0)