From b45714977d189ef17b1399fe31afbf9ff1dba822 Mon Sep 17 00:00:00 2001 From: agdl Date: Mon, 19 Mar 2018 09:46:12 +0100 Subject: [PATCH] Add MKR WiFi1010 variant and bootloader * Update variant for hardware changes - Use sercom2 for SPI1 - Remove Serial2 - update various comments - disable NINA on start * Add Serial2 (overlaps with SPI1) This commit squashes all the dev commits from @agdl, @sandeepmistry and @facchinm --- boards.txt | 29 + .../samd21_sam_ba_arduino_mkrwifi1010.bin | Bin 0 -> 7992 bytes .../samd21_sam_ba_arduino_mkrwifi1010.hex | 502 ++++++++++++++++++ bootloaders/zero/board_definitions.h | 2 + .../board_definitions_arduino_mkrwifi1010.h | 86 +++ bootloaders/zero/build_all_bootloaders.sh | 3 + .../mkrwifi1010/debug_scripts/variant.gdb | 31 ++ .../gcc/flash_with_bootloader.ld | 217 ++++++++ .../gcc/flash_without_bootloader.ld | 214 ++++++++ .../openocd_scripts/arduino_zero.cfg | 30 ++ variants/mkrwifi1010/pins_arduino.h | 21 + variants/mkrwifi1010/variant.cpp | 252 +++++++++ variants/mkrwifi1010/variant.h | 214 ++++++++ 13 files changed, 1601 insertions(+) create mode 100755 bootloaders/mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.bin create mode 100644 bootloaders/mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.hex create mode 100644 bootloaders/zero/board_definitions_arduino_mkrwifi1010.h create mode 100644 variants/mkrwifi1010/debug_scripts/variant.gdb create mode 100644 variants/mkrwifi1010/linker_scripts/gcc/flash_with_bootloader.ld create mode 100644 variants/mkrwifi1010/linker_scripts/gcc/flash_without_bootloader.ld create mode 100644 variants/mkrwifi1010/openocd_scripts/arduino_zero.cfg create mode 100644 variants/mkrwifi1010/pins_arduino.h create mode 100644 variants/mkrwifi1010/variant.cpp create mode 100644 variants/mkrwifi1010/variant.h diff --git a/boards.txt b/boards.txt index 0ecc86e6..c9a63c11 100644 --- a/boards.txt +++ b/boards.txt @@ -249,6 +249,35 @@ mkrwan1300.build.pid=0x8053 mkrwan1300.bootloader.tool=openocd mkrwan1300.bootloader.file=mkrwan1300/samd21_sam_ba_arduino_mkrwan1300.bin +# Arduino MKR WiFi 1010 +# -------------------- +mkrwifi1010.name=Arduino MKR WiFi 1010 +mkrwifi1010.vid.0=0x2341 +mkrwifi1010.pid.0=0x8054 +mkrwifi1010.vid.1=0x2341 +mkrwifi1010.pid.1=0x0054 + +mkrwifi1010.upload.tool=bossac +mkrwifi1010.upload.protocol=sam-ba +mkrwifi1010.upload.maximum_size=262144 +mkrwifi1010.upload.use_1200bps_touch=true +mkrwifi1010.upload.wait_for_upload_port=true +mkrwifi1010.upload.native_usb=true +mkrwifi1010.build.mcu=cortex-m0plus +mkrwifi1010.build.f_cpu=48000000L +mkrwifi1010.build.usb_product="Arduino MKR WiFi 1010" +mkrwifi1010.build.usb_manufacturer="Arduino LLC" +mkrwifi1010.build.board=SAMD_MKRWIFI1010 +mkrwifi1010.build.core=arduino +mkrwifi1010.build.extra_flags=-D__SAMD21G18A__ {build.usb_flags} -DUSE_BQ24195L_PMIC +mkrwifi1010.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld +mkrwifi1010.build.openocdscript=openocd_scripts/arduino_zero.cfg +mkrwifi1010.build.variant=mkrwifi1010 +mkrwifi1010.build.vid=0x2341 +mkrwifi1010.build.pid=0x8054 +mkrwifi1010.bootloader.tool=openocd +mkrwifi1010.bootloader.file=mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.bin + # Adafruit Circuit Playground M0 # ------------------------------ adafruit_circuitplayground_m0.name=Adafruit Circuit Playground Express diff --git a/bootloaders/mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.bin b/bootloaders/mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.bin new file mode 100755 index 0000000000000000000000000000000000000000..0efac740c2b0ded148471d9ddb60092fc9674944 GIT binary patch literal 7992 zcmaJm4R{pQwfD~KfBtq8es(uQ*xgCOCL18h1`GjlvWv;?P7>tD8p2N}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|8QTd1a-w0(fd%*^9soWrbGW64YE#o z3}hPMp8`gIY%D1UA_F3evHtR!2ah2Zcd$|qkpYX8-|Od& z=E0v^1!Xdvm&f}1wm{JtoSSPr9MGNK3RxO6&c>HVKSbB-VYC`u9&HQYGn~^ItT7!5 zP-jr~8j~lu=UVvyl;6Boz5r#AlALYEvf2E>sFkt42zeWL86($V(D-{QL>=brR0j?5 zl>@FPDj1V#xL+@5=`RL?yPS5obL8Gx;Xk9U04=|{=HyE3zcOkapqXvo*khuzyg5#0UiNx z!=?(H2;B?4Y8yAXN*1_Ei%ZH;@q&u7c@-sPsNRx>Rsl4C=SxG2QRy5qJ$f1@ItB0% zfEn`3c>o000<6Ba=!*JP4QqkdZ4J0?FW$jDam$~DQOUHmU|;0$ozLt!{|D9w z3BKRE)BNy1K6>k`r(W56cE$Wn`L=1rhIj7$*BuXk@Ap-!|FHSjjz`KLd@r6DJ^0Rx zubvEjRR1&a*HO;YXs5hv`J1OcKlk%bes?9btGUN=)c3+y4R1&Ou=$r8TAa67{1usn zlfxI@cxn7s7hCt&w=evo^T~hT_~3mX*1WRDQ$#NkQY)F?e*TNe&;Ih4cMG3R84&k| z4?eQxxx3D;`|rA}#ietWQ0Jox-0-yhu) zpYiIVch2PhbN)WVv1zy6aqqoTtIEDtbMA+y(yz?@Tk&SwidE9OjQe7^DB+Q0nA zK>O1lA3U`;|32f!rZqR$Jho_ik;)uTo%zLLZS7n4y|@2&|M}9nUtE54`d#z4+* FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* To copy multiple ROM to RAM sections, + * uncomment .copy.table section and, + * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */ + /* + .copy.table : + { + . = ALIGN(4); + __copy_table_start__ = .; + LONG (__etext) + LONG (__data_start__) + LONG (__data_end__ - __data_start__) + LONG (__etext2) + LONG (__data2_start__) + LONG (__data2_end__ - __data2_start__) + __copy_table_end__ = .; + } > FLASH + */ + + /* To clear multiple BSS sections, + * uncomment .zero.table section and, + * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */ + /* + .zero.table : + { + . = ALIGN(4); + __zero_table_start__ = .; + LONG (__bss_start__) + LONG (__bss_end__ - __bss_start__) + LONG (__bss2_start__) + LONG (__bss2_end__ - __bss2_start__) + __zero_table_end__ = .; + } > FLASH + */ + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(16); + /* All data end */ + __data_end__ = .; + + } > RAM + + .bss : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + PROVIDE(end = .); + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + __ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ; + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") +} diff --git a/variants/mkrwifi1010/linker_scripts/gcc/flash_without_bootloader.ld b/variants/mkrwifi1010/linker_scripts/gcc/flash_without_bootloader.ld new file mode 100644 index 00000000..ebeeee37 --- /dev/null +++ b/variants/mkrwifi1010/linker_scripts/gcc/flash_without_bootloader.ld @@ -0,0 +1,214 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* Linker script to configure memory regions. + * Need modifying for a specific board. + * FLASH.ORIGIN: starting address of flash + * FLASH.LENGTH: length of flash + * RAM.ORIGIN: starting address of RAM bank 0 + * RAM.LENGTH: length of RAM bank 0 + */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 +} + +/* Linker script to place sections and symbol values. Should be used together + * with other linker script that defines memory regions FLASH and RAM. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __copy_table_start__ + * __copy_table_end__ + * __zero_table_start__ + * __zero_table_end__ + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + * __ram_end__ + */ +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + __text_start__ = .; + + KEEP(*(.isr_vector)) + *(.text*) + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + KEEP(*(.eh_frame*)) + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* To copy multiple ROM to RAM sections, + * uncomment .copy.table section and, + * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */ + /* + .copy.table : + { + . = ALIGN(4); + __copy_table_start__ = .; + LONG (__etext) + LONG (__data_start__) + LONG (__data_end__ - __data_start__) + LONG (__etext2) + LONG (__data2_start__) + LONG (__data2_end__ - __data2_start__) + __copy_table_end__ = .; + } > FLASH + */ + + /* To clear multiple BSS sections, + * uncomment .zero.table section and, + * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */ + /* + .zero.table : + { + . = ALIGN(4); + __zero_table_start__ = .; + LONG (__bss_start__) + LONG (__bss_end__ - __bss_start__) + LONG (__bss2_start__) + LONG (__bss2_end__ - __bss2_start__) + __zero_table_end__ = .; + } > FLASH + */ + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(16); + /* All data end */ + __data_end__ = .; + + } > RAM + + .bss : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + PROVIDE(end = .); + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM) ; + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + __ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ; + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") +} diff --git a/variants/mkrwifi1010/openocd_scripts/arduino_zero.cfg b/variants/mkrwifi1010/openocd_scripts/arduino_zero.cfg new file mode 100644 index 00000000..36c65c32 --- /dev/null +++ b/variants/mkrwifi1010/openocd_scripts/arduino_zero.cfg @@ -0,0 +1,30 @@ +# +# Arduino Zero OpenOCD script. +# +# Copyright (c) 2014-2015 Arduino LLC. All right reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +source [find interface/cmsis-dap.cfg] + +# chip name +set CHIPNAME at91samd21g18 +set ENDIAN little + +# choose a port here +set telnet_port 0 + +source [find target/at91samdXX.cfg] diff --git a/variants/mkrwifi1010/pins_arduino.h b/variants/mkrwifi1010/pins_arduino.h new file mode 100644 index 00000000..db0e40c3 --- /dev/null +++ b/variants/mkrwifi1010/pins_arduino.h @@ -0,0 +1,21 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +// API compatibility +#include "variant.h" + diff --git a/variants/mkrwifi1010/variant.cpp b/variants/mkrwifi1010/variant.cpp new file mode 100644 index 00000000..3605ce11 --- /dev/null +++ b/variants/mkrwifi1010/variant.cpp @@ -0,0 +1,252 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "Arduino.h" + +const PinDescription g_APinDescription[] = { + +/* + +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+ + | Pin number | MKR Board pin | PIN | Notes | Peri.A | Peripheral B | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H | + | | | | | EIC | ADC | AC | PTC | DAC | SERCOMx | SERCOMx | TCCx | TCCx | COM | AC/GLCK | + | | | | |(EXTINT)|(AIN)|(AIN)| | | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | 00 | D0 | PA22 | | *06 | | | X10 | | 3/00 | 5/00 |* TC4/0 | TCC0/4 | | GCLK_IO6 | + | 01 | D1 | PA23 | | *07 | | | X11 | | 3/01 | 5/01 |* TC4/1 | TCC0/5 | USB/SOF | GCLK_IO7 | + | 02 | D2 | PA10 | | 10 | *18 | | X02 | | 0/02 | 2/02 |*TCC1/0 | TCC0/2 | I2S/SCK0 | GCLK_IO4 | + | 03 | D3 | PA11 | | 11 | *19 | | X03 | | 0/03 | 2/03 |*TCC1/1 | TCC0/3 | I2S/FS0 | GCLK_IO5 | + | 04 | D4 | PB10 | | *10 | | | | | | 4/02 |* TC5/0 | TCC0/4 | I2S/MCK1 | GCLK_IO4 | + | 05 | D5 | PB11 | | *11 | | | | | | 4/03 |* TC5/1 | TCC0/5 | I2S/SCK1 | GCLK_IO5 | + | 06 | D6 | PA20 | LED_BUILTIN | *04 | | | X08 | | 5/02 | 3/02 | |*TCC0/6 | I2S/SCK0 | GCLK_IO4 | + | 07 | D7 | PA21 | | *05 | | | X09 | | 5/03 | 3/03 | |*TCC0/7 | I2S/FS0 | GCLK_IO5 | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + */ + { PORTA, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), No_ADC_Channel, PWM4_CH0, TC4_CH0, EXTERNAL_INT_6 }, + { PORTA, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), No_ADC_Channel, PWM4_CH1, TC4_CH1, EXTERNAL_INT_7 }, + { PORTA, 10, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), ADC_Channel18, PWM1_CH0, TCC1_CH0, EXTERNAL_INT_NONE }, + { PORTA, 11, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), ADC_Channel19, PWM1_CH1, TCC1_CH1, EXTERNAL_INT_NONE }, + { PORTB, 10, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), No_ADC_Channel, PWM5_CH0, TC5_CH0, EXTERNAL_INT_10 }, + { PORTB, 11, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), No_ADC_Channel, PWM5_CH1, TC5_CH1, EXTERNAL_INT_11 }, + { PORTA, 20, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH6, TCC0_CH6, EXTERNAL_INT_4 }, + { PORTA, 21, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH7, TCC0_CH7, EXTERNAL_INT_5 }, + +/* + +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+ + | Pin number | MKR Board pin | PIN | Notes | Peri.A | Peripheral B | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H | + | | | | | EIC | ADC | AC | PTC | DAC | SERCOMx | SERCOMx | TCCx | TCCx | COM | AC/GLCK | + | | | | |(EXTINT)|(AIN)|(AIN)| | | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | | SPI | | | | | | | | | | | | | | + | 08 | MOSI | PA16 | | *00 | | | X04 | | *1/00 | 3/00 |*TCC2/0 | TCC0/6 | | GCLK_IO2 | + | 09 | SCK | PA17 | | *01 | | | X05 | | *1/01 | 3/01 | TCC2/1 | TCC0/7 | | GCLK_IO3 | + | 10 | MISO | PA19 | | 03 | | | X07 | | *1/03 | 3/03 |* TC3/1 | TCC0/3 | I2S/SD0 | AC/CMP1 | + +------------+------------------+--------+-----------------+--------------------+-----+-----+---------+---------+--------+--------+----------+----------+ + | | Wire | | | | | | | | | | | | | | + | 11 | SDA | PA08 | | NMI | *16 | | X00 | | *0/00 | 2/00 | TCC0/0 | TCC1/2 | I2S/SD1 | | + | 12 | SCL | PA09 | | 09 | *17 | | X01 | | *0/01 | 2/01 | TCC0/1 | TCC1/3 | I2S/MCK0 | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | | Serial1 | | | | | | | | | | | | | | + | 13 | RX | PB23 | | 07 | | | | | | *5/03 | | | | GCLK_IO1 | + | 14 | TX | PB22 | | 06 | | | | | | *5/02 | | | | GCLK_IO0 | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + */ + // DIPO=3 DOPO=0 + { PORTA, 16, PIO_SERCOM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), No_ADC_Channel, PWM2_CH0, TCC2_CH0, EXTERNAL_INT_0 }, // MOSI: SERCOM1/PAD[0] + { PORTA, 17, PIO_SERCOM, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, // SCK: SERCOM1/PAD[1] + { PORTA, 19, PIO_SERCOM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), No_ADC_Channel, PWM3_CH1, TC3_CH1, EXTERNAL_INT_NONE }, // MISO: SERCOM1/PAD[3] + + // PINOUT=0 + { PORTA, 8, PIO_SERCOM, (PIN_ATTR_DIGITAL ), ADC_Channel16, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI }, // SDA: SERCOM0/PAD[0] + { PORTA, 9, PIO_SERCOM, (PIN_ATTR_DIGITAL ), ADC_Channel17, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SCL: SERCOM0/PAD[1] + + // RXPO=3 TXPO=1 + { PORTB, 23, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // RX: SERCOM5/PAD[3] + { PORTB, 22, PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // TX: SERCOM5/PAD[2] + + +/* + +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+ + | Pin number | MKR Board pin | PIN | Notes | Peri.A | Peripheral B | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H | + | | | | | EIC | ADC | AC | PTC | DAC | SERCOMx | SERCOMx | TCCx | TCCx | COM | AC/GLCK | + | | | | |(EXTINT)|(AIN)|(AIN)| | | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | 15 | A0 / DAC0 | PA02 | | 02 | *00 | | Y00 | OUT | | | | | | | + | 16 | A1 | PB02 | | *02 | *10 | | Y08 | | | 5/00 | | | | | + | 17 | A2 | PB03 | | *03 | *11 | | Y09 | | | 5/01 | | | | | + | 18 | A3 | PA04 | | 04 | *04 | 00 | Y02 | | | 0/00 |*TCC0/0 | | | | + | 19 | A4 | PA05 | | 05 | *05 | 01 | Y03 | | | 0/01 |*TCC0/1 | | | | + | 20 | A5 | PA06 | | 06 | *06 | 02 | Y04 | | | 0/02 | TCC1/0 | | | | + | 21 | A6 | PA07 | | 07 | *07 | 03 | Y05 | | | 0/03 | TCC1/1 | | I2S/SD0 | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + */ + { PORTA, 2, PIO_ANALOG, (PIN_ATTR_DIGITAL|PIN_ATTR_ANALOG /*DAC*/ ), ADC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + { PORTB, 2, PIO_ANALOG, (PIN_ATTR_DIGITAL ), ADC_Channel10, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, + { PORTB, 3, PIO_ANALOG, (PIN_ATTR_DIGITAL ), ADC_Channel11, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3 }, + { PORTA, 4, PIO_ANALOG, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), ADC_Channel4, PWM0_CH0, TCC0_CH0, EXTERNAL_INT_NONE }, + { PORTA, 5, PIO_ANALOG, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER ), ADC_Channel5, PWM0_CH1, TCC0_CH1, EXTERNAL_INT_NONE }, + { PORTA, 6, PIO_ANALOG, (PIN_ATTR_DIGITAL ), ADC_Channel6, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + { PORTA, 7, PIO_ANALOG, (PIN_ATTR_DIGITAL ), ADC_Channel7, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + +/* + +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+ + | Pin number | MKR Board pin | PIN | Notes | Peri.A | Peripheral B | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H | + | | | | | EIC | ADC | AC | PTC | DAC | SERCOMx | SERCOMx | TCCx | TCCx | COM | AC/GLCK | + | | | | |(EXTINT)|(AIN)|(AIN)| | | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | | USB | | | | | | | | | | | | | | + | 22 | | PA24 | USB N | 12 | | | | | 3/02 | 5/02 | TC5/0 | TCC1/2 | USB/DM | | + | 23 | | PA25 | USB P | 13 | | | | | 3/03 | 5/03 | TC5/1 | TCC1/3 | USB/DP | | + | 24 | | PA18 | USB ID | 02 | | | X06 | | 1/02 | 3/02 | TC3/0 | TCC0/2 | | AC/CMP0 | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | 25 | AREF | PA03 | | 03 | 01 | | Y01 | | | | | | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + */ + { PORTA, 24, PIO_COM, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM + { PORTA, 25, PIO_COM, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP + { PORTA, 18, PIO_DIGITAL, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + + { PORTA, 3, PIO_DIGITAL, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VREFP + +/* + +------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+ + | Pin number | MKR Board pin | PIN | Notes | Peri.A | Peripheral B | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H | + | | | | | EIC | ADC | AC | PTC | DAC | SERCOMx | SERCOMx | TCCx | TCCx | COM | AC/GLCK | + | | | | |(EXTINT)|(AIN)|(AIN)| | | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | | WiFi SPI | | | | | | | | | | | | | | + | 26 | | PA12 | NINA_MOSI | 12 | | | | | *2/00 | 4/00 | TCC2/0 | TCC0/6 | | AC/CMP0 | + | 27 | | PA13 | NINA_MISO | 13 | | | | | *2/01 | 4/01 | TCC2/1 | TCC0/7 | | AC/CMP1 | + | 28 | | PA14 | NINA_CS | 14 | | | | | 2/02 | 4/02 | TC3/0 | TCC0/4 | | GCLK_IO0 | + | 29 | | PA15 | NINA_SCK | 15 | | | | | *2/03 | 4/03 | TC3/1 | TCC0/5 | | GCLK_IO1 | + | 30 | | PA27 | NINA_GPIO0 | *15 | | | | | | | | | | GCLK_IO0 | + | 31 | | PB08 | NINA_RESETN | 08 | 02 | | Y14 | | | 4/00 | TC4/0 | | | | + | 32 | | PB09 | ADC_VBAT | *09 | 03 | | Y15 | | | 4/01 | TC4/1 | | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | | 32768Hz Crystal | | | | | | | | | | | | | | + | 33 | | PA00 | XIN32 | 00 | | | | | | 1/00 | TCC2/0 | | | | + | 34 | | PA01 | XOUT32 | 01 | | | | | | 1/01 | TCC2/1 | | | | + +------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ + | 35 | | PA28 | NINA_ACK | 01 | | | | | | 1/01 | TCC2/1 | | | | ++------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+ +*/ + // DIPO=3 DOPO=0 + { PORTA, 12, PIO_SERCOM, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // MOSI: SERCOM2/PAD[0] + { PORTA, 13, PIO_SERCOM, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SCK: SERCOM2/PAD[1] + { PORTA, 14, PIO_DIGITAL, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // SS: as GPIO + { PORTA, 15, PIO_SERCOM, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // MISO: SERCOM2/PAD[3] + { PORTA, 27, PIO_DIGITAL, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_15 }, + + { PORTB, 8, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_ANALOG ), ADC_Channel2, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + { PORTB, 9, PIO_ANALOG, (PIN_ATTR_PWM|PIN_ATTR_TIMER ), ADC_Channel3, PWM4_CH1, TC4_CH1, EXTERNAL_INT_9 }, + + { PORTA, 0, PIO_DIGITAL, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + { PORTA, 1, PIO_DIGITAL, (PIN_ATTR_NONE ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, + + { PORTA, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, +}; + +const void* g_apTCInstances[TCC_INST_NUM + TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, TC4, TC5 }; + +// Multi-serial objects instantiation +SERCOM sercom0(SERCOM0); +SERCOM sercom1(SERCOM1); +SERCOM sercom2(SERCOM2); +SERCOM sercom3(SERCOM3); +SERCOM sercom4(SERCOM4); +SERCOM sercom5(SERCOM5); + +#if defined(USE_BQ24195L_PMIC) + +#include "wiring_private.h" + +#define PMIC_ADDRESS 0x6B +#define PMIC_REG01 0x01 +#define PMIC_REG07 0x07 + +static inline void enable_battery_charging() { + PERIPH_WIRE.initMasterWIRE(100000); + PERIPH_WIRE.enableWIRE(); + pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType); + pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType); + + PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG ); + PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG01); + PERIPH_WIRE.sendDataMasterWIRE(0x1B); // Charge Battery + Minimum System Voltage 3.5V + PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP); + + PERIPH_WIRE.disableWIRE(); +} + +static inline void disable_battery_fet(bool disabled) { + PERIPH_WIRE.initMasterWIRE(100000); + PERIPH_WIRE.enableWIRE(); + pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType); + pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType); + + PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG ); + PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG07); + // No D+/D– detection + Safety timer not slowed by 2X during input DPM or thermal regulation + + // BAT fet disabled/enabled + charge and bat fault INT + PERIPH_WIRE.sendDataMasterWIRE(0x0B | (disabled ? 0x20 : 0x00)); + PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP); + + PERIPH_WIRE.disableWIRE(); +} + +#endif + +void initVariant() { +#if defined(USE_BQ24195L_PMIC) + pinMode(ADC_BATTERY, OUTPUT); + digitalWrite(ADC_BATTERY, LOW); + delay(10); + pinMode(ADC_BATTERY, INPUT); + delay(100); + + bool batteryPresent = analogRead(ADC_BATTERY) > 600; + if (batteryPresent) { + enable_battery_charging(); + } + disable_battery_fet(!batteryPresent); +#endif + + // NINA - SPI boot + pinMode(NINA_GPIO0, OUTPUT); + digitalWrite(NINA_GPIO0, HIGH); + + // disable NINA + pinMode(NINA_RESETN, OUTPUT); + digitalWrite(NINA_RESETN, HIGH); +} + +// Serial1 +Uart Serial1(&sercom5, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX); + +void SERCOM5_Handler() +{ + Serial1.IrqHandler(); +} + +// Serial2 +Uart Serial2(&sercom2, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX, PIN_SERIAL2_RTS, PIN_SERIAL2_CTS); + +void SERCOM2_Handler() +{ + Serial2.IrqHandler(); +} diff --git a/variants/mkrwifi1010/variant.h b/variants/mkrwifi1010/variant.h new file mode 100644 index 00000000..272c2fde --- /dev/null +++ b/variants/mkrwifi1010/variant.h @@ -0,0 +1,214 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#pragma once + +// The definitions here needs a SAMD core >=1.6.10 +#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610 + +#include + +// General definitions +// ------------------- + +// Frequency of the board main oscillator +#define VARIANT_MAINOSC (32768ul) + +// Master clock frequency +#define VARIANT_MCK (48000000ul) + +// Pins +// ---- + +// Number of pins defined in PinDescription array +#define PINS_COUNT (26u) +#define NUM_DIGITAL_PINS (15u) +#define NUM_ANALOG_INPUTS (7u) +#define NUM_ANALOG_OUTPUTS (1u) + +// Low-level pin register query macros +// ----------------------------------- +#define digitalPinToPort(P) (&(PORT->Group[g_APinDescription[P].ulPort])) +#define digitalPinToBitMask(P) (1 << g_APinDescription[P].ulPin) +//#define analogInPinToBit(P) () +#define portOutputRegister(port) (&(port->OUT.reg)) +#define portInputRegister(port) (&(port->IN.reg)) +#define portModeRegister(port) (&(port->DIR.reg)) +#define digitalPinHasPWM(P) (g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER) + +/* + * digitalPinToTimer(..) is AVR-specific and is not defined for SAMD + * architecture. If you need to check if a pin supports PWM you must + * use digitalPinHasPWM(..). + * + * https://github.com/arduino/Arduino/issues/1833 + */ +// #define digitalPinToTimer(P) + +//Battery +#define ADC_BATTERY (32u) + +//NINA +#define NINA_GPIO0 (30u) +#define NINA_RESETN (31u) +#define NINA_ACK (35u) + +// LEDs +// ---- +#define PIN_LED (6u) +#define LED_BUILTIN PIN_LED + +// Analog pins +// ----------- +#define PIN_A0 (15u) +#define PIN_A1 (16u) +#define PIN_A2 (17u) +#define PIN_A3 (18u) +#define PIN_A4 (19u) +#define PIN_A5 (20u) +#define PIN_A6 (21u) +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +#define ADC_RESOLUTION 12 + +// SPI Interfaces +// -------------- +#define SPI_INTERFACES_COUNT 2 + +// SPI +#define PIN_SPI_MISO (10u) +#define PIN_SPI_MOSI (8u) +#define PIN_SPI_SCK (9u) +#define PIN_SPI_SS (4u) +#define PERIPH_SPI sercom1 +#define PAD_SPI_TX SPI_PAD_0_SCK_1 +#define PAD_SPI_RX SERCOM_RX_PAD_3 + +static const uint8_t SS = PIN_SPI_SS; // SPI Slave SS not used. Set here only for reference. +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +// SPI1 +#define PIN_SPI1_MISO (27u) +#define PIN_SPI1_MOSI (26u) +#define PIN_SPI1_SCK (29u) +#define PIN_SPI1_SS (28u) +#define PERIPH_SPI1 sercom2 +#define PAD_SPI1_TX SPI_PAD_0_SCK_3 +#define PAD_SPI1_RX SERCOM_RX_PAD_1 +static const uint8_t SS1 = PIN_SPI1_SS; +static const uint8_t MOSI1 = PIN_SPI1_MOSI; +static const uint8_t MISO1 = PIN_SPI1_MISO; +static const uint8_t SCK1 = PIN_SPI1_SCK; + +#define SPIWIFI_SS PIN_SPI1_SS +#define SPIWIFI_ACK NINA_ACK +#define SPIWIFI_RESET (~NINA_RESETN) // fixme! Inverted logic + + +// Wire Interfaces +// --------------- +#define WIRE_INTERFACES_COUNT 1 + +// Wire +#define PIN_WIRE_SDA (11u) +#define PIN_WIRE_SCL (12u) +#define PERIPH_WIRE sercom0 +#define WIRE_IT_HANDLER SERCOM0_Handler + +// USB +// --- +#define PIN_USB_DM (22ul) +#define PIN_USB_DP (23ul) +#define PIN_USB_HOST_ENABLE (24ul) + +// I2S Interfaces +// -------------- +#define I2S_INTERFACES_COUNT 1 + +#define I2S_DEVICE 0 +#define I2S_CLOCK_GENERATOR 3 +#define PIN_I2S_SD (PIN_A6) +#define PIN_I2S_SCK (2u) +#define PIN_I2S_FS (3u) + +// Serial ports +// ------------ +#ifdef __cplusplus +#include "SERCOM.h" +#include "Uart.h" + +// Instances of SERCOM +extern SERCOM sercom0; +extern SERCOM sercom1; +extern SERCOM sercom2; +extern SERCOM sercom3; +extern SERCOM sercom4; +extern SERCOM sercom5; + +// Serial1 +extern Uart Serial1; +#define PIN_SERIAL1_RX (13ul) +#define PIN_SERIAL1_TX (14ul) +#define PAD_SERIAL1_TX (UART_TX_PAD_2) +#define PAD_SERIAL1_RX (SERCOM_RX_PAD_3) + +// Serial2 +extern Uart Serial2; +#define PIN_SERIAL2_RX (27ul) +#define PIN_SERIAL2_TX (26ul) +#define PAD_SERIAL2_TX (UART_TX_RTS_CTS_PAD_0_2_3) +#define PAD_SERIAL2_RX (SERCOM_RX_PAD_1) +#define PIN_SERIAL2_RTS (28u) +#define PIN_SERIAL2_CTS (29u) + +#endif // __cplusplus + +// These serial port names are intended to allow libraries and architecture-neutral +// sketches to automatically default to the correct port name for a particular type +// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, +// the first hardware serial port whose RX/TX pins are not dedicated to another use. +// +// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor +// +// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial +// +// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library +// +// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. +// +// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX +// pins are NOT connected to anything by default. +#define SERIAL_PORT_USBVIRTUAL SerialUSB +#define SERIAL_PORT_MONITOR SerialUSB +#define SERIAL_PORT_HARDWARE Serial1 +#define SERIAL_PORT_HARDWARE_OPEN Serial1 + +// Alias Serial to SerialUSB +#define Serial SerialUSB + +// Alias Serial1 to SerialNina (useful in libraries) +#define SerialNina Serial1 + +#define SPIWIFI SPI1