summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-11-04 14:54:04 +0700
committerhathach <[email protected]>2019-11-04 14:54:04 +0700
commit6baa79b3308d4637f7a22ad73a5ac26f9ef6b491 (patch)
treec2a5b1b698070e6f618b6fad7adae8541bfc41c2
parente2b6f8c92bdf04036b4269d77f561869cf4da9fe (diff)
board test works
-rw-r--r--hw/bsp/samg55xplained/board.mk50
-rw-r--r--hw/bsp/samg55xplained/samg55xplained.c114
-rw-r--r--src/portable/template/dcd_template.c116
-rw-r--r--src/tusb_option.h2
4 files changed, 282 insertions, 0 deletions
diff --git a/hw/bsp/samg55xplained/board.mk b/hw/bsp/samg55xplained/board.mk
new file mode 100644
index 000000000..a8d2b0fe9
--- /dev/null
+++ b/hw/bsp/samg55xplained/board.mk
@@ -0,0 +1,50 @@
+CFLAGS += \
+ -D__SAMG55J19__ \
+ -mthumb \
+ -mabi=aapcs \
+ -mcpu=cortex-m4 \
+ -mfloat-abi=hard \
+ -mfpu=fpv4-sp-d16 \
+ -nostdlib -nostartfiles \
+ -DCFG_TUSB_MCU=OPT_MCU_NONE
+
+#CFLAGS += -Wno-error=undef
+
+ASF_DIR = hw/mcu/microchip/samg
+
+# All source paths should be relative to the top level.
+LD_FILE = $(ASF_DIR)/samg55/gcc/gcc/samg55j19_flash.ld
+
+SRC_C += \
+ $(ASF_DIR)/samg55/gcc/gcc/startup_samg55j19.c \
+ $(ASF_DIR)/samg55/gcc/system_samg55j19.c \
+ $(ASF_DIR)/hpl/core/hpl_init.c \
+ $(ASF_DIR)/hpl/pmc/hpl_pmc.c \
+ $(ASF_DIR)/hal/src/hal_atomic.c
+
+INC += \
+ $(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 TinyUSB port source
+VENDOR = .
+CHIP_FAMILY = template
+
+# For freeRTOS port source
+FREERTOS_PORT = ARM_CM4F
+
+# For flash-jlink target
+JLINK_DEVICE = ATSAMD51J19
+JLINK_IF = swd
+
+# flash using edbg from https://github.com/ataradov/edbg
+flash: $(BUILD)/$(BOARD)-firmware.bin
+ edbg --verbose -t samg55 -pv -f $<
diff --git a/hw/bsp/samg55xplained/samg55xplained.c b/hw/bsp/samg55xplained/samg55xplained.c
new file mode 100644
index 000000000..e1bc9c4cc
--- /dev/null
+++ b/hw/bsp/samg55xplained/samg55xplained.c
@@ -0,0 +1,114 @@
+/*
+ * 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 "peripheral_clk_config.h"
+#include "hal/include/hal_init.h"
+#include "hpl/pmc/hpl_pmc.h"
+#include "hal/include/hal_gpio.h"
+
+#include "bsp/board.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
+
+//------------- 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);
+
+#if CFG_TUSB_OS == OPT_OS_NONE
+ // 1ms tick timer (samd SystemCoreClock may not correct)
+ SysTick_Config(CONF_CPU_FREQUENCY / 1000);
+#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)
+{
+ (void) buf; (void) len;
+ return 0;
+}
+
+#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)
+{
+
+}
diff --git a/src/portable/template/dcd_template.c b/src/portable/template/dcd_template.c
new file mode 100644
index 000000000..102910509
--- /dev/null
+++ b/src/portable/template/dcd_template.c
@@ -0,0 +1,116 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018, 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.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+
+#include "tusb_option.h"
+
+#if CFG_TUSB_MCU == OPT_MCU_NONE
+
+#include "device/dcd.h"
+
+//--------------------------------------------------------------------+
+// MACRO TYPEDEF CONSTANT ENUM DECLARATION
+//--------------------------------------------------------------------+
+
+
+/*------------------------------------------------------------------*/
+/* Device API
+ *------------------------------------------------------------------*/
+
+// Initialize controller to device mode
+void dcd_init (uint8_t rhport)
+{
+ (void) rhport;
+}
+
+// Enable device interrupt
+void dcd_int_enable (uint8_t rhport)
+{
+ (void) rhport;
+}
+
+// Disable device interrupt
+void dcd_int_disable (uint8_t rhport)
+{
+ (void) rhport;
+}
+
+// Receive Set Address request, mcu port must also include status IN response
+void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
+{
+ (void) rhport;
+ (void) dev_addr;
+}
+
+// Receive Set Configure request
+void dcd_set_config (uint8_t rhport, uint8_t config_num)
+{
+ (void) rhport;
+ (void) config_num;
+}
+
+// Wake up host
+void dcd_remote_wakeup (uint8_t rhport)
+{
+ (void) rhport;
+}
+
+//--------------------------------------------------------------------+
+// Endpoint API
+//--------------------------------------------------------------------+
+
+// Configure endpoint's registers according to descriptor
+bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
+{
+ (void) rhport;
+ (void) ep_desc;
+ return false;
+}
+
+// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
+bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
+{
+ (void) rhport;
+ (void) ep_addr;
+ (void) buffer;
+ (void) total_bytes;
+ return false;
+}
+
+// Stall endpoint
+void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
+{
+ (void) rhport;
+ (void) ep_addr;
+}
+
+// clear stall, data toggle is also reset to DATA0
+void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
+{
+ (void) rhport;
+ (void) ep_addr;
+}
+
+#endif
diff --git a/src/tusb_option.h b/src/tusb_option.h
index fc509ae76..5700bc8a5 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -36,6 +36,8 @@
* \ref CFG_TUSB_MCU must be defined to one of these
* @{ */
+#define OPT_MCU_NONE 0
+
// LPC
#define OPT_MCU_LPC11UXX 1 ///< NXP LPC11Uxx
#define OPT_MCU_LPC13XX 2 ///< NXP LPC13xx