From 0a90509d0d0b575247a04078dd1df95a75b8dc15 Mon Sep 17 00:00:00 2001 From: Jack Reamy Date: Mon, 7 Sep 2020 11:43:56 -0700 Subject: [PATCH 1/5] Adding support for the Arduino Zero --- README.md | 3 +- src/machine/board_arduino_zero.go | 85 +++++++++++++++++++++++++++ targets/arduino-zero-native.json | 6 ++ targets/arduino-zero-programming.json | 9 +++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/machine/board_arduino_zero.go create mode 100644 targets/arduino-zero-native.json create mode 100644 targets/arduino-zero-programming.json diff --git a/README.md b/README.md index 1ff94089f4..437f617efc 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ See the [getting started instructions](https://tinygo.org/getting-started/) for You can compile TinyGo programs for microcontrollers, WebAssembly and Linux. -The following 40 microcontroller boards are currently supported: +The following 41 microcontroller boards are currently supported: * [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333) * [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333) @@ -62,6 +62,7 @@ The following 40 microcontroller boards are currently supported: * [Arduino Mega 2560](https://store.arduino.cc/arduino-mega-2560-rev3) * [Arduino Nano](https://store.arduino.cc/arduino-nano) * [Arduino Nano33 IoT](https://store.arduino.cc/nano-33-iot) +* [Arduino Zero](https://store.arduino.cc/usa/arduino-zero) * [Arduino Uno](https://store.arduino.cc/arduino-uno-rev3) * [BBC micro:bit](https://microbit.org/) * [Digispark](http://digistump.com/products/1) diff --git a/src/machine/board_arduino_zero.go b/src/machine/board_arduino_zero.go new file mode 100644 index 0000000000..f69092ade3 --- /dev/null +++ b/src/machine/board_arduino_zero.go @@ -0,0 +1,85 @@ +// +build sam,atsamd21,arduino_zero + +package machine + +// used to reset into bootloader +const RESET_MAGIC_VALUE = 0x07738135 + +// GPIO Pins +const ( + D0 = PA11 // RX + D1 = PA10 // TX + D2 = PA14 + D3 = PA09 // PWM available + D4 = PA08 // PWM available + D5 = PA15 // PWM available + D6 = PA20 // PWM available + D7 = PA21 + D8 = PA06 // PWM available + D9 = PA07 // PWM available + D10 = PA18 // PWM available + D11 = PA16 // PWM available + D12 = PA19 // PWM available + D13 = PA17 // PWM available +) + +// LEDs on the Arduino Zero +const ( + LED Pin = D13 + LED1 Pin = PA27 + LED2 Pin = PB03 +) + +// ADC on the Arduino +const ( + ADC0 Pin = PA02 + ADC1 Pin = PB08 + ADC2 Pin = PB09 + ADC3 Pin = PA04 + ADC4 Pin = PA05 + ADC5 Pin = PB02 +) + +// SPI pins +const ( + SPI0_SDO_PIN = PA16 // MOSI: SERCOM1/PAD[0] + SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1] + SPI0_SS_Pin = PA18 // SS: SERCOM1/PAD[2] + SPI0_SDI_PIN = PA19 // MISO: SERCOM1/PAD[3] +) + +// I2C pins +const ( + SDA_PIN Pin = PA22 // SDA: SERCOM3/PAD[0] + SCL_PIN Pin = PA23 // SCL: SERCOM3/PAD[1] +) + +// I2S pins +const ( + I2S_SCK_PIN Pin = PA10 + I2S_SD_PIN Pin = PA07 + I2S_WS_PIN Pin = PA11 +) + +// UART0 pins - 'promgramming' USB port +const ( + UART_TX_PIN Pin = D1 + UART_RX_PIN Pin = D0 +) + +// 'native' USB port pins +const ( + USBCDC_DM_PIN Pin = PA25 + USBCDC_DP_PIN Pin = PA24 +) + +// USB CDC identifiers +const ( + usb_STRING_PRODUCT = "Arduino Zero" + usb_STRING_MANUFACTURER = "Arduino LLC" +) + +var ( + usb_VID uint16 = 0x03eb + usb_PID uint16 = 0x2157 +) diff --git a/targets/arduino-zero-native.json b/targets/arduino-zero-native.json new file mode 100644 index 0000000000..672eb09853 --- /dev/null +++ b/targets/arduino-zero-native.json @@ -0,0 +1,6 @@ +{ + "inherits": ["atsamd21g18a"], + "build-tags": ["sam", "atsamd21g18a", "arduino_zero"], + "flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}", + "flash-1200-bps-reset": "true" +} diff --git a/targets/arduino-zero-programming.json b/targets/arduino-zero-programming.json new file mode 100644 index 0000000000..fa634ab6dc --- /dev/null +++ b/targets/arduino-zero-programming.json @@ -0,0 +1,9 @@ +{ + "inherits": ["atsamd21g18a"], + "build-tags": ["sam", "atsamd21g18a", "arduino_zero"], + + "flash-method":"openocd", + "openocd-transport": "swd", + "openocd-target": "at91samdXX", + "openocd-interface":"cmsis-dap" +} From 32c411e2fa0eb5d1bba6aa59b4941997b923c18c Mon Sep 17 00:00:00 2001 From: Jack Reamy Date: Tue, 8 Sep 2020 10:24:50 -0700 Subject: [PATCH 2/5] consolidating to use native port only --- src/machine/board_arduino_zero.go | 71 +++++++++++-------- targets/arduino-zero-programming.json | 9 --- ...ino-zero-native.json => arduino-zero.json} | 0 3 files changed, 43 insertions(+), 37 deletions(-) delete mode 100644 targets/arduino-zero-programming.json rename targets/{arduino-zero-native.json => arduino-zero.json} (100%) diff --git a/src/machine/board_arduino_zero.go b/src/machine/board_arduino_zero.go index f69092ade3..23e69cc1e7 100644 --- a/src/machine/board_arduino_zero.go +++ b/src/machine/board_arduino_zero.go @@ -5,16 +5,20 @@ package machine // used to reset into bootloader const RESET_MAGIC_VALUE = 0x07738135 -// GPIO Pins +// GPIO Pins - Digital Low +const ( + D0 = PA11 // RX + D1 = PA10 // TX + D2 = PA14 + D3 = PA09 // PWM available + D4 = PA08 // PWM available + D5 = PA15 // PWM available + D6 = PA20 // PWM available + D7 = PA21 +) + +// GPIO Pins - Digital High const ( - D0 = PA11 // RX - D1 = PA10 // TX - D2 = PA14 - D3 = PA09 // PWM available - D4 = PA08 // PWM available - D5 = PA15 // PWM available - D6 = PA20 // PWM available - D7 = PA21 D8 = PA06 // PWM available D9 = PA07 // PWM available D10 = PA18 // PWM available @@ -26,12 +30,13 @@ const ( // LEDs on the Arduino Zero const ( LED Pin = D13 - LED1 Pin = PA27 - LED2 Pin = PB03 + LED1 Pin = PA27 // TX LED + LED2 Pin = PB03 // RX LED ) -// ADC on the Arduino +// ADC pins const ( + AREF Pin = PA03 ADC0 Pin = PA02 ADC1 Pin = PB08 ADC2 Pin = PB09 @@ -40,46 +45,56 @@ const ( ADC5 Pin = PB02 ) -// SPI pins +// SPI pins - EDBG connected +const ( + SPI0_SDO_PIN Pin = PA16 // MOSI: SERCOM1/PAD[0] + SPI0_SDI_PIN Pin = PA19 // MISO: SERCOM1/PAD[2] + SPI0_SCK_PIN Pin = PA17 // SCK: SERCOM1/PAD[3] +) + +// SPI pins (Legacy ICSP) const ( - SPI0_SDO_PIN = PA16 // MOSI: SERCOM1/PAD[0] - SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1] - SPI0_SS_Pin = PA18 // SS: SERCOM1/PAD[2] - SPI0_SDI_PIN = PA19 // MISO: SERCOM1/PAD[3] + SPI1_SDO_PIN Pin = PB10 // MOSI: SERCOM4/PAD[2] - Pin 4 + SPI1_SDI_PIN Pin = PA12 // MISO: SERCOM4/PAD[0] - Pin 1 + SPI1_SCK_PIN Pin = PB11 // SCK: SERCOM4/PAD[3] - Pin 3 ) -// I2C pins +// I2C pins - EDBG connected const ( - SDA_PIN Pin = PA22 // SDA: SERCOM3/PAD[0] - SCL_PIN Pin = PA23 // SCL: SERCOM3/PAD[1] + SDA_PIN Pin = PA22 // SDA: SERCOM3/PAD[0] - Pin 20 + SCL_PIN Pin = PA23 // SCL: SERCOM3/PAD[1] - Pin 21 ) -// I2S pins +// I2S pins - might not be exposed const ( I2S_SCK_PIN Pin = PA10 I2S_SD_PIN Pin = PA07 I2S_WS_PIN Pin = PA11 ) -// UART0 pins - 'promgramming' USB port +// UART0 pins - EDBG connected const ( - UART_TX_PIN Pin = D1 UART_RX_PIN Pin = D0 + UART_TX_PIN Pin = D1 ) // 'native' USB port pins const ( - USBCDC_DM_PIN Pin = PA25 - USBCDC_DP_PIN Pin = PA24 + USBCDC_DM_PIN Pin = PA24 + USBCDC_DP_PIN Pin = PA25 ) // USB CDC identifiers const ( usb_STRING_PRODUCT = "Arduino Zero" usb_STRING_MANUFACTURER = "Arduino LLC" + + usb_VID uint16 = 0x2341 + usb_PID uint16 = 0x804d ) -var ( - usb_VID uint16 = 0x03eb - usb_PID uint16 = 0x2157 +// 32.768 KHz Crystal +const ( + XIN32 Pin = PA00 + XOUT32 Pin = PA01 ) diff --git a/targets/arduino-zero-programming.json b/targets/arduino-zero-programming.json deleted file mode 100644 index fa634ab6dc..0000000000 --- a/targets/arduino-zero-programming.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "inherits": ["atsamd21g18a"], - "build-tags": ["sam", "atsamd21g18a", "arduino_zero"], - - "flash-method":"openocd", - "openocd-transport": "swd", - "openocd-target": "at91samdXX", - "openocd-interface":"cmsis-dap" -} diff --git a/targets/arduino-zero-native.json b/targets/arduino-zero.json similarity index 100% rename from targets/arduino-zero-native.json rename to targets/arduino-zero.json From d78aee76280eaa455d55dd6a7e17c4a1492073a5 Mon Sep 17 00:00:00 2001 From: jreamy <37675348+jreamy@users.noreply.github.com> Date: Wed, 9 Sep 2020 11:21:07 -0700 Subject: [PATCH 3/5] Update targets/arduino-zero.json Co-authored-by: Ayke --- targets/arduino-zero.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/arduino-zero.json b/targets/arduino-zero.json index 672eb09853..50483512ee 100644 --- a/targets/arduino-zero.json +++ b/targets/arduino-zero.json @@ -1,6 +1,6 @@ { "inherits": ["atsamd21g18a"], - "build-tags": ["sam", "atsamd21g18a", "arduino_zero"], + "build-tags": ["arduino_zero"], "flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}", "flash-1200-bps-reset": "true" } From 9f7f55bca7f209ec1435d21f27334fe4eeda86d2 Mon Sep 17 00:00:00 2001 From: jreamy <37675348+jreamy@users.noreply.github.com> Date: Wed, 9 Sep 2020 11:21:15 -0700 Subject: [PATCH 4/5] Update src/machine/board_arduino_zero.go Co-authored-by: Ayke --- src/machine/board_arduino_zero.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/machine/board_arduino_zero.go b/src/machine/board_arduino_zero.go index 23e69cc1e7..651eea8216 100644 --- a/src/machine/board_arduino_zero.go +++ b/src/machine/board_arduino_zero.go @@ -29,9 +29,10 @@ const ( // LEDs on the Arduino Zero const ( - LED Pin = D13 - LED1 Pin = PA27 // TX LED - LED2 Pin = PB03 // RX LED + LED = LED1 + LED1 Pin = D13 + LED2 Pin = PA27 // TX LED + LED3 Pin = PB03 // RX LED ) // ADC pins From caab75146c8f516b092f0fc37b304f94f6c42773 Mon Sep 17 00:00:00 2001 From: Jack Reamy Date: Wed, 9 Sep 2020 23:07:46 -0700 Subject: [PATCH 5/5] it actually won't build without the build-tags set as they were --- targets/arduino-zero.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/arduino-zero.json b/targets/arduino-zero.json index 50483512ee..672eb09853 100644 --- a/targets/arduino-zero.json +++ b/targets/arduino-zero.json @@ -1,6 +1,6 @@ { "inherits": ["atsamd21g18a"], - "build-tags": ["arduino_zero"], + "build-tags": ["sam", "atsamd21g18a", "arduino_zero"], "flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}", "flash-1200-bps-reset": "true" }