mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 14:48:40 +00:00
Compare commits
3 Commits
dev
...
renesas-repo
| Author | SHA1 | Date | |
|---|---|---|---|
| a2b2926d4f | |||
| 5988be8790 | |||
| 61af20bdb9 |
@@ -0,0 +1,95 @@
|
||||
//go:build arduino_unor4
|
||||
|
||||
// This contains the pin mappings for the Arduino Uno R4 board.
|
||||
//
|
||||
// For more information, see:
|
||||
package machine
|
||||
|
||||
// GPIO Pins
|
||||
const (
|
||||
D0 Pin = P3_01
|
||||
D1 Pin = P3_02
|
||||
D2 Pin = P1_04
|
||||
D3 Pin = P1_05
|
||||
D4 Pin = P1_06
|
||||
D5 Pin = P1_07
|
||||
D6 Pin = P1_11
|
||||
D7 Pin = P1_12
|
||||
D8 Pin = P3_04
|
||||
D9 Pin = P3_03
|
||||
D10 Pin = P1_03
|
||||
D11 Pin = P4_11
|
||||
D12 Pin = P4_10
|
||||
D13 Pin = P1_02
|
||||
)
|
||||
|
||||
// Analog pins
|
||||
const (
|
||||
A0 Pin = P0_14
|
||||
A1 Pin = P0_00
|
||||
A2 Pin = P0_01
|
||||
A3 Pin = P0_02
|
||||
A4 Pin = P1_01
|
||||
A5 Pin = P1_00
|
||||
)
|
||||
|
||||
const (
|
||||
LED = D13
|
||||
)
|
||||
|
||||
|
||||
// UART1 pins
|
||||
const (
|
||||
UART_TX_PIN Pin = P1_09
|
||||
UART_RX_PIN Pin = P1_10
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
const (
|
||||
SDA_PIN Pin = A4
|
||||
SCL_PIN Pin = A5
|
||||
)
|
||||
|
||||
// { BSP_IO_PORT_03_PIN_01, P301 }, /* (0) D0 ------------------------- DIGITAL */
|
||||
// { BSP_IO_PORT_03_PIN_02, P302 }, /* (1) D1 */
|
||||
// { BSP_IO_PORT_01_PIN_04, P104 }, /* (2) D2 */
|
||||
// { BSP_IO_PORT_01_PIN_05, P105 }, /* (3) D3~ */
|
||||
// { BSP_IO_PORT_01_PIN_06, P106 }, /* (4) D4 */
|
||||
// { BSP_IO_PORT_01_PIN_07, P107 }, /* (5) D5~ */
|
||||
// { BSP_IO_PORT_01_PIN_11, P111 }, /* (6) D6~ */
|
||||
// { BSP_IO_PORT_01_PIN_12, P112 }, /* (7) D7 */
|
||||
// { BSP_IO_PORT_03_PIN_04, P304 }, /* (8) D8 */
|
||||
// { BSP_IO_PORT_03_PIN_03, P303 }, /* (9) D9~ */
|
||||
// { BSP_IO_PORT_01_PIN_03, P103 }, /* (10) D10~ */
|
||||
// { BSP_IO_PORT_04_PIN_11, P411 }, /* (11) D11~ */
|
||||
// { BSP_IO_PORT_04_PIN_10, P410 }, /* (12) D12 */
|
||||
// { BSP_IO_PORT_01_PIN_02, P102 }, /* (13) D13 */
|
||||
// { BSP_IO_PORT_00_PIN_14, P014 }, /* (14) A0 -------------------------- ANALOG */
|
||||
// { BSP_IO_PORT_00_PIN_00, P000 }, /* (15) A1 */
|
||||
// { BSP_IO_PORT_00_PIN_01, P001 }, /* (16) A2 */
|
||||
// { BSP_IO_PORT_00_PIN_02, P002 }, /* (17) A3 */
|
||||
// { BSP_IO_PORT_01_PIN_01, P101 }, /* (18) A4/SDA */
|
||||
// { BSP_IO_PORT_01_PIN_00, P100 }, /* (19) A5/SCL */
|
||||
|
||||
// { BSP_IO_PORT_05_PIN_00, P500 }, /* (20) Analog voltage measure pin */
|
||||
// { BSP_IO_PORT_04_PIN_08, P408 }, /* (21) USB switch, drive high for RA4 */
|
||||
|
||||
// { BSP_IO_PORT_01_PIN_09, P109 }, /* (22) D22 ------------------------ TX */
|
||||
// { BSP_IO_PORT_01_PIN_10, P110 }, /* (23) D23 ------------------------ RX */
|
||||
// { BSP_IO_PORT_05_PIN_01, P501 }, /* (24) D24 ------------------------- TX WIFI */
|
||||
// { BSP_IO_PORT_05_PIN_02, P502 }, /* (25) D25 ------------------------- RX WIFI */
|
||||
|
||||
// { BSP_IO_PORT_04_PIN_00, P400 }, /* (26) D26 QWIC SCL */
|
||||
// { BSP_IO_PORT_04_PIN_01, P401 }, /* (27) D27 QWIC SDA */
|
||||
|
||||
// { BSP_IO_PORT_00_PIN_03, P003 }, /* (28) D28 */
|
||||
// { BSP_IO_PORT_00_PIN_04, P004 }, /* (29) D29 */
|
||||
// { BSP_IO_PORT_00_PIN_11, P011 }, /* (30) D30 */
|
||||
// { BSP_IO_PORT_00_PIN_12, P012 }, /* (31) D31 */
|
||||
// { BSP_IO_PORT_00_PIN_13, P013 }, /* (32) D32 */
|
||||
// { BSP_IO_PORT_00_PIN_15, P015 }, /* (33) D33 */
|
||||
// { BSP_IO_PORT_02_PIN_04, P204 }, /* (34) D34 */
|
||||
// { BSP_IO_PORT_02_PIN_05, P205 }, /* (35) D35 */
|
||||
// { BSP_IO_PORT_02_PIN_06, P206 }, /* (36) D36 */
|
||||
// { BSP_IO_PORT_02_PIN_12, P212 }, /* (37) D37 */
|
||||
// { BSP_IO_PORT_02_PIN_13, P213 }, /* (38) D38 */
|
||||
@@ -0,0 +1,236 @@
|
||||
//go:build ra4m1
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/renesas"
|
||||
"runtime/volatile"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const deviceName = renesas.Device
|
||||
|
||||
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
|
||||
P1_00 Pin = 16
|
||||
P1_01 Pin = 17
|
||||
P1_02 Pin = 18
|
||||
P1_03 Pin = 19
|
||||
P1_04 Pin = 20
|
||||
P1_05 Pin = 21
|
||||
P1_06 Pin = 22
|
||||
P1_07 Pin = 23
|
||||
P1_08 Pin = 24
|
||||
P1_09 Pin = 25
|
||||
P1_10 Pin = 26
|
||||
P1_11 Pin = 27
|
||||
P1_12 Pin = 28
|
||||
P1_13 Pin = 29
|
||||
P1_14 Pin = 30
|
||||
P1_15 Pin = 31
|
||||
P2_00 Pin = 32
|
||||
P2_01 Pin = 33
|
||||
P2_02 Pin = 34
|
||||
P2_03 Pin = 35
|
||||
P2_04 Pin = 36
|
||||
P2_05 Pin = 37
|
||||
P2_06 Pin = 38
|
||||
P2_07 Pin = 39
|
||||
P2_08 Pin = 40
|
||||
P2_09 Pin = 41
|
||||
P2_10 Pin = 42
|
||||
P2_11 Pin = 43
|
||||
P2_12 Pin = 44
|
||||
P2_13 Pin = 45
|
||||
P2_14 Pin = 46
|
||||
P2_15 Pin = 47
|
||||
P3_00 Pin = 48
|
||||
P3_01 Pin = 49
|
||||
P3_02 Pin = 50
|
||||
P3_03 Pin = 51
|
||||
P3_04 Pin = 52
|
||||
P3_05 Pin = 53
|
||||
P3_06 Pin = 54
|
||||
P3_07 Pin = 55
|
||||
P3_08 Pin = 56
|
||||
P3_09 Pin = 57
|
||||
P3_10 Pin = 58
|
||||
P3_11 Pin = 59
|
||||
P3_12 Pin = 60
|
||||
P3_13 Pin = 61
|
||||
P3_14 Pin = 62
|
||||
P3_15 Pin = 63
|
||||
P4_00 Pin = 64
|
||||
P4_01 Pin = 65
|
||||
P4_02 Pin = 66
|
||||
P4_03 Pin = 67
|
||||
P4_04 Pin = 68
|
||||
P4_05 Pin = 69
|
||||
P4_06 Pin = 70
|
||||
P4_07 Pin = 71
|
||||
P4_08 Pin = 72
|
||||
P4_09 Pin = 73
|
||||
P4_10 Pin = 74
|
||||
P4_11 Pin = 75
|
||||
P4_12 Pin = 76
|
||||
P4_13 Pin = 77
|
||||
P4_14 Pin = 78
|
||||
P4_15 Pin = 79
|
||||
P5_00 Pin = 80
|
||||
P5_01 Pin = 81
|
||||
P5_02 Pin = 82
|
||||
P5_03 Pin = 83
|
||||
P5_04 Pin = 84
|
||||
P5_05 Pin = 85
|
||||
P5_06 Pin = 86
|
||||
P5_07 Pin = 87
|
||||
P5_08 Pin = 88
|
||||
P5_09 Pin = 89
|
||||
P5_10 Pin = 90
|
||||
P5_11 Pin = 91
|
||||
P5_12 Pin = 92
|
||||
P5_13 Pin = 93
|
||||
P5_14 Pin = 94
|
||||
P5_15 Pin = 95
|
||||
)
|
||||
|
||||
const (
|
||||
PinOutput PinMode = iota
|
||||
PinInput
|
||||
PinInputPullUp
|
||||
PinInputPullDown
|
||||
)
|
||||
|
||||
// Configure configures the gpio pin as per mode.
|
||||
func (p Pin) Configure(config PinConfig) {
|
||||
if p == NoPin {
|
||||
return
|
||||
}
|
||||
|
||||
enableWritingPmnPFS()
|
||||
|
||||
switch config.Mode {
|
||||
case PinOutput:
|
||||
setPDR(p, renesas.PFS_P000PFS_PDR_1)
|
||||
default:
|
||||
setPDR(p, renesas.PFS_P000PFS_PDR_0)
|
||||
}
|
||||
|
||||
disableWritingPmnPFS()
|
||||
}
|
||||
|
||||
// Set drives the pin high if value is true else drives it low.
|
||||
func (p Pin) Set(value bool) {
|
||||
if p == NoPin {
|
||||
return
|
||||
}
|
||||
|
||||
port := getPort(p)
|
||||
if port == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if value == true {
|
||||
port.set(p)
|
||||
} else {
|
||||
port.clr(p)
|
||||
}
|
||||
}
|
||||
|
||||
// Get reads the pin value.
|
||||
func (p Pin) Get() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
gpioPort0 = gpioPortType0{renesas.PORT0}
|
||||
gpioPort1 = gpioPortType1{renesas.PORT1}
|
||||
gpioPort2 = gpioPortType1{renesas.PORT2}
|
||||
gpioPort3 = gpioPortType1{renesas.PORT3}
|
||||
gpioPort4 = gpioPortType1{renesas.PORT4}
|
||||
gpioPort5 = gpioPortType0{renesas.PORT5}
|
||||
)
|
||||
|
||||
func getPort(p Pin) gpioPort {
|
||||
switch getPortNumber(p) {
|
||||
case 0:
|
||||
return gpioPort0
|
||||
case 1:
|
||||
return gpioPort1
|
||||
case 2:
|
||||
return gpioPort2
|
||||
case 3:
|
||||
return gpioPort3
|
||||
case 4:
|
||||
return gpioPort4
|
||||
case 5:
|
||||
return gpioPort5
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func getPortNumber(p Pin) int {
|
||||
return int(p) >> 8
|
||||
}
|
||||
|
||||
type gpioPort interface {
|
||||
set(p Pin)
|
||||
clr(p Pin)
|
||||
}
|
||||
|
||||
type gpioPortType0 struct {
|
||||
port *renesas.PORT0_Type
|
||||
}
|
||||
|
||||
func (p gpioPortType0) set(pin Pin) {
|
||||
p.port.SetPCNTR3_PORR(1 << pin)
|
||||
}
|
||||
|
||||
func (p gpioPortType0) clr(pin Pin) {
|
||||
p.port.SetPCNTR3_POSR(1 << pin)
|
||||
}
|
||||
|
||||
type gpioPortType1 struct {
|
||||
port *renesas.PORT1_Type
|
||||
}
|
||||
|
||||
func (p gpioPortType1) set(pin Pin) {
|
||||
p.port.SetPCNTR3_PORR(1 << pin)
|
||||
}
|
||||
|
||||
func (p gpioPortType1) clr(pin Pin) {
|
||||
p.port.SetPCNTR3_POSR(1 << pin)
|
||||
}
|
||||
|
||||
func enableWritingPmnPFS() {
|
||||
renesas.PMISC.PWPR.Set(0x0)
|
||||
renesas.PMISC.SetPWPR_PFSWE(0x1)
|
||||
}
|
||||
|
||||
func disableWritingPmnPFS() {
|
||||
renesas.PMISC.PWPR.Set(0x0)
|
||||
renesas.PMISC.SetPWPR_B0WI(0x1)
|
||||
}
|
||||
|
||||
func setPDR(p Pin, value uint32) {
|
||||
port := getPortNumber(p)
|
||||
bit := int(p) & 0xff
|
||||
reg := (*volatile.Register32)(unsafe.Add(unsafe.Pointer(uintptr(0x40040800)), 0x40*port+4*bit))
|
||||
reg.SetBits(value << renesas.PFS_P000PFS_PDR_Pos)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
//go:build ra4m1
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"device/arm"
|
||||
"machine"
|
||||
)
|
||||
|
||||
// machineTicks is provided by package machine.
|
||||
func machineTicks() uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// machineLightSleep is provided by package machine.
|
||||
func machineLightSleep(uint64) {
|
||||
return
|
||||
}
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||
func ticks() timeUnit {
|
||||
t := machineTicks()
|
||||
return timeUnit(t)
|
||||
}
|
||||
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
return int64(ticks) * 1000
|
||||
}
|
||||
|
||||
func nanosecondsToTicks(ns int64) timeUnit {
|
||||
return timeUnit(ns / 1000)
|
||||
}
|
||||
|
||||
func sleepTicks(d timeUnit) {
|
||||
if d <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if hasScheduler {
|
||||
// With scheduler, sleepTicks may return early if an interrupt or
|
||||
// event fires - so scheduler can schedule any go routines now
|
||||
// eligible to run
|
||||
machineLightSleep(uint64(d))
|
||||
return
|
||||
}
|
||||
|
||||
// Busy loop
|
||||
sleepUntil := ticks() + d
|
||||
for ticks() < sleepUntil {
|
||||
}
|
||||
}
|
||||
|
||||
func waitForEvents() {
|
||||
arm.Asm("wfe")
|
||||
}
|
||||
|
||||
func putchar(c byte) {
|
||||
machine.Serial.WriteByte(c)
|
||||
}
|
||||
|
||||
func getchar() byte {
|
||||
for machine.Serial.Buffered() == 0 {
|
||||
Gosched()
|
||||
}
|
||||
v, _ := machine.Serial.ReadByte()
|
||||
return v
|
||||
}
|
||||
|
||||
func buffered() int {
|
||||
return machine.Serial.Buffered()
|
||||
}
|
||||
|
||||
// machineInit is provided by package machine.
|
||||
func machineInit() {
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
machineInit()
|
||||
}
|
||||
|
||||
//export Reset_Handler
|
||||
func main() {
|
||||
preinit()
|
||||
run()
|
||||
exit(0)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"inherits": ["ra4m1"],
|
||||
"build-tags": ["arduino_unor4"],
|
||||
"flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x4000 {bin}",
|
||||
"serial-port": ["2341:8057", "2341:0057"],
|
||||
"flash-1200-bps-reset": "true"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"inherits": ["cortex-m4"],
|
||||
"build-tags": ["ra4m1", "r7fa4m1ab", "renesas"],
|
||||
"linkerscript": "targets/ra4m1.ld",
|
||||
"extra-files": [
|
||||
"src/device/renesas/r7fa4m1ab.s"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH_TEXT (rw) : ORIGIN = 0x00000000+0x4000, LENGTH = 0x00080000-0x4000 /* First 16KB used by bootloader */
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00040000
|
||||
}
|
||||
|
||||
_stack_size = 4K;
|
||||
|
||||
INCLUDE "targets/arm.ld"
|
||||
@@ -550,6 +550,10 @@ func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPre
|
||||
// names like "CNT[31]". Replace invalid characters with "_" when
|
||||
// needed.
|
||||
fieldName := cleanName(fieldEl.Name)
|
||||
// Renesas has duplicate reserved fields that we have to skip
|
||||
if strings.EqualFold(fieldName, "reserved") {
|
||||
continue
|
||||
}
|
||||
if !unicode.IsUpper(rune(fieldName[0])) && !unicode.IsDigit(rune(fieldName[0])) {
|
||||
fieldName = strings.ToUpper(fieldName)
|
||||
}
|
||||
@@ -834,12 +838,20 @@ func parseRegister(groupName string, regEl *SVDRegister, baseAddress uint64, bit
|
||||
// we need to generate a separate register for each "element"
|
||||
var results []*PeripheralField
|
||||
shortName := strings.ToUpper(strings.ReplaceAll(strings.ReplaceAll(reg.name(), "_%s", ""), "%s", ""))
|
||||
// handle Renesas SVDs that have multiple dimIndex values with same name
|
||||
if reg.element.DimIndex != nil {
|
||||
idx := reg.dimIndex()
|
||||
if !(idx[0] == "0" || idx[0] == "1") {
|
||||
shortName = strings.ToUpper(strings.ReplaceAll(strings.ReplaceAll(reg.name(), "_%s", ""), "%s", idx[0]))
|
||||
}
|
||||
}
|
||||
|
||||
for i, j := range reg.dimIndex() {
|
||||
regAddress := reg.address() + (uint64(i) * dimIncrement)
|
||||
results = append(results, &PeripheralField{
|
||||
Name: strings.ToUpper(strings.ReplaceAll(reg.name(), "%s", j)),
|
||||
Address: regAddress,
|
||||
Description: reg.description(),
|
||||
Description: strings.ReplaceAll(reg.description(), "%s", j),
|
||||
Array: -1,
|
||||
ElementSize: reg.size(),
|
||||
ShortName: shortName,
|
||||
|
||||
Reference in New Issue
Block a user