Skip to content

Commit a2b2926

Browse files
committed
targets: WIP on Arduino Uno R4
Signed-off-by: deadprogram <[email protected]>
1 parent 5988be8 commit a2b2926

File tree

6 files changed

+343
-7
lines changed

6 files changed

+343
-7
lines changed

src/machine/board_arduino_unor4.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//go:build arduino_unor4
2+
3+
// This contains the pin mappings for the Arduino Uno R4 board.
4+
//
5+
// For more information, see:
6+
package machine
7+
8+
// GPIO Pins
9+
const (
10+
D0 Pin = P3_01
11+
D1 Pin = P3_02
12+
D2 Pin = P1_04
13+
D3 Pin = P1_05
14+
D4 Pin = P1_06
15+
D5 Pin = P1_07
16+
D6 Pin = P1_11
17+
D7 Pin = P1_12
18+
D8 Pin = P3_04
19+
D9 Pin = P3_03
20+
D10 Pin = P1_03
21+
D11 Pin = P4_11
22+
D12 Pin = P4_10
23+
D13 Pin = P1_02
24+
)
25+
26+
// Analog pins
27+
const (
28+
A0 Pin = P0_14
29+
A1 Pin = P0_00
30+
A2 Pin = P0_01
31+
A3 Pin = P0_02
32+
A4 Pin = P1_01
33+
A5 Pin = P1_00
34+
)
35+
36+
const (
37+
LED = D13
38+
)
39+
40+
41+
// UART1 pins
42+
const (
43+
UART_TX_PIN Pin = P1_09
44+
UART_RX_PIN Pin = P1_10
45+
)
46+
47+
// I2C pins
48+
const (
49+
SDA_PIN Pin = A4
50+
SCL_PIN Pin = A5
51+
)
52+
53+
// { BSP_IO_PORT_03_PIN_01, P301 }, /* (0) D0 ------------------------- DIGITAL */
54+
// { BSP_IO_PORT_03_PIN_02, P302 }, /* (1) D1 */
55+
// { BSP_IO_PORT_01_PIN_04, P104 }, /* (2) D2 */
56+
// { BSP_IO_PORT_01_PIN_05, P105 }, /* (3) D3~ */
57+
// { BSP_IO_PORT_01_PIN_06, P106 }, /* (4) D4 */
58+
// { BSP_IO_PORT_01_PIN_07, P107 }, /* (5) D5~ */
59+
// { BSP_IO_PORT_01_PIN_11, P111 }, /* (6) D6~ */
60+
// { BSP_IO_PORT_01_PIN_12, P112 }, /* (7) D7 */
61+
// { BSP_IO_PORT_03_PIN_04, P304 }, /* (8) D8 */
62+
// { BSP_IO_PORT_03_PIN_03, P303 }, /* (9) D9~ */
63+
// { BSP_IO_PORT_01_PIN_03, P103 }, /* (10) D10~ */
64+
// { BSP_IO_PORT_04_PIN_11, P411 }, /* (11) D11~ */
65+
// { BSP_IO_PORT_04_PIN_10, P410 }, /* (12) D12 */
66+
// { BSP_IO_PORT_01_PIN_02, P102 }, /* (13) D13 */
67+
// { BSP_IO_PORT_00_PIN_14, P014 }, /* (14) A0 -------------------------- ANALOG */
68+
// { BSP_IO_PORT_00_PIN_00, P000 }, /* (15) A1 */
69+
// { BSP_IO_PORT_00_PIN_01, P001 }, /* (16) A2 */
70+
// { BSP_IO_PORT_00_PIN_02, P002 }, /* (17) A3 */
71+
// { BSP_IO_PORT_01_PIN_01, P101 }, /* (18) A4/SDA */
72+
// { BSP_IO_PORT_01_PIN_00, P100 }, /* (19) A5/SCL */
73+
74+
// { BSP_IO_PORT_05_PIN_00, P500 }, /* (20) Analog voltage measure pin */
75+
// { BSP_IO_PORT_04_PIN_08, P408 }, /* (21) USB switch, drive high for RA4 */
76+
77+
// { BSP_IO_PORT_01_PIN_09, P109 }, /* (22) D22 ------------------------ TX */
78+
// { BSP_IO_PORT_01_PIN_10, P110 }, /* (23) D23 ------------------------ RX */
79+
// { BSP_IO_PORT_05_PIN_01, P501 }, /* (24) D24 ------------------------- TX WIFI */
80+
// { BSP_IO_PORT_05_PIN_02, P502 }, /* (25) D25 ------------------------- RX WIFI */
81+
82+
// { BSP_IO_PORT_04_PIN_00, P400 }, /* (26) D26 QWIC SCL */
83+
// { BSP_IO_PORT_04_PIN_01, P401 }, /* (27) D27 QWIC SDA */
84+
85+
// { BSP_IO_PORT_00_PIN_03, P003 }, /* (28) D28 */
86+
// { BSP_IO_PORT_00_PIN_04, P004 }, /* (29) D29 */
87+
// { BSP_IO_PORT_00_PIN_11, P011 }, /* (30) D30 */
88+
// { BSP_IO_PORT_00_PIN_12, P012 }, /* (31) D31 */
89+
// { BSP_IO_PORT_00_PIN_13, P013 }, /* (32) D32 */
90+
// { BSP_IO_PORT_00_PIN_15, P015 }, /* (33) D33 */
91+
// { BSP_IO_PORT_02_PIN_04, P204 }, /* (34) D34 */
92+
// { BSP_IO_PORT_02_PIN_05, P205 }, /* (35) D35 */
93+
// { BSP_IO_PORT_02_PIN_06, P206 }, /* (36) D36 */
94+
// { BSP_IO_PORT_02_PIN_12, P212 }, /* (37) D37 */
95+
// { BSP_IO_PORT_02_PIN_13, P213 }, /* (38) D38 */

src/machine/machine_ra4m1.go

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
//go:build ra4m1
2+
3+
package machine
4+
5+
import (
6+
"device/renesas"
7+
"runtime/volatile"
8+
"unsafe"
9+
)
10+
11+
const deviceName = renesas.Device
12+
13+
const (
14+
P0_00 Pin = 0
15+
P0_01 Pin = 1
16+
P0_02 Pin = 2
17+
P0_03 Pin = 3
18+
P0_04 Pin = 4
19+
P0_05 Pin = 5
20+
P0_06 Pin = 6
21+
P0_07 Pin = 7
22+
P0_08 Pin = 8
23+
P0_09 Pin = 9
24+
P0_10 Pin = 10
25+
P0_11 Pin = 11
26+
P0_12 Pin = 12
27+
P0_13 Pin = 13
28+
P0_14 Pin = 14
29+
P0_15 Pin = 15
30+
P1_00 Pin = 16
31+
P1_01 Pin = 17
32+
P1_02 Pin = 18
33+
P1_03 Pin = 19
34+
P1_04 Pin = 20
35+
P1_05 Pin = 21
36+
P1_06 Pin = 22
37+
P1_07 Pin = 23
38+
P1_08 Pin = 24
39+
P1_09 Pin = 25
40+
P1_10 Pin = 26
41+
P1_11 Pin = 27
42+
P1_12 Pin = 28
43+
P1_13 Pin = 29
44+
P1_14 Pin = 30
45+
P1_15 Pin = 31
46+
P2_00 Pin = 32
47+
P2_01 Pin = 33
48+
P2_02 Pin = 34
49+
P2_03 Pin = 35
50+
P2_04 Pin = 36
51+
P2_05 Pin = 37
52+
P2_06 Pin = 38
53+
P2_07 Pin = 39
54+
P2_08 Pin = 40
55+
P2_09 Pin = 41
56+
P2_10 Pin = 42
57+
P2_11 Pin = 43
58+
P2_12 Pin = 44
59+
P2_13 Pin = 45
60+
P2_14 Pin = 46
61+
P2_15 Pin = 47
62+
P3_00 Pin = 48
63+
P3_01 Pin = 49
64+
P3_02 Pin = 50
65+
P3_03 Pin = 51
66+
P3_04 Pin = 52
67+
P3_05 Pin = 53
68+
P3_06 Pin = 54
69+
P3_07 Pin = 55
70+
P3_08 Pin = 56
71+
P3_09 Pin = 57
72+
P3_10 Pin = 58
73+
P3_11 Pin = 59
74+
P3_12 Pin = 60
75+
P3_13 Pin = 61
76+
P3_14 Pin = 62
77+
P3_15 Pin = 63
78+
P4_00 Pin = 64
79+
P4_01 Pin = 65
80+
P4_02 Pin = 66
81+
P4_03 Pin = 67
82+
P4_04 Pin = 68
83+
P4_05 Pin = 69
84+
P4_06 Pin = 70
85+
P4_07 Pin = 71
86+
P4_08 Pin = 72
87+
P4_09 Pin = 73
88+
P4_10 Pin = 74
89+
P4_11 Pin = 75
90+
P4_12 Pin = 76
91+
P4_13 Pin = 77
92+
P4_14 Pin = 78
93+
P4_15 Pin = 79
94+
P5_00 Pin = 80
95+
P5_01 Pin = 81
96+
P5_02 Pin = 82
97+
P5_03 Pin = 83
98+
P5_04 Pin = 84
99+
P5_05 Pin = 85
100+
P5_06 Pin = 86
101+
P5_07 Pin = 87
102+
P5_08 Pin = 88
103+
P5_09 Pin = 89
104+
P5_10 Pin = 90
105+
P5_11 Pin = 91
106+
P5_12 Pin = 92
107+
P5_13 Pin = 93
108+
P5_14 Pin = 94
109+
P5_15 Pin = 95
110+
)
111+
112+
const (
113+
PinOutput PinMode = iota
114+
PinInput
115+
PinInputPullUp
116+
PinInputPullDown
117+
)
118+
119+
// Configure configures the gpio pin as per mode.
120+
func (p Pin) Configure(config PinConfig) {
121+
if p == NoPin {
122+
return
123+
}
124+
125+
enableWritingPmnPFS()
126+
127+
switch config.Mode {
128+
case PinOutput:
129+
setPDR(p, renesas.PFS_P000PFS_PDR_1)
130+
default:
131+
setPDR(p, renesas.PFS_P000PFS_PDR_0)
132+
}
133+
134+
disableWritingPmnPFS()
135+
}
136+
137+
// Set drives the pin high if value is true else drives it low.
138+
func (p Pin) Set(value bool) {
139+
if p == NoPin {
140+
return
141+
}
142+
143+
port := getPort(p)
144+
if port == nil {
145+
return
146+
}
147+
148+
if value == true {
149+
port.set(p)
150+
} else {
151+
port.clr(p)
152+
}
153+
}
154+
155+
// Get reads the pin value.
156+
func (p Pin) Get() bool {
157+
return false
158+
}
159+
160+
var (
161+
gpioPort0 = gpioPortType0{renesas.PORT0}
162+
gpioPort1 = gpioPortType1{renesas.PORT1}
163+
gpioPort2 = gpioPortType1{renesas.PORT2}
164+
gpioPort3 = gpioPortType1{renesas.PORT3}
165+
gpioPort4 = gpioPortType1{renesas.PORT4}
166+
gpioPort5 = gpioPortType0{renesas.PORT5}
167+
)
168+
169+
func getPort(p Pin) gpioPort {
170+
switch getPortNumber(p) {
171+
case 0:
172+
return gpioPort0
173+
case 1:
174+
return gpioPort1
175+
case 2:
176+
return gpioPort2
177+
case 3:
178+
return gpioPort3
179+
case 4:
180+
return gpioPort4
181+
case 5:
182+
return gpioPort5
183+
default:
184+
return nil
185+
}
186+
}
187+
188+
func getPortNumber(p Pin) int {
189+
return int(p) >> 8
190+
}
191+
192+
type gpioPort interface {
193+
set(p Pin)
194+
clr(p Pin)
195+
}
196+
197+
type gpioPortType0 struct {
198+
port *renesas.PORT0_Type
199+
}
200+
201+
func (p gpioPortType0) set(pin Pin) {
202+
p.port.SetPCNTR3_PORR(1 << pin)
203+
}
204+
205+
func (p gpioPortType0) clr(pin Pin) {
206+
p.port.SetPCNTR3_POSR(1 << pin)
207+
}
208+
209+
type gpioPortType1 struct {
210+
port *renesas.PORT1_Type
211+
}
212+
213+
func (p gpioPortType1) set(pin Pin) {
214+
p.port.SetPCNTR3_PORR(1 << pin)
215+
}
216+
217+
func (p gpioPortType1) clr(pin Pin) {
218+
p.port.SetPCNTR3_POSR(1 << pin)
219+
}
220+
221+
func enableWritingPmnPFS() {
222+
renesas.PMISC.PWPR.Set(0x0)
223+
renesas.PMISC.SetPWPR_PFSWE(0x1)
224+
}
225+
226+
func disableWritingPmnPFS() {
227+
renesas.PMISC.PWPR.Set(0x0)
228+
renesas.PMISC.SetPWPR_B0WI(0x1)
229+
}
230+
231+
func setPDR(p Pin, value uint32) {
232+
port := getPortNumber(p)
233+
bit := int(p) & 0xff
234+
reg := (*volatile.Register32)(unsafe.Add(unsafe.Pointer(uintptr(0x40040800)), 0x40*port+4*bit))
235+
reg.SetBits(value << renesas.PFS_P000PFS_PDR_Pos)
236+
}

src/runtime/runtime_ra4m1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build renasas
1+
//go:build ra4m1
22

33
package runtime
44

targets/arduino-unor4.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"inherits": ["ra4m1"],
3+
"build-tags": ["arduino_unor4"],
4+
"flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x4000 {bin}",
5+
"serial-port": ["2341:8057", "2341:0057"],
6+
"flash-1200-bps-reset": "true"
7+
}

targets/ra4m1.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"inherits": ["cortex-m4"],
3-
"build-tags": ["ra4m1", "renesas"],
3+
"build-tags": ["ra4m1", "r7fa4m1ab", "renesas"],
44
"linkerscript": "targets/ra4m1.ld",
55
"extra-files": [
6-
"src/device/renesas/r7fa4m2ad.s"
7-
],
8-
"openocd-transport": "swd",
9-
"openocd-target": "atsame5x"
6+
"src/device/renesas/r7fa4m1ab.s"
7+
]
108
}

targets/ra4m1.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
MEMORY
33
{
44
FLASH_TEXT (rw) : ORIGIN = 0x00000000+0x4000, LENGTH = 0x00080000-0x4000 /* First 16KB used by bootloader */
5-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00030000
5+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00040000
66
}
77

88
_stack_size = 4K;

0 commit comments

Comments
 (0)