summaryrefslogtreecommitdiffstats
path: root/tinyusb/hw/bsp/samg55xplained
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-08-28 12:50:18 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-08-28 12:50:18 -0400
commit39a5c822a2a2e798e2e39ff8a98b7af84253026c (patch)
treefa157c98d3aea0d4f996e4415aa2a7ad1093ac05 /tinyusb/hw/bsp/samg55xplained
parentc9e00b83bbdcb05058806d915ec4fff3cf4e596f (diff)
downloadSensor-Watch-39a5c822a2a2e798e2e39ff8a98b7af84253026c.tar.gz
Sensor-Watch-39a5c822a2a2e798e2e39ff8a98b7af84253026c.tar.bz2
Sensor-Watch-39a5c822a2a2e798e2e39ff8a98b7af84253026c.zip
add tinyusb
Diffstat (limited to 'tinyusb/hw/bsp/samg55xplained')
-rwxr-xr-xtinyusb/hw/bsp/samg55xplained/board.mk52
-rwxr-xr-xtinyusb/hw/bsp/samg55xplained/hpl_usart_config.h215
-rwxr-xr-xtinyusb/hw/bsp/samg55xplained/peripheral_clk_config.h85
-rwxr-xr-xtinyusb/hw/bsp/samg55xplained/samg55j19_flash.ld158
-rwxr-xr-xtinyusb/hw/bsp/samg55xplained/samg55xplained.c157
5 files changed, 667 insertions, 0 deletions
diff --git a/tinyusb/hw/bsp/samg55xplained/board.mk b/tinyusb/hw/bsp/samg55xplained/board.mk
new file mode 100755
index 00000000..aed4de68
--- /dev/null
+++ b/tinyusb/hw/bsp/samg55xplained/board.mk
@@ -0,0 +1,52 @@
+DEPS_SUBMODULES += hw/mcu/microchip
+
+CFLAGS += \
+ -flto \
+ -mthumb \
+ -mabi=aapcs \
+ -mcpu=cortex-m4 \
+ -mfloat-abi=hard \
+ -mfpu=fpv4-sp-d16 \
+ -nostdlib -nostartfiles \
+ -D__SAMG55J19__ \
+ -DCFG_TUSB_MCU=OPT_MCU_SAMG
+
+# suppress following warnings from mcu driver
+CFLAGS += -Wno-error=undef
+
+ASF_DIR = hw/mcu/microchip/samg55
+
+# All source paths should be relative to the top level.
+LD_FILE = hw/bsp/$(BOARD)/samg55j19_flash.ld
+
+SRC_C += \
+ src/portable/microchip/samg/dcd_samg.c \
+ $(ASF_DIR)/samg55/gcc/gcc/startup_samg55.c \
+ $(ASF_DIR)/samg55/gcc/system_samg55.c \
+ $(ASF_DIR)/hpl/core/hpl_init.c \
+ $(ASF_DIR)/hpl/usart/hpl_usart.c \
+ $(ASF_DIR)/hpl/pmc/hpl_pmc.c \
+ $(ASF_DIR)/hal/src/hal_atomic.c
+
+INC += \
+ $(TOP)/hw/bsp/$(BOARD) \
+ $(TOP)/$(ASF_DIR) \
+ $(TOP)/$(ASF_DIR)/config \
+ $(TOP)/$(ASF_DIR)/samg55/include \
+ $(TOP)/$(ASF_DIR)/hal/include \
+ $(TOP)/$(ASF_DIR)/hal/utils/include \
+ $(TOP)/$(ASF_DIR)/hpl/core \
+ $(TOP)/$(ASF_DIR)/hpl/pio \
+ $(TOP)/$(ASF_DIR)/hpl/pmc \
+ $(TOP)/$(ASF_DIR)/hri \
+ $(TOP)/$(ASF_DIR)/CMSIS/Core/Include
+
+# For freeRTOS port source
+FREERTOS_PORT = ARM_CM4F
+
+# For flash-jlink target
+JLINK_DEVICE = ATSAMG55J19
+
+# flash using edbg from https://github.com/ataradov/edbg
+flash: $(BUILD)/$(PROJECT).bin
+ edbg --verbose -t samg55 -pv -f $<
diff --git a/tinyusb/hw/bsp/samg55xplained/hpl_usart_config.h b/tinyusb/hw/bsp/samg55xplained/hpl_usart_config.h
new file mode 100755
index 00000000..4f2837d2
--- /dev/null
+++ b/tinyusb/hw/bsp/samg55xplained/hpl_usart_config.h
@@ -0,0 +1,215 @@
+/* Auto-generated config file hpl_usart_config.h */
+#ifndef HPL_USART_CONFIG_H
+#define HPL_USART_CONFIG_H
+
+// <<< Use Configuration Wizard in Context Menu >>>
+
+#include <peripheral_clk_config.h>
+
+#ifndef CONF_USART_7_ENABLE
+#define CONF_USART_7_ENABLE 1
+#endif
+
+// <h> Basic Configuration
+
+// <o> Frame parity
+// <0x0=>Even parity
+// <0x1=>Odd parity
+// <0x2=>Parity forced to 0
+// <0x3=>Parity forced to 1
+// <0x4=>No parity
+// <i> Parity bit mode for USART frame
+// <id> usart_parity
+#ifndef CONF_USART_7_PARITY
+#define CONF_USART_7_PARITY 0x4
+#endif
+
+// <o> Character Size
+// <0x0=>5 bits
+// <0x1=>6 bits
+// <0x2=>7 bits
+// <0x3=>8 bits
+// <i> Data character size in USART frame
+// <id> usart_character_size
+#ifndef CONF_USART_7_CHSIZE
+#define CONF_USART_7_CHSIZE 0x3
+#endif
+
+// <o> Stop Bit
+// <0=>1 stop bit
+// <1=>1.5 stop bits
+// <2=>2 stop bits
+// <i> Number of stop bits in USART frame
+// <id> usart_stop_bit
+#ifndef CONF_USART_7_SBMODE
+#define CONF_USART_7_SBMODE 0
+#endif
+
+// <o> Clock Output Select
+// <0=>The USART does not drive the SCK pin
+// <1=>The USART drives the SCK pin if USCLKS does not select the external clock SCK
+// <i> Clock Output Select in USART sck, if in usrt master mode, please drive SCK.
+// <id> usart_clock_output_select
+#ifndef CONF_USART_7_CLKO
+#define CONF_USART_7_CLKO 0
+#endif
+
+// <o> Baud rate <1-3000000>
+// <i> USART baud rate setting
+// <id> usart_baud_rate
+#ifndef CONF_USART_7_BAUD
+#define CONF_USART_7_BAUD 9600
+#endif
+
+// </h>
+
+// <e> Advanced configuration
+// <id> usart_advanced
+#ifndef CONF_USART_7_ADVANCED_CONFIG
+#define CONF_USART_7_ADVANCED_CONFIG 0
+#endif
+
+// <o> Channel Mode
+// <0=>Normal Mode
+// <1=>Automatic Echo
+// <2=>Local Loopback
+// <3=>Remote Loopback
+// <i> Channel mode in USART frame
+// <id> usart_channel_mode
+#ifndef CONF_USART_7_CHMODE
+#define CONF_USART_7_CHMODE 0
+#endif
+
+// <q> 9 bits character enable
+// <i> Enable 9 bits character, this has high priority than 5/6/7/8 bits.
+// <id> usart_9bits_enable
+#ifndef CONF_USART_7_MODE9
+#define CONF_USART_7_MODE9 0
+#endif
+
+// <o> Variable Sync
+// <0=>User defined configuration
+// <1=>sync field is updated when a character is written into US_THR
+// <i> Variable Synchronization of Command/Data Sync Start Frarm Delimiter
+// <id> variable_sync
+#ifndef CONF_USART_7_VAR_SYNC
+#define CONF_USART_7_VAR_SYNC 0
+#endif
+
+// <o> Oversampling Mode
+// <0=>16 Oversampling
+// <1=>8 Oversampling
+// <i> Oversampling Mode in UART mode
+// <id> usart__oversampling_mode
+#ifndef CONF_USART_7_OVER
+#define CONF_USART_7_OVER 0
+#endif
+
+// <o> Inhibit Non Ack
+// <0=>The NACK is generated
+// <1=>The NACK is not generated
+// <i> Inhibit Non Acknowledge
+// <id> usart__inack
+#ifndef CONF_USART_7_INACK
+#define CONF_USART_7_INACK 1
+#endif
+
+// <o> Disable Successive NACK
+// <0=>NACK is sent on the ISO line as soon as a parity error occurs
+// <1=>Many parity errors generate a NACK on the ISO line
+// <i> Disable Successive NACK
+// <id> usart_dsnack
+#ifndef CONF_USART_7_DSNACK
+#define CONF_USART_7_DSNACK 0
+#endif
+
+// <o> Inverted Data
+// <0=>Data isn't inverted, nomal mode
+// <1=>Data is inverted
+// <i> Inverted Data
+// <id> usart_invdata
+#ifndef CONF_USART_7_INVDATA
+#define CONF_USART_7_INVDATA 0
+#endif
+
+// <o> Maximum Number of Automatic Iteration <0-7>
+// <i> Defines the maximum number of iterations in mode ISO7816, protocol T = 0.
+// <id> usart_max_iteration
+#ifndef CONF_USART_7_MAX_ITERATION
+#define CONF_USART_7_MAX_ITERATION 0
+#endif
+
+// <q> Receive Line Filter enable
+// <i> whether the USART filters the receive line using a three-sample filter
+// <id> usart_receive_filter_enable
+#ifndef CONF_USART_7_FILTER
+#define CONF_USART_7_FILTER 0
+#endif
+
+// <q> Manchester Encoder/Decoder Enable
+// <i> whether the USART Manchester Encoder/Decoder
+// <id> usart_manchester_filter_enable
+#ifndef CONF_USART_7_MAN
+#define CONF_USART_7_MAN 0
+#endif
+
+// <o> Manchester Synchronization Mode
+// <0=>The Manchester start bit is a 0 to 1 transition
+// <1=>The Manchester start bit is a 1 to 0 transition
+// <i> Manchester Synchronization Mode
+// <id> usart_manchester_synchronization_mode
+#ifndef CONF_USART_7_MODSYNC
+#define CONF_USART_7_MODSYNC 0
+#endif
+
+// <o> Start Frame Delimiter Selector
+// <0=>Start frame delimiter is COMMAND or DATA SYNC
+// <1=>Start frame delimiter is one bit
+// <i> Start Frame Delimiter Selector
+// <id> usart_start_frame_delimiter
+#ifndef CONF_USART_7_ONEBIT
+#define CONF_USART_7_ONEBIT 0
+#endif
+
+// <o> Fractional Part <0-7>
+// <i> Fractional part of the baud rate if baud rate generator is in fractional mode
+// <id> usart_arch_fractional
+#ifndef CONF_USART_7_FRACTIONAL
+#define CONF_USART_7_FRACTIONAL 0x0
+#endif
+
+// <o> Data Order
+// <0=>LSB is transmitted first
+// <1=>MSB is transmitted first
+// <i> Data order of the data bits in the frame
+// <id> usart_arch_msbf
+#ifndef CONF_USART_7_MSBF
+#define CONF_USART_7_MSBF 0
+#endif
+
+// </e>
+
+#define CONF_USART_7_MODE 0x0
+
+// Calculate BAUD register value in UART mode
+#if CONF_FLEXCOM7_CK_SRC < 3
+#ifndef CONF_USART_7_BAUD_CD
+#define CONF_USART_7_BAUD_CD ((CONF_FLEXCOM7_FREQUENCY) / CONF_USART_7_BAUD / 8 / (2 - CONF_USART_7_OVER))
+#endif
+#ifndef CONF_USART_7_BAUD_FP
+#define CONF_USART_7_BAUD_FP \
+ ((CONF_FLEXCOM7_FREQUENCY) / CONF_USART_7_BAUD / (2 - CONF_USART_7_OVER) - 8 * CONF_USART_7_BAUD_CD)
+#endif
+#elif CONF_FLEXCOM7_CK_SRC == 3
+// No division is active. The value written in US_BRGR has no effect.
+#ifndef CONF_USART_7_BAUD_CD
+#define CONF_USART_7_BAUD_CD 1
+#endif
+#ifndef CONF_USART_7_BAUD_FP
+#define CONF_USART_7_BAUD_FP 1
+#endif
+#endif
+
+// <<< end of configuration section >>>
+
+#endif // HPL_USART_CONFIG_H
diff --git a/tinyusb/hw/bsp/samg55xplained/peripheral_clk_config.h b/tinyusb/hw/bsp/samg55xplained/peripheral_clk_config.h
new file mode 100755
index 00000000..6d390f38
--- /dev/null
+++ b/tinyusb/hw/bsp/samg55xplained/peripheral_clk_config.h
@@ -0,0 +1,85 @@
+/* Auto-generated config file peripheral_clk_config.h */
+#ifndef PERIPHERAL_CLK_CONFIG_H
+#define PERIPHERAL_CLK_CONFIG_H
+
+// <<< Use Configuration Wizard in Context Menu >>>
+
+/**
+ * \def CONF_HCLK_FREQUENCY
+ * \brief HCLK's Clock frequency
+ */
+#ifndef CONF_HCLK_FREQUENCY
+#define CONF_HCLK_FREQUENCY 8000000
+#endif
+
+/**
+ * \def CONF_FCLK_FREQUENCY
+ * \brief FCLK's Clock frequency
+ */
+#ifndef CONF_FCLK_FREQUENCY
+#define CONF_FCLK_FREQUENCY 8000000
+#endif
+
+/**
+ * \def CONF_CPU_FREQUENCY
+ * \brief CPU's Clock frequency
+ */
+#ifndef CONF_CPU_FREQUENCY
+#define CONF_CPU_FREQUENCY 8000000
+#endif
+
+/**
+ * \def CONF_SLCK_FREQUENCY
+ * \brief Slow Clock frequency
+ */
+#define CONF_SLCK_FREQUENCY 32768
+
+/**
+ * \def CONF_MCK_FREQUENCY
+ * \brief Master Clock frequency
+ */
+#define CONF_MCK_FREQUENCY 8000000
+
+// <o> USB Clock Source
+// <0=> USB Clock Controller (USB_48M)
+// <id> usb_clock_source
+// <i> Select the clock source for USB.
+#ifndef CONF_UDP_SRC
+#define CONF_UDP_SRC 0
+#endif
+
+/**
+ * \def CONF_UDP_FREQUENCY
+ * \brief UDP's Clock frequency
+ */
+#ifndef CONF_UDP_FREQUENCY
+#define CONF_UDP_FREQUENCY 48005120
+#endif
+
+// <h> FLEXCOM Clock Settings
+// <o> FLEXCOM Clock source
+// <0=> Master Clock (MCK)
+// <1=> MCK / 8
+// <2=> Programmable Clock Controller 6 (PMC_PCK6)
+// <2=> Programmable Clock Controller 7 (PMC_PCK7)
+// <3=> External Clock
+// <i> This defines the clock source for the FLEXCOM, PCK6 is used for FLEXCOM0/1/2/3 and PCK7 is used for FLEXCOM4/5/6/7
+// <id> flexcom_clock_source
+#ifndef CONF_FLEXCOM7_CK_SRC
+#define CONF_FLEXCOM7_CK_SRC 0
+#endif
+
+// <o> FLEXCOM External Clock Input on SCK <1-4294967295>
+// <i> Inputs the external clock frequency on SCK
+// <id> flexcom_clock_freq
+#ifndef CONF_FLEXCOM7_SCK_FREQ
+#define CONF_FLEXCOM7_SCK_FREQ 10000000
+#endif
+
+#ifndef CONF_FLEXCOM7_FREQUENCY
+#define CONF_FLEXCOM7_FREQUENCY 8000000
+#endif
+
+// <<< end of configuration section >>>
+
+#endif // PERIPHERAL_CLK_CONFIG_H
diff --git a/tinyusb/hw/bsp/samg55xplained/samg55j19_flash.ld b/tinyusb/hw/bsp/samg55xplained/samg55j19_flash.ld
new file mode 100755
index 00000000..21c0b5bc
--- /dev/null
+++ b/tinyusb/hw/bsp/samg55xplained/samg55j19_flash.ld
@@ -0,0 +1,158 @@
+/**
+ * \file
+ *
+ * \brief GCC linker script (flash) for ATSAMG55J19
+ *
+ * Copyright (c) 2017 Atmel Corporation, a wholly owned subsidiary of Microchip Technology Inc.
+ *
+ * \license_start
+ *
+ * \page License
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * \license_stop
+ *
+ */
+
+/*------------------------------------------------------------------------------
+ * Linker script for running in internal FLASH on the ATSAMG55J19
+ *----------------------------------------------------------------------------*/
+
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+
+/* Memory Spaces Definitions */
+MEMORY
+{
+ rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00080000 /* rom, 524288K */
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00028000 /* ram, 163840K */
+}
+
+/* The stack size used by the application. NOTE: you need to adjust according to your application. */
+STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
+
+/* The heapsize used by the application. NOTE: you need to adjust according to your application. */
+HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : DEFINED(__heap_size__) ? __heap_size__ : 0x0200;
+
+/* Section Definitions */
+SECTIONS
+{
+ .text :
+ {
+ . = ALIGN(4);
+ _sfixed = .;
+ KEEP(*(.vectors .vectors.*))
+ *(.text .text.* .gnu.linkonce.t.*)
+ *(.glue_7t) *(.glue_7)
+ *(.rodata .rodata* .gnu.linkonce.r.*)
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+
+ /* Support C constructors, and C destructors in both user code
+ and the C library. This also provides support for C++ code. */
+ . = ALIGN(4);
+ KEEP(*(.init))
+ . = ALIGN(4);
+ __preinit_array_start = .;
+ KEEP (*(.preinit_array))
+ __preinit_array_end = .;
+
+ . = ALIGN(4);
+ __init_array_start = .;
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ __init_array_end = .;
+
+ . = ALIGN(0x4);
+ KEEP (*crtbegin.o(.ctors))
+ KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*crtend.o(.ctors))
+
+ . = ALIGN(4);
+ KEEP(*(.fini))
+
+ . = ALIGN(4);
+ __fini_array_start = .;
+ KEEP (*(.fini_array))
+ KEEP (*(SORT(.fini_array.*)))
+ __fini_array_end = .;
+
+ KEEP (*crtbegin.o(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*crtend.o(.dtors))
+
+ . = ALIGN(4);
+ _efixed = .; /* End of text section */
+ } > rom
+
+ /* .ARM.exidx is sorted, so has to go in its own output section. */
+ PROVIDE_HIDDEN (__exidx_start = .);
+ .ARM.exidx :
+ {
+ *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+ } > rom
+ PROVIDE_HIDDEN (__exidx_end = .);
+
+ . = ALIGN(4);
+ _etext = .;
+
+ .relocate : AT (_etext)
+ {
+ . = ALIGN(4);
+ _srelocate = .;
+ *(.ramfunc .ramfunc.*);
+ *(.data .data.*);
+ . = ALIGN(4);
+ _erelocate = .;
+ } > ram
+
+ /* .bss section which is used for uninitialized data */
+ .bss (NOLOAD) :
+ {
+ . = ALIGN(4);
+ _sbss = . ;
+ _szero = .;
+ *(.bss .bss.*)
+ *(COMMON)
+ . = ALIGN(4);
+ _ebss = . ;
+ _ezero = .;
+ end = .;
+ } > ram
+
+ /* heap section */
+ .heap (NOLOAD):
+ {
+ . = ALIGN(8);
+ _sheap = .;
+ . = . + HEAP_SIZE;
+ . = ALIGN(8);
+ _eheap = .;
+ } > ram
+
+ /* stack section */
+ .stack (NOLOAD):
+ {
+ . = ALIGN(8);
+ _sstack = .;
+ . = . + STACK_SIZE;
+ . = ALIGN(8);
+ _estack = .;
+ } > ram
+
+ . = ALIGN(4);
+ _end = . ;
+ _ram_end_ = ORIGIN(ram) + LENGTH(ram) - 1 ;
+}
diff --git a/tinyusb/hw/bsp/samg55xplained/samg55xplained.c b/tinyusb/hw/bsp/samg55xplained/samg55xplained.c
new file mode 100755
index 00000000..ed106b06
--- /dev/null
+++ b/tinyusb/hw/bsp/samg55xplained/samg55xplained.c
@@ -0,0 +1,157 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019, hathach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "sam.h"
+#include "bsp/board.h"
+
+#include "peripheral_clk_config.h"
+#include "hal/include/hal_init.h"
+#include "hal/include/hpl_usart_sync.h"
+#include "hpl/pmc/hpl_pmc.h"
+#include "hal/include/hal_gpio.h"
+
+
+//--------------------------------------------------------------------+
+// MACRO TYPEDEF CONSTANT ENUM DECLARATION
+//--------------------------------------------------------------------+
+
+#define LED_PIN GPIO(GPIO_PORTA, 6)
+
+#define BUTTON_PIN GPIO(GPIO_PORTA, 2)
+#define BUTTON_STATE_ACTIVE 0
+
+#define UART_TX_PIN GPIO(GPIO_PORTA, 28)
+#define UART_RX_PIN GPIO(GPIO_PORTA, 27)
+
+struct _usart_sync_device edbg_com;
+
+//------------- IMPLEMENTATION -------------//
+void board_init(void)
+{
+ init_mcu();
+
+ _pmc_enable_periph_clock(ID_PIOA);
+
+ /* Disable Watchdog */
+ hri_wdt_set_MR_WDDIS_bit(WDT);
+
+ // LED
+ gpio_set_pin_level(LED_PIN, false);
+ gpio_set_pin_direction(LED_PIN, GPIO_DIRECTION_OUT);
+ gpio_set_pin_function(LED_PIN, GPIO_PIN_FUNCTION_OFF);
+
+ // Button
+ gpio_set_pin_direction(BUTTON_PIN, GPIO_DIRECTION_IN);
+ gpio_set_pin_pull_mode(BUTTON_PIN, GPIO_PULL_UP);
+ gpio_set_pin_function(BUTTON_PIN, GPIO_PIN_FUNCTION_OFF);
+
+ // Uart via EDBG Com
+ _pmc_enable_periph_clock(ID_FLEXCOM7);
+ gpio_set_pin_function(UART_RX_PIN, MUX_PA27B_FLEXCOM7_RXD);
+ gpio_set_pin_function(UART_TX_PIN, MUX_PA28B_FLEXCOM7_TXD);
+
+ _usart_sync_init(&edbg_com, FLEXCOM7);
+ _usart_sync_set_baud_rate(&edbg_com, CFG_BOARD_UART_BAUDRATE);
+ _usart_sync_set_mode(&edbg_com, USART_MODE_ASYNCHRONOUS);
+ _usart_sync_enable(&edbg_com);
+
+#if CFG_TUSB_OS == OPT_OS_NONE
+ // 1ms tick timer (samd SystemCoreClock may not correct)
+ SysTick_Config(CONF_CPU_FREQUENCY / 1000);
+#endif
+
+ // USB Pin, Clock init
+
+ /* Clear SYSIO 10 & 11 for USB DM & DP */
+ hri_matrix_clear_CCFG_SYSIO_reg(MATRIX, CCFG_SYSIO_SYSIO10 | CCFG_SYSIO_SYSIO11);
+
+ // Enable clock
+ _pmc_enable_periph_clock(ID_UDP);
+
+ /* USB Device mode & Transceiver active */
+ hri_matrix_write_CCFG_USBMR_reg(MATRIX, CCFG_USBMR_USBMODE);
+}
+
+//--------------------------------------------------------------------+
+// USB Interrupt Handler
+//--------------------------------------------------------------------+
+void UDP_Handler(void)
+{
+ #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
+ tud_int_handler(0);
+ #endif
+}
+
+//--------------------------------------------------------------------+
+// Board porting API
+//--------------------------------------------------------------------+
+
+void board_led_write(bool state)
+{
+ gpio_set_pin_level(LED_PIN, state);
+}
+
+uint32_t board_button_read(void)
+{
+ return BUTTON_STATE_ACTIVE == gpio_get_pin_level(BUTTON_PIN);
+}
+
+int board_uart_read(uint8_t* buf, int len)
+{
+ (void) buf; (void) len;
+ return 0;
+}
+
+int board_uart_write(void const * buf, int len)
+{
+ uint8_t const * buf8 = (uint8_t const *) buf;
+ for(int i=0; i<len; i++)
+ {
+ while ( !_usart_sync_is_ready_to_send(&edbg_com) ) {}
+ _usart_sync_write_byte(&edbg_com, buf8[i]);
+ }
+ return len;
+}
+
+#if CFG_TUSB_OS == OPT_OS_NONE
+volatile uint32_t system_ticks = 0;
+
+void SysTick_Handler (void)
+{
+ system_ticks++;
+}
+
+uint32_t board_millis(void)
+{
+ return system_ticks;
+}
+#endif
+
+// Required by __libc_init_array in startup code if we are compiling using
+// -nostdlib/-nostartfiles.
+void _init(void)
+{
+
+}