[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/target/stm32f746g-disco/include/target/debugconfig.h b/src/bsp/lk/target/stm32f746g-disco/include/target/debugconfig.h
new file mode 100644
index 0000000..88ffe5f
--- /dev/null
+++ b/src/bsp/lk/target/stm32f746g-disco/include/target/debugconfig.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * 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.
+ */
+#ifndef __TARGET_DEBUGCONFIG_H
+#define __TARGET_DEBUGCONFIG_H
+
+#define DEBUG_UART 1
+
+#endif
diff --git a/src/bsp/lk/target/stm32f746g-disco/include/target/gpioconfig.h b/src/bsp/lk/target/stm32f746g-disco/include/target/gpioconfig.h
new file mode 100644
index 0000000..c5d3d81
--- /dev/null
+++ b/src/bsp/lk/target/stm32f746g-disco/include/target/gpioconfig.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * 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.
+ */
+#ifndef __TARGET_GPIOCONFIG_H
+#define __TARGET_GPIOCONFIG_H
+
+#include <platform/gpio.h>
+
+#define GPIO_USART1_TX GPIO(GPIO_PORT_A, 9)
+#define GPIO_USART1_RX GPIO(GPIO_PORT_B, 7)
+
+#endif
diff --git a/src/bsp/lk/target/stm32f746g-disco/init.c b/src/bsp/lk/target/stm32f746g-disco/init.c
new file mode 100644
index 0000000..f311a26
--- /dev/null
+++ b/src/bsp/lk/target/stm32f746g-disco/init.c
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 2015 Travis Geiselbrecht
+ *
+ * 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 <err.h>
+#include <stdlib.h>
+#include <debug.h>
+#include <trace.h>
+#include <target.h>
+#include <compiler.h>
+#include <reg.h>
+#include <dev/gpio.h>
+#include <dev/usb.h>
+#include <platform/stm32.h>
+#include <platform/sdram.h>
+#include <platform/gpio.h>
+#include <platform/eth.h>
+#include <platform/qspi.h>
+#include <platform/n25q128a.h>
+#include <target/debugconfig.h>
+#include <target/gpioconfig.h>
+#include <kernel/novm.h>
+
+#if WITH_LIB_MINIP
+#include <lib/minip.h>
+#endif
+
+extern uint8_t BSP_LCD_Init(void);
+extern void target_usb_setup(void);
+
+const sdram_config_t target_sdram_config = {
+ .bus_width = SDRAM_BUS_WIDTH_16,
+ .cas_latency = SDRAM_CAS_LATENCY_2,
+ .col_bits_num = SDRAM_COLUMN_BITS_8
+};
+
+void target_early_init(void)
+{
+#if DEBUG_UART == 1
+ /* configure usart 1 pins */
+ gpio_config(GPIO_USART1_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
+ gpio_config(GPIO_USART1_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
+#else
+#error need to configure gpio pins for debug uart
+#endif
+
+ /* now that the uart gpios are configured, enable the debug uart */
+ stm32_debug_early_init();
+
+ /* start the lcd */
+ BSP_LCD_Init();
+}
+
+void target_init(void)
+{
+ stm32_debug_init();
+
+ qspi_flash_init(N25Q128A_FLASH_SIZE);
+
+#if WITH_LIB_MINIP
+ uint8_t mac_addr[6];
+ gen_random_mac_address(mac_addr);
+ eth_init(mac_addr, PHY_LAN8742A);
+
+ /* start minip */
+ minip_set_macaddr(mac_addr);
+
+ uint32_t ip_addr = IPV4(192, 168, 0, 98);
+ uint32_t ip_mask = IPV4(255, 255, 255, 0);
+ uint32_t ip_gateway = IPV4_NONE;
+
+ minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
+#endif
+
+ // start usb
+ target_usb_setup();
+}
+
+/**
+ * @brief Initializes SDRAM GPIO.
+ * called back from stm32_sdram_init
+ */
+void stm_sdram_GPIO_init(void)
+{
+ GPIO_InitTypeDef gpio_init_structure;
+
+ /* Enable GPIOs clock */
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOF_CLK_ENABLE();
+ __HAL_RCC_GPIOG_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+
+ /* Common GPIO configuration */
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Pull = GPIO_PULLUP;
+ gpio_init_structure.Speed = GPIO_SPEED_FAST;
+ gpio_init_structure.Alternate = GPIO_AF12_FMC;
+
+ /* GPIOC configuration */
+ gpio_init_structure.Pin = GPIO_PIN_3;
+ HAL_GPIO_Init(GPIOC, &gpio_init_structure);
+
+ /* GPIOD configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_8| GPIO_PIN_9 | GPIO_PIN_10 |\
+ GPIO_PIN_14 | GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOD, &gpio_init_structure);
+
+ /* GPIOE configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7| GPIO_PIN_8 | GPIO_PIN_9 |\
+ GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
+ GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOE, &gpio_init_structure);
+
+ /* GPIOF configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
+ GPIO_PIN_5 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
+ GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOF, &gpio_init_structure);
+
+ /* GPIOG configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4| GPIO_PIN_5 | GPIO_PIN_8 |\
+ GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOG, &gpio_init_structure);
+
+ /* GPIOH configuration */
+ gpio_init_structure.Pin = GPIO_PIN_3 | GPIO_PIN_5;
+ HAL_GPIO_Init(GPIOH, &gpio_init_structure);
+}
+
+
+/**
+ * @brief Initializes the ETH MSP.
+ * @param heth: ETH handle
+ * @retval None
+ */
+/* called back from the HAL_ETH_Init routine */
+void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIOs clocks */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOG_CLK_ENABLE();
+
+ /* Ethernet pins configuration ************************************************/
+ /*
+ RMII_REF_CLK ----------------------> PA1
+ RMII_MDIO -------------------------> PA2
+ RMII_MDC --------------------------> PC1
+ RMII_MII_CRS_DV -------------------> PA7
+ RMII_MII_RXD0 ---------------------> PC4
+ RMII_MII_RXD1 ---------------------> PC5
+ RMII_MII_TX_EN --------------------> PG11
+ RMII_MII_TXD0 ---------------------> PG13
+ RMII_MII_TXD1 ---------------------> PG14
+ */
+
+ /* Configure PA1, PA2 and PA7 */
+ GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStructure.Pull = GPIO_NOPULL;
+ GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
+ GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ /* Configure PC1, PC4 and PC5 */
+ GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /* Configure PG2, PG11, PG13 and PG14 */
+ GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14;
+ HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
+}
+
+void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ /*##-1- Enable peripherals and GPIO Clocks #################################*/
+ /* Enable GPIO clocks */
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+
+ /*##-2- Configure peripheral GPIO ##########################################*/
+ /* QSPI CS GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_6;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* QSPI CLK GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* QSPI D0 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_11;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /* QSPI D1 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_12;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /* QSPI D2 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
+
+ /* QSPI D3 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_13;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+}
+
+/**
+ * @brief Initializes the PCD MSP.
+ * @param hpcd: PCD handle
+ * @retval None
+ */
+void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ if (hpcd->Instance == USB_OTG_FS) {
+ /* Configure USB FS GPIOs */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+
+ /* Configure DM DP Pins */
+ GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* Enable USB FS Clock */
+ __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+
+ /* Set USBFS Interrupt priority */
+ HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
+
+ /* Enable USBFS Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
+
+ if (hpcd->Init.low_power_enable == 1) {
+ /* Enable EXTI Line 18 for USB wakeup*/
+ __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG();
+ __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
+ __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
+
+ /* Set EXTI Wakeup Interrupt priority*/
+ HAL_NVIC_SetPriority(OTG_FS_WKUP_IRQn, 0, 0);
+
+ /* Enable EXTI Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_FS_WKUP_IRQn);
+ }
+ } else if (hpcd->Instance == USB_OTG_HS) {
+ /* Configure USB FS GPIOs */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+
+ /* CLK */
+ GPIO_InitStruct.Pin = GPIO_PIN_5;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* D0 */
+ GPIO_InitStruct.Pin = GPIO_PIN_3;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* D1 D2 D3 D4 D5 D6 D7 */
+ GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\
+ GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* STP */
+ GPIO_InitStruct.Pin = GPIO_PIN_0;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ /* NXT */
+ GPIO_InitStruct.Pin = GPIO_PIN_4;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
+
+ /* DIR */
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
+
+ /* Enable USB HS Clocks */
+ __HAL_RCC_USB_OTG_HS_CLK_ENABLE();
+
+ /* Set USBHS Interrupt to the lowest priority */
+ HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0);
+
+ /* Enable USBHS Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
+ }
+}
+
diff --git a/src/bsp/lk/target/stm32f746g-disco/lcd.c b/src/bsp/lk/target/stm32f746g-disco/lcd.c
new file mode 100644
index 0000000..25b26b8
--- /dev/null
+++ b/src/bsp/lk/target/stm32f746g-disco/lcd.c
@@ -0,0 +1,425 @@
+/*
+ * Copyright (c) 2015 Carlos Pizano-Uribe <cpu@chromium.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.
+ */
+/*
+ * COPYRIGHT(c) 2015 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include <err.h>
+#include <debug.h>
+#include <trace.h>
+#include <target.h>
+#include <compiler.h>
+#include <string.h>
+#include <lib/gfx.h>
+#include <dev/gpio.h>
+#include <dev/display.h>
+#include <kernel/novm.h>
+#include <platform/stm32.h>
+
+/*
+ * lcd initialization sequence, taken from
+ * STM32Cube_FW_F7_V1.1.0/Drivers/BSP/STM32746G_Disco/stm32746g_discovery_lcd.[ch]
+ *
+ * This code only applies to The RK043FN48H LCD 480x272.
+ */
+
+/**
+ * @brief RK043FN48H Size
+ */
+#define RK043FN48H_WIDTH ((uint16_t)480) /* LCD PIXEL WIDTH */
+#define RK043FN48H_HEIGHT ((uint16_t)272) /* LCD PIXEL HEIGHT */
+
+/**
+ * @brief RK043FN48H Timing
+ */
+#define RK043FN48H_HSYNC ((uint16_t)41) /* Horizontal synchronization */
+#define RK043FN48H_HBP ((uint16_t)13) /* Horizontal back porch */
+#define RK043FN48H_HFP ((uint16_t)32) /* Horizontal front porch */
+#define RK043FN48H_VSYNC ((uint16_t)10) /* Vertical synchronization */
+#define RK043FN48H_VBP ((uint16_t)2) /* Vertical back porch */
+#define RK043FN48H_VFP ((uint16_t)2) /* Vertical front porch */
+
+
+/**
+ * @brief LCD special pins
+ */
+/* Display enable pin */
+#define LCD_DISP_PIN GPIO_PIN_12
+#define LCD_DISP_GPIO_PORT GPIOI
+/* Backlight control pin */
+#define LCD_BL_CTRL_PIN GPIO_PIN_3
+#define LCD_BL_CTRL_GPIO_PORT GPIOK
+
+#define LCD_DISP_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
+#define LCD_DISP_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
+#define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
+#define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
+
+/**
+ * @brief RK043FN48H frequency divider
+ */
+#define RK043FN48H_FREQUENCY_DIVIDER 5 /* LCD Frequency divider */
+
+/** @defgroup STM32746G_DISCOVERY_LCD_Exported_Constants
+ * @{
+ */
+#define MAX_LAYER_NUMBER ((uint32_t)2)
+
+#define LCD_LayerCfgTypeDef LTDC_LayerCfgTypeDef
+
+#define LTDC_ACTIVE_LAYER ((uint32_t)1) /* Layer 1 */
+/**
+ * @brief LCD status structure definition
+ */
+#define LCD_OK ((uint8_t)0x00)
+#define LCD_ERROR ((uint8_t)0x01)
+#define LCD_TIMEOUT ((uint8_t)0x02)
+
+
+static LTDC_HandleTypeDef ltdc_handle;
+
+/* Default LCD configuration with LCD Layer 1 */
+static uint32_t active_layer = 0;
+
+/**
+ * @brief Gets the LCD X size.
+ * @retval Used LCD X size
+ */
+static uint32_t BSP_LCD_GetXSize(void)
+{
+ return ltdc_handle.LayerCfg[active_layer].ImageWidth;
+}
+
+/**
+ * @brief Gets the LCD Y size.
+ * @retval Used LCD Y size
+ */
+static uint32_t BSP_LCD_GetYSize(void)
+{
+ return ltdc_handle.LayerCfg[active_layer].ImageHeight;
+}
+
+static size_t BSP_LCD_PixelSize(void)
+{
+ return (ltdc_handle.LayerCfg[active_layer].PixelFormat ==
+ LTDC_PIXEL_FORMAT_ARGB8888) ? 4 : 2;
+}
+
+/**
+ * @brief Initializes the LCD layer in ARGB8888 format (32 bits per pixel).
+ * @param LayerIndex: Layer foreground or background
+ * @param FB_Address: Layer frame buffer
+ * @retval None
+ */
+static void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
+{
+ LCD_LayerCfgTypeDef layer_cfg;
+
+ /* Layer Init */
+ layer_cfg.WindowX0 = 0;
+ layer_cfg.WindowX1 = BSP_LCD_GetXSize();
+ layer_cfg.WindowY0 = 0;
+ layer_cfg.WindowY1 = BSP_LCD_GetYSize();
+ layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
+ layer_cfg.FBStartAdress = FB_Address;
+ layer_cfg.Alpha = 255;
+ layer_cfg.Alpha0 = 0;
+ layer_cfg.Backcolor.Blue = 0;
+ layer_cfg.Backcolor.Green = 0;
+ layer_cfg.Backcolor.Red = 0;
+ layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
+ layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
+ layer_cfg.ImageWidth = BSP_LCD_GetXSize();
+ layer_cfg.ImageHeight = BSP_LCD_GetYSize();
+
+ HAL_LTDC_ConfigLayer(<dc_handle, &layer_cfg, LayerIndex);
+}
+
+/**
+ * @brief Selects the LCD Layer.
+ * @param LayerIndex: Layer foreground or background
+ * @retval None
+ */
+void BSP_LCD_SelectLayer(uint32_t LayerIndex)
+{
+ active_layer = LayerIndex;
+}
+
+/**
+ * @brief Sets an LCD Layer visible
+ * @param LayerIndex: Visible Layer
+ * @param State: New state of the specified layer
+ * This parameter can be one of the following values:
+ * @arg ENABLE
+ * @arg DISABLE
+ * @retval None
+ */
+void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
+{
+ if(State == ENABLE) {
+ __HAL_LTDC_LAYER_ENABLE(<dc_handle, LayerIndex);
+ } else {
+ __HAL_LTDC_LAYER_DISABLE(<dc_handle, LayerIndex);
+ }
+ __HAL_LTDC_RELOAD_CONFIG(<dc_handle);
+}
+
+/**
+ * @brief Sets an LCD layer frame buffer address.
+ * @param LayerIndex: Layer foreground or background
+ * @param Address: New LCD frame buffer value
+ * @retval None
+ */
+void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
+{
+ HAL_LTDC_SetAddress(<dc_handle, Address, LayerIndex);
+}
+
+/**
+ * @brief Enables the display.
+ * @retval None
+ */
+void BSP_LCD_DisplayOn(void)
+{
+ /* Display On */
+ __HAL_LTDC_ENABLE(<dc_handle);
+ HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET);
+ HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET);
+}
+
+/**
+ * @brief Disables the display.
+ * @retval None
+ */
+void BSP_LCD_DisplayOff(void)
+{
+ /* Display Off */
+ __HAL_LTDC_DISABLE(<dc_handle);
+ HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_RESET);
+ HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_RESET);
+}
+
+/**
+ * @brief Initializes the LTDC MSP.
+ * @param hltdc: LTDC handle
+ * @param Params
+ * @retval None
+ */
+static void BSP_LCD_MspInit(LTDC_HandleTypeDef *hltdc, void *Params)
+{
+ GPIO_InitTypeDef gpio_init_structure;
+
+ /* Enable the LTDC and DMA2D clocks */
+ __HAL_RCC_LTDC_CLK_ENABLE();
+ __HAL_RCC_DMA2D_CLK_ENABLE();
+
+ /* Enable GPIOs clock */
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOG_CLK_ENABLE();
+ __HAL_RCC_GPIOI_CLK_ENABLE();
+ __HAL_RCC_GPIOJ_CLK_ENABLE();
+ __HAL_RCC_GPIOK_CLK_ENABLE();
+ LCD_DISP_GPIO_CLK_ENABLE();
+ LCD_BL_CTRL_GPIO_CLK_ENABLE();
+
+ /*** LTDC Pins configuration ***/
+ /* GPIOE configuration */
+ gpio_init_structure.Pin = GPIO_PIN_4;
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Pull = GPIO_NOPULL;
+ gpio_init_structure.Speed = GPIO_SPEED_FAST;
+ gpio_init_structure.Alternate = GPIO_AF14_LTDC;
+ HAL_GPIO_Init(GPIOE, &gpio_init_structure);
+
+ /* GPIOG configuration */
+ gpio_init_structure.Pin = GPIO_PIN_12;
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Alternate = GPIO_AF9_LTDC;
+ HAL_GPIO_Init(GPIOG, &gpio_init_structure);
+
+ /* GPIOI LTDC alternate configuration */
+ gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | \
+ GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Alternate = GPIO_AF14_LTDC;
+ HAL_GPIO_Init(GPIOI, &gpio_init_structure);
+
+ /* GPIOJ configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | \
+ GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | \
+ GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \
+ GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Alternate = GPIO_AF14_LTDC;
+ HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
+
+ /* GPIOK configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | \
+ GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Alternate = GPIO_AF14_LTDC;
+ HAL_GPIO_Init(GPIOK, &gpio_init_structure);
+
+ /* LCD_DISP GPIO configuration
+ Note that LCD_DISP pin has to be manually controlled.
+ */
+ gpio_init_structure.Pin = LCD_DISP_PIN;
+ gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
+ HAL_GPIO_Init(LCD_DISP_GPIO_PORT, &gpio_init_structure);
+
+ /* LCD_BL_CTRL GPIO configuration
+ Note that LCD_BL_CTRL pin has to be manually controlled.
+ */
+ gpio_init_structure.Pin = LCD_BL_CTRL_PIN;
+ gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
+ HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &gpio_init_structure);
+}
+
+/**
+ * @brief Clock Config.
+ * @param hltdc: LTDC handle
+ * @param Params
+ * @note This API is called by BSP_LCD_Init()
+ * @retval None
+ */
+static void BSP_LCD_ClockConfig(LTDC_HandleTypeDef *hltdc, void *Params)
+{
+ static RCC_PeriphCLKInitTypeDef periph_clk_init_struct;
+
+ /* RK043FN48H LCD clock configuration */
+ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
+ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
+ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/5 = 38.4 Mhz */
+ /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_4 = 38.4/4 = 9.6Mhz */
+ periph_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
+ periph_clk_init_struct.PLLSAI.PLLSAIN = 192;
+ periph_clk_init_struct.PLLSAI.PLLSAIR = RK043FN48H_FREQUENCY_DIVIDER;
+ periph_clk_init_struct.PLLSAIDivR = RCC_PLLSAIDIVR_4;
+ HAL_RCCEx_PeriphCLKConfig(&periph_clk_init_struct);
+}
+
+/**
+ * @brief Initializes the LCD.
+ * @retval LCD state
+ */
+uint8_t BSP_LCD_Init(void)
+{
+ /* Timing Configuration */
+ ltdc_handle.Init.HorizontalSync = (RK043FN48H_HSYNC - 1);
+ ltdc_handle.Init.VerticalSync = (RK043FN48H_VSYNC - 1);
+ ltdc_handle.Init.AccumulatedHBP = (RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
+ ltdc_handle.Init.AccumulatedVBP = (RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
+ ltdc_handle.Init.AccumulatedActiveH = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
+ ltdc_handle.Init.AccumulatedActiveW = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
+ ltdc_handle.Init.TotalHeigh = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP + RK043FN48H_VFP - 1);
+ ltdc_handle.Init.TotalWidth = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP + RK043FN48H_HFP - 1);
+
+ /* LCD clock configuration */
+ BSP_LCD_ClockConfig(<dc_handle, NULL);
+
+ /* Initialize the LCD pixel width and pixel height */
+ ltdc_handle.LayerCfg->ImageWidth = RK043FN48H_WIDTH;
+ ltdc_handle.LayerCfg->ImageHeight = RK043FN48H_HEIGHT;
+
+ /* Background value */
+ ltdc_handle.Init.Backcolor.Blue = 0;
+ ltdc_handle.Init.Backcolor.Green = 0;
+ ltdc_handle.Init.Backcolor.Red = 0;
+
+ /* Polarity */
+ ltdc_handle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
+ ltdc_handle.Init.VSPolarity = LTDC_VSPOLARITY_AL;
+ ltdc_handle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
+ ltdc_handle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
+ ltdc_handle.Instance = LTDC;
+
+ if (HAL_LTDC_GetState(<dc_handle) == HAL_LTDC_STATE_RESET) {
+ BSP_LCD_MspInit(<dc_handle, NULL);
+ }
+
+ HAL_LTDC_Init(<dc_handle);
+
+ /* allocate the framebuffer */
+ size_t fb_size_pages = PAGE_ALIGN(RK043FN48H_WIDTH * RK043FN48H_HEIGHT * 4) / PAGE_SIZE;
+ void *fb_address = novm_alloc_pages(fb_size_pages, NOVM_ARENA_SECONDARY);
+ if (!fb_address)
+ panic("failed to allocate framebuffer for LCD\n");
+
+ BSP_LCD_LayerDefaultInit(0, (uint32_t)fb_address);
+ BSP_LCD_SelectLayer(0);
+
+ /* clear framebuffer */
+ memset((void *)ltdc_handle.LayerCfg[active_layer].FBStartAdress, 0,
+ BSP_LCD_GetXSize() * BSP_LCD_GetYSize() * BSP_LCD_PixelSize());
+
+ /* turn the display on */
+ BSP_LCD_DisplayOn();
+ return LCD_OK;
+}
+
+/* LK display (lib/gfx.h) calls this function */
+status_t display_get_info(struct display_info *info)
+{
+ info->framebuffer = (void *)ltdc_handle.LayerCfg[active_layer].FBStartAdress;
+
+ if (ltdc_handle.LayerCfg[active_layer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888) {
+ info->format = GFX_FORMAT_ARGB_8888;
+ } else if (ltdc_handle.LayerCfg[active_layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) {
+ info->format = GFX_FORMAT_RGB_565;
+ } else {
+ panic("unhandled pixel format\n");
+ return ERR_NOT_FOUND;
+ }
+
+ info->width = BSP_LCD_GetXSize();
+ info->height = BSP_LCD_GetYSize();
+ info->stride = BSP_LCD_GetXSize();
+ info->flush = NULL;
+
+ return NO_ERROR;
+}
+
diff --git a/src/bsp/lk/target/stm32f746g-disco/rules.mk b/src/bsp/lk/target/stm32f746g-disco/rules.mk
new file mode 100644
index 0000000..577be12
--- /dev/null
+++ b/src/bsp/lk/target/stm32f746g-disco/rules.mk
@@ -0,0 +1,34 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+STM32_CHIP := stm32f746
+
+PLATFORM := stm32f7xx
+
+SDRAM_SIZE := 0x00800000
+SDRAM_BASE := 0xc0000000
+
+GLOBAL_DEFINES += \
+ ENABLE_UART1=1 \
+ ENABLE_SDRAM=1 \
+ USE_HSE_XTAL=1 \
+ SDRAM_BASE=$(SDRAM_BASE) \
+ SDRAM_SIZE=$(SDRAM_SIZE) \
+ PLL_M_VALUE=8 \
+ PLL_N_VALUE=336 \
+ PLL_P_VALUE=2 \
+\
+ PKTBUF_POOL_SIZE=16
+
+
+MODULE_SRCS += \
+ $(LOCAL_DIR)/init.c \
+ $(LOCAL_DIR)/lcd.c \
+ $(LOCAL_DIR)/usb.c
+
+MODULE_DEPS += \
+ lib/gfx
+
+include make/module.mk
+
diff --git a/src/bsp/lk/target/stm32f746g-disco/usb.c b/src/bsp/lk/target/stm32f746g-disco/usb.c
new file mode 100644
index 0000000..2689b44
--- /dev/null
+++ b/src/bsp/lk/target/stm32f746g-disco/usb.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2013-2015 Travis Geiselbrecht
+ *
+ * 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 <err.h>
+#include <debug.h>
+#include <stdio.h>
+#include <trace.h>
+#include <target.h>
+#include <compiler.h>
+#include <dev/usb.h>
+#include <dev/usbc.h>
+#include <hw/usb.h>
+#include <lk/init.h>
+
+#define LOCAL_TRACE 0
+
+#define W(w) (w & 0xff), (w >> 8)
+#define W3(w) (w & 0xff), ((w >> 8) & 0xff), ((w >> 16) & 0xff)
+
+/* top level device descriptor */
+static const uint8_t dev_descr[] = {
+ 0x12, /* descriptor length */
+ DEVICE, /* Device Descriptor type */
+ W(0x0200), /* USB Version */
+ 0xff, /* class */
+ 0xff, /* subclass */
+ 0xff, /* protocol */
+ 64, /* max packet size, ept0 */
+ W(0x9999), /* vendor */
+ W(0x9999), /* product */
+ W(0x9999), /* release */
+ 0x2, /* manufacturer string */
+ 0x1, /* product string */
+ 0x0, /* serialno string */
+ 0x1, /* num configs */
+};
+
+/* high/low speed device qualifier */
+static const uint8_t devqual_descr[] = {
+ 0x0a, /* len */
+ DEVICE_QUALIFIER, /* Device Qualifier type */
+ W(0x0200), /* USB version */
+ 0x00, /* class */
+ 0x00, /* subclass */
+ 0x00, /* protocol */
+ 64, /* max packet size, ept0 */
+ 0x01, /* num configs */
+ 0x00 /* reserved */
+};
+
+static const uint8_t cfg_descr[] = {
+ 0x09, /* Length of Cfg Descr */
+ CONFIGURATION, /* Type of Cfg Descr */
+ W(0x09), /* Total Length (incl ifc, ept) */
+ 0x00, /* # Interfaces */
+ 0x01, /* Cfg Value */
+ 0x00, /* Cfg String */
+ 0xc0, /* Attributes -- self powered */
+ 250, /* Power Consumption - 500mA */
+};
+
+static const uchar langid[] = { 0x04, 0x03, 0x09, 0x04 };
+
+static const uint8_t if_descriptor_lowspeed[] = {
+ 0x09, /* length */
+ INTERFACE, /* type */
+ 0x01, /* interface num */
+ 0x00, /* alternates */
+ 0x02, /* endpoint count */
+ 0xff, /* interface class */
+ 0xff, /* interface subclass */
+ 0x00, /* interface protocol */
+ 0x00, /* string index */
+
+ /* endpoint 1 IN */
+ 0x07, /* length */
+ ENDPOINT, /* type */
+ 0x81, /* address: 1 IN */
+ 0x02, /* type: bulk */
+ W(64), /* max packet size: 64 */
+ 00, /* interval */
+
+ /* endpoint 1 OUT */
+ 0x07, /* length */
+ ENDPOINT, /* type */
+ 0x01, /* address: 1 OUT */
+ 0x02, /* type: bulk */
+ W(64), /* max packet size: 64 */
+ 00, /* interval */
+};
+
+usb_config config = {
+ .lowspeed = {
+ .device = USB_DESC_STATIC(dev_descr),
+ .device_qual = USB_DESC_STATIC(devqual_descr),
+ .config = USB_DESC_STATIC(cfg_descr),
+ },
+ .highspeed = {
+ .device = USB_DESC_STATIC(dev_descr),
+ .device_qual = USB_DESC_STATIC(devqual_descr),
+ .config = USB_DESC_STATIC(cfg_descr),
+ },
+
+ .langid = USB_DESC_STATIC(langid),
+};
+
+static status_t ep_cb_rx(ep_t endpoint, usbc_transfer_t *t);
+static status_t ep_cb_tx(ep_t endpoint, usbc_transfer_t *t);
+
+static void queue_rx(void)
+{
+ static usbc_transfer_t transfer;
+ static uint8_t buf[512];
+
+ transfer.callback = &ep_cb_rx;
+ transfer.result = 0;
+ transfer.buf = &buf;
+ transfer.buflen = sizeof(buf);
+ transfer.bufpos = 0;
+ transfer.extra = 0;
+
+ usbc_queue_rx(1, &transfer);
+}
+
+static void queue_tx(void)
+{
+ static usbc_transfer_t transfer;
+ static uint8_t buf[512];
+
+ for (uint i = 0; i < sizeof(buf); i++) {
+ buf[i] = ~i;
+ }
+
+ transfer.callback = &ep_cb_tx;
+ transfer.result = 0;
+ transfer.buf = &buf;
+ transfer.buflen = sizeof(buf);
+ transfer.bufpos = 0;
+ transfer.extra = 0;
+
+ usbc_queue_tx(1, &transfer);
+}
+
+static status_t ep_cb_rx(ep_t endpoint, usbc_transfer_t *t)
+{
+#if LOCAL_TRACE
+ LTRACEF("ep %u transfer %p\n", endpoint, t);
+ usbc_dump_transfer(t);
+
+ if (t->result >= 0) {
+ hexdump8(t->buf, t->bufpos);
+ }
+#endif
+
+ if (t->result >= 0)
+ queue_rx();
+
+ return NO_ERROR;
+}
+
+static status_t ep_cb_tx(ep_t endpoint, usbc_transfer_t *t)
+{
+#if LOCAL_TRACE
+ LTRACEF("ep %u transfer %p\n", endpoint, t);
+ usbc_dump_transfer(t);
+#endif
+
+ if (t->result >= 0)
+ queue_tx();
+
+ return NO_ERROR;
+}
+
+static status_t usb_cb(void *cookie, usb_callback_op_t op, const union usb_callback_args *args)
+{
+ LTRACEF("cookie %p, op %u, args %p\n", cookie, op, args);
+
+ if (op == USB_CB_ONLINE) {
+ usbc_setup_endpoint(1, USB_IN, 0x40);
+ usbc_setup_endpoint(1, USB_OUT, 0x40);
+
+ queue_rx();
+ queue_tx();
+ }
+ return NO_ERROR;
+}
+
+void target_usb_setup(void)
+{
+ usb_setup(&config);
+ printf("appending interfaces\n");
+ usb_append_interface_lowspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
+ usb_append_interface_highspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
+
+ usb_add_string("LK", 1);
+ usb_add_string("LK Industries", 2);
+
+ usb_register_callback(&usb_cb, NULL);
+ usb_start();
+}