summaryrefslogtreecommitdiff
path: root/hw/bsp
diff options
context:
space:
mode:
authorGordon McNab <[email protected]>2021-10-05 13:54:47 +0100
committerGordon McNab <[email protected]>2021-10-05 13:54:47 +0100
commit62c613f6d2d4e3e2cf0918f75e302d48a3df673e (patch)
tree3f5ff1055feae03c081448572536fb21305027ef /hw/bsp
parent36dc25a22d05cf9826944e363dd9ca4eb3416661 (diff)
Add initial port for FT9xx series from Bridgetek.
Add FT90X and FT93X to the list of devices in tusb_option.h. 1700 for FT90x and 1701 for FT93x. Set endpoint attributes for FT90x and FT93x in dcd_attr.h. Add FT90x routines for USB device in src/portable/bridgetek/ft90x/dcd_ft90x.c The location for hardware header files and libraries is hw/mcu/bridgetek/ft90x/hardware. There are no files in the repository, but files will be linked as a submodule in the future. The required files can be copied from or linked to the location "C:/Program Files(x86)/Bridgetek/FT9xx Toolchain/Toolchain/hardware" once the toolchain is installed. Makefile for the MM900EV1B board for developing with an FT900 device is present. Use "BOARD=mm900ev1b".
Diffstat (limited to 'hw/bsp')
-rw-r--r--hw/bsp/brtmm90x/boards/mm900ev1b/board.h56
-rw-r--r--hw/bsp/brtmm90x/family.c210
-rw-r--r--hw/bsp/brtmm90x/family.mk35
3 files changed, 301 insertions, 0 deletions
diff --git a/hw/bsp/brtmm90x/boards/mm900ev1b/board.h b/hw/bsp/brtmm90x/boards/mm900ev1b/board.h
new file mode 100644
index 000000000..dfb566289
--- /dev/null
+++ b/hw/bsp/brtmm90x/boards/mm900ev1b/board.h
@@ -0,0 +1,56 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2021, Ha Thach (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.
+ */
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#if defined(__FT900__)
+#define GPIO_UART0_TX 48
+#define GPIO_UART0_RX 49
+#define GPIO_ETH_LED0 61
+#define GPIO_ETH_LED1 62
+#define GPIO_REMOTE_WAKEUP_PIN 18
+#define USBD_VBUS_DTC_PIN 3
+#elif defined(__FT930__)
+#define GPIO_UART0_TX 23
+#define GPIO_UART0_RX 22
+#define GPIO_ETH_LED0 4
+#define GPIO_ETH_LED1 5
+#define GPIO_REMOTE_WAKEUP_PIN 12
+#define USBD_VBUS_DTC_PIN 39
+#endif
+
+//#define GPIO_REMOTE_WAKEUP
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
diff --git a/hw/bsp/brtmm90x/family.c b/hw/bsp/brtmm90x/family.c
new file mode 100644
index 000000000..010704d92
--- /dev/null
+++ b/hw/bsp/brtmm90x/family.c
@@ -0,0 +1,210 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright 2019 Sony Semiconductor Solutions Corporation
+ *
+ * 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 <registers/ft900_registers.h>
+#include <ft900.h>
+#include "bsp/board.h"
+#include "board.h"
+//#include "src/device/dcd.h"
+
+#if TUSB_OPT_DEVICE_ENABLED
+int8_t board_ft90x_vbus(void); // Board specific implementation of VBUS detection for USB device.
+extern void ft90x_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
+#endif
+
+#ifdef GPIO_REMOTE_WAKEUP
+void gpio_ISR(void);
+#endif
+void timer_ISR(void);
+volatile unsigned int timer_ms = 0;
+void board_pm_ISR(void);
+
+#define WELCOME_MSG "\x1B[2J\x1B[H" \
+ "MM900EV1B board\r\n"
+
+// Initialize on-board peripherals : led, button, uart and USB
+void board_init(void)
+{
+ sys_reset_all();
+ // Enable the UART Device.
+ sys_enable(sys_device_uart0);
+ // Set UART0 GPIO functions to UART0_TXD and UART0_RXD.
+ gpio_function(GPIO_UART0_TX, pad_uart0_txd); /* UART0 TXD */
+ gpio_function(GPIO_UART0_RX, pad_uart0_rxd); /* UART0 RXD */
+ uart_open(UART0, /* Device */
+ 1, /* Prescaler = 1 */
+ UART_DIVIDER_19200_BAUD, /* Divider = 1302 */
+ uart_data_bits_8, /* No. Data Bits */
+ uart_parity_none, /* Parity */
+ uart_stop_bits_1); /* No. Stop Bits */
+ // Print out a welcome message.
+ // Use sizeof to avoid pulling in strlen unnecessarily.
+ board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG));
+
+#if 1
+ gpio_function(GPIO_ETH_LED0, pad_gpio4); /* ETH LED0 */
+ gpio_dir(GPIO_ETH_LED0, pad_dir_open_drain);
+ gpio_function(GPIO_ETH_LED1, pad_gpio5); /* ETH LED0 */
+ gpio_dir(GPIO_ETH_LED1, pad_dir_output);
+#endif
+ sys_enable(sys_device_timer_wdt);
+ interrupt_attach(interrupt_timers, (int8_t)interrupt_timers, timer_ISR);
+ /* Timer A = 1ms */
+ timer_prescaler(timer_select_a, 1000);
+ timer_init(timer_select_a, 100, timer_direction_down, timer_prescaler_select_on, timer_mode_continuous);
+ timer_enable_interrupt(timer_select_a);
+ timer_start(timer_select_a);
+
+ // Setup VBUS detect GPIO. If the device is connected then this
+ // will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG.
+ gpio_interrupt_disable(USBD_VBUS_DTC_PIN);
+ gpio_function(USBD_VBUS_DTC_PIN, pad_vbus_dtc);
+ gpio_pull(USBD_VBUS_DTC_PIN, pad_pull_pulldown);
+ gpio_dir(USBD_VBUS_DTC_PIN, pad_dir_input);
+
+ interrupt_attach(interrupt_0, (int8_t)interrupt_0, board_pm_ISR);
+
+#ifdef GPIO_REMOTE_WAKEUP
+ //Configuring GPIO pin to wakeup.
+ // Set up the wakeup pin.
+ gpio_dir(GPIO_REMOTE_WAKEUP_PIN, pad_dir_input);
+ gpio_pull(GPIO_REMOTE_WAKEUP_PIN, pad_pull_pullup);
+
+ // Attach an interrupt handler.
+ interrupt_attach(interrupt_gpio, (uint8_t)interrupt_gpio, gpio_ISR);
+ gpio_interrupt_enable(GPIO_REMOTE_WAKEUP_PIN, gpio_int_edge_falling);
+#endif
+
+ uart_disable_interrupt(UART0, uart_interrupt_tx);
+ uart_disable_interrupt(UART0, uart_interrupt_rx);
+
+ // Enable all peripheral interrupts.
+ interrupt_enable_globally();
+
+ TU_LOG1("MM900EV1B board setup complete\r\n");
+};
+
+void timer_ISR(void)
+{
+ if (timer_is_interrupted(timer_select_a))
+ {
+ timer_ms++;
+ }
+}
+
+#ifdef GPIO_REMOTE_WAKEUP
+void gpio_ISR(void)
+{
+ if (gpio_is_interrupted(GPIO_REMOTE_WAKEUP_PIN))
+ {
+ }
+}
+#endif
+
+/* Power management ISR */
+void board_pm_ISR(void)
+{
+ uint16_t pmcfg = SYS->PMCFG_H;
+
+#if defined(__FT930__)
+ if (pmcfg & MASK_SYS_PMCFG_SLAVE_PERI_IRQ_PEND)
+ {
+ // Clear d2xx hw engine wakeup.
+ SYS->PMCFG_H = MASK_SYS_PMCFG_SLAVE_PERI_IRQ_PEND;
+ }
+#endif
+ if (pmcfg & MASK_SYS_PMCFG_PM_GPIO_IRQ_PEND)
+ {
+ // Clear GPIO wakeup pending.
+ SYS->PMCFG_H = MASK_SYS_PMCFG_PM_GPIO_IRQ_PEND;
+ }
+
+#if defined(__FT900__)
+ // USB device power management interrupts.
+ if (pmcfg & (MASK_SYS_PMCFG_DEV_CONN_DEV |
+ MASK_SYS_PMCFG_DEV_DIS_DEV |
+ MASK_SYS_PMCFG_HOST_RST_DEV |
+ MASK_SYS_PMCFG_HOST_RESUME_DEV)
+ )
+ {
+#if TUSB_OPT_DEVICE_ENABLED
+ ft90x_usbd_pm_ISR(pmcfg);
+#endif
+ }
+#endif
+}
+
+#if TUSB_OPT_DEVICE_ENABLED
+int8_t board_ft90x_vbus(void)
+{
+ return gpio_read(USBD_VBUS_DTC_PIN);
+}
+#endif
+
+//--------------------------------------------------------------------+
+// Board porting API
+//--------------------------------------------------------------------+
+
+// Turn LED on or off
+void board_led_write(bool state)
+{
+ gpio_write(GPIO_ETH_LED0, state);
+}
+
+// Get the current state of button
+// a '1' means active (pressed), a '0' means inactive.
+uint32_t board_button_read(void)
+{
+ return 0;
+}
+
+// Get characters from UART
+int board_uart_read(uint8_t *buf, int len)
+{
+ int r = uart_readn(UART0, (uint8_t *)buf, len);
+
+ return r;
+}
+
+// Send characters to UART
+int board_uart_write(void const *buf, int len)
+{
+ int r = uart_writen(UART0, (uint8_t *)buf, len);
+
+ return r;
+}
+
+// Get current milliseconds
+uint32_t board_millis(void)
+{
+ uint32_t safe_ms;
+
+ CRITICAL_SECTION_BEGIN
+ safe_ms = timer_ms;
+ CRITICAL_SECTION_END
+
+ return safe_ms;
+}
diff --git a/hw/bsp/brtmm90x/family.mk b/hw/bsp/brtmm90x/family.mk
new file mode 100644
index 000000000..57a141506
--- /dev/null
+++ b/hw/bsp/brtmm90x/family.mk
@@ -0,0 +1,35 @@
+
+CROSS_COMPILE = ft32-elf-
+DEPS_SUBMODULES += hw/mcu/bridgetek/ft90x/hardware
+SKIP_NANOLIB = 1
+
+# This is installed at "C:/Program Files(x86)/Bridgetek/FT9xx Toolchain/Toolchain/hardware"
+FT90X_SDK = $(TOP)/hw/mcu/bridgetek/ft90x/hardware
+
+CFLAGS += \
+ -D__FT900__ \
+ -fvar-tracking \
+ -fvar-tracking-assignments \
+ -fmessage-length=0 \
+ -ffunction-sections \
+ -DCFG_TUSB_MCU=OPT_MCU_FT90X
+
+# lwip/src/core/raw.c:334:43: error: declaration of 'recv' shadows a global declaration
+CFLAGS += -Wno-error=shadow
+CFLAGS:=$(filter-out -Wcast-function-type,$(CFLAGS))
+
+# All source paths should be relative to the top level.
+LDINC += $(FT90X_SDK)/lib/Release
+LIBS += -lft900
+LD_FILE = hw/mcu/bridgetek/ft90x/hardware/scripts/ldscript.ld
+LDFLAGS += $(addprefix -L,$(LDINC)) \
+ -Xlinker --entry=_start \
+ -Wl,-lc
+
+SRC_C += src/portable/bridgetek/ft90x/dcd_ft90x.c
+
+#SRC_S += hw/mcu/bridgetek/ft90x/hardware/scripts/crt0.S
+
+INC += \
+ $(FT90X_SDK)/include \
+ $(TOP)/$(BOARD_PATH)