From a9279ece33e0e56cf8390da443d0042766f83c3f Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 19 Aug 2021 17:27:53 +0700 Subject: [PATCH] merge waveshare to h7 family --- hw/bsp/stm32h7/boards/stm32h743eval/board.h | 11 + hw/bsp/stm32h7/boards/stm32h743nucleo/board.h | 6 + hw/bsp/stm32h7/boards/stm32h745disco/board.h | 5 + .../STM32H743IITX_FLASH.ld | 175 +++++++++++++ .../boards/waveshare_openh743i_2/board.h | 229 ++++++++++++++++++ .../boards/waveshare_openh743i_2/board.mk | 19 ++ hw/bsp/stm32h7/family.c | 75 +++--- 7 files changed, 472 insertions(+), 48 deletions(-) create mode 100644 hw/bsp/stm32h7/boards/waveshare_openh743i_2/STM32H743IITX_FLASH.ld create mode 100644 hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.h create mode 100644 hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.mk diff --git a/hw/bsp/stm32h7/boards/stm32h743eval/board.h b/hw/bsp/stm32h7/boards/stm32h743eval/board.h index ab263d2b7..af2063ce0 100644 --- a/hw/bsp/stm32h7/boards/stm32h743eval/board.h +++ b/hw/bsp/stm32h7/boards/stm32h743eval/board.h @@ -52,6 +52,12 @@ #define OTG_FS_VBUS_SENSE 1 #define OTG_HS_VBUS_SENSE 0 +// USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7 +#define ULPI_PINS \ + {GPIOA, GPIO_PIN_3 }, {GPIOA, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_0 }, {GPIOB, GPIO_PIN_1 }, \ + {GPIOB, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_10}, {GPIOB, GPIO_PIN_11}, {GPIOB, GPIO_PIN_12}, \ + {GPIOB, GPIO_PIN_13}, {GPIOC, GPIO_PIN_0 }, {GPIOH, GPIO_PIN_4 }, {GPIOI, GPIO_PIN_11} + //--------------------------------------------------------------------+ // RCC Clock //--------------------------------------------------------------------+ @@ -125,6 +131,11 @@ static inline void board_stm32h7_clock_init(void) HAL_EnableCompensationCell(); } +static inline void board_stm32h7_post_init(void) +{ + // For this board does nothing +} + #ifdef __cplusplus } #endif diff --git a/hw/bsp/stm32h7/boards/stm32h743nucleo/board.h b/hw/bsp/stm32h7/boards/stm32h743nucleo/board.h index 3a31783a8..06148c875 100644 --- a/hw/bsp/stm32h7/boards/stm32h743nucleo/board.h +++ b/hw/bsp/stm32h7/boards/stm32h743nucleo/board.h @@ -109,6 +109,12 @@ static inline void board_stm32h7_clock_init(void) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct); } +static inline void board_stm32h7_post_init(void) +{ + // For this board does nothing +} + + #ifdef __cplusplus } #endif diff --git a/hw/bsp/stm32h7/boards/stm32h745disco/board.h b/hw/bsp/stm32h7/boards/stm32h745disco/board.h index 30a7a9ff6..d33e0c8eb 100644 --- a/hw/bsp/stm32h7/boards/stm32h745disco/board.h +++ b/hw/bsp/stm32h7/boards/stm32h745disco/board.h @@ -127,6 +127,11 @@ static inline void board_stm32h7_clock_init(void) HAL_EnableCompensationCell(); } +static inline void board_stm32h7_post_init(void) +{ + // For this board does nothing +} + #ifdef __cplusplus } #endif diff --git a/hw/bsp/stm32h7/boards/waveshare_openh743i_2/STM32H743IITX_FLASH.ld b/hw/bsp/stm32h7/boards/waveshare_openh743i_2/STM32H743IITX_FLASH.ld new file mode 100644 index 000000000..73d2dedb2 --- /dev/null +++ b/hw/bsp/stm32h7/boards/waveshare_openh743i_2/STM32H743IITX_FLASH.ld @@ -0,0 +1,175 @@ +/* +****************************************************************************** +** +** File : LinkerScript.ld +** +** Author : STM32CubeIDE +** +** Abstract : Linker script for STM32H7 series +** 2048Kbytes FLASH and 192Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used. +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +***************************************************************************** +** @attention +** +** Copyright (c) 2019 STMicroelectronics. +** All rights reserved. +** +** This software component is licensed by ST under BSD 3-Clause license, +** the "License"; You may not use this file except in compliance with the +** License. You may obtain a copy of the License at: +** opensource.org/licenses/BSD-3-Clause +** +**************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = 0x20020000; /* end of RAM */ +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x2000 ; /* required amount of heap */ +_Min_Stack_Size = 0x2000 ; /* required amount of stack */ + +/* Specify the memory areas */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K + RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K + RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K + RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K + ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + } >RAM AT> FLASH + + /* Uninitialized data section */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough RAM left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + + diff --git a/hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.h b/hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.h new file mode 100644 index 000000000..09442c233 --- /dev/null +++ b/hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.h @@ -0,0 +1,229 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 + * Ha Thach (tinyusb.org) + * Benjamin Evans + * + * 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_ + +/* ** BOARD SETUP ** + * + * NOTE: This board has bad signal integrity so you may experience some problems. + * This setup assumes you have an openh743i-c Core and breakout board. For the HS + * examples it also assumes you have a waveshare USB3300 breakout board plugged + * into the ULPI PMOD header on the openh743i-c. + * + * UART Debugging: + * Due to pin conflicts in the HS configuration, this BSP uses USART3 (PD8, PD9). + * As such, you won't be able to use the UART to USB converter on board and will + * require an external UART to USB converter. You could use the waveshare FT232 + * USB UART Board (micro) but any 3.3V UART to USB converter will be fine. + * + * Fullspeed: + * If VBUS sense is enabled, ensure the PA9-VBUS jumper is connected on the core + * board. Connect the PB6 jumper for the LED and the Wakeup - PA0 jumper for the + * button. Connect the USB cable to the USB connector on the core board. + * + * High Speed: + * Remove all jumpers from the openh743i-c (especially the USART1 jumpers as the + * pins conflict). Connect the PB6 jumper for the LED and the Wakeup - PA0 + * jumper for the button. + * + * The reset pin on the ULPI PMOD port is not connected to the MCU. You'll need + * to solder a wire from the RST pin on the USB3300 to a pin of your choosing on + * the openh743i-c board (this example assumes you've used PD14 as specified with + * the ULPI_RST_PORT and ULPI_RST_PIN defines below). + * + * Preferably power the board using the external 5VDC jack. Connect the USB cable + * to the USB connector on the ULPI board. Adjust delays in this file as required. + * + * If you're having trouble, ask a question on the tinyUSB Github Discussion boards. + * + * Have fun! + * +*/ + +#ifdef __cplusplus + extern "C" { +#endif + +#define LED_PORT GPIOB +#define LED_PIN GPIO_PIN_6 +#define LED_STATE_ON 1 + +// Tamper push-button +#define BUTTON_PORT GPIOA +#define BUTTON_PIN GPIO_PIN_0 +#define BUTTON_STATE_ACTIVE 1 + +// Need to change jumper setting J7 and J8 from RS-232 to STLink +#define UART_DEV USART3 +#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE +#define UART_GPIO_PORT GPIOD +#define UART_GPIO_AF GPIO_AF7_USART3 +#define UART_TX_PIN GPIO_PIN_8 +#define UART_RX_PIN GPIO_PIN_9 + +// VBUS Sense detection +#define OTG_FS_VBUS_SENSE 1 +#define OTG_HS_VBUS_SENSE 0 + + // USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7 +#define ULPI_PINS \ + {GPIOA, GPIO_PIN_3 }, {GPIOA, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_0 }, {GPIOB, GPIO_PIN_1 }, \ + {GPIOB, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_10}, {GPIOB, GPIO_PIN_11}, {GPIOB, GPIO_PIN_12}, \ + {GPIOB, GPIO_PIN_13}, {GPIOC, GPIO_PIN_0 }, {GPIOC, GPIO_PIN_2 }, {GPIOC, GPIO_PIN_3 } + +// ULPI PHY reset pin used by walkaround +#define ULPI_RST_PORT GPIOD +#define ULPI_RST_PIN GPIO_PIN_14 + +//--------------------------------------------------------------------+ +// RCC Clock +//--------------------------------------------------------------------+ +static inline void board_stm32h7_clock_init(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; + + __HAL_RCC_SYSCFG_CLK_ENABLE(); + + // Supply configuration update enable + HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); + + // Configure the main internal regulator output voltage + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); + + while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) + { + } + // Macro to configure the PLL clock source + __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSE); + + // Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure. + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 2; + RCC_OscInitStruct.PLL.PLLN = 240; + RCC_OscInitStruct.PLL.PLLP = 2; + RCC_OscInitStruct.PLL.PLLQ = 2; + RCC_OscInitStruct.PLL.PLLR = 2; + RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2; + RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; + RCC_OscInitStruct.PLL.PLLFRACN = 0; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB | RCC_PERIPHCLK_USART3; + PeriphClkInitStruct.PLL3.PLL3M = 8; + PeriphClkInitStruct.PLL3.PLL3N = 336; + PeriphClkInitStruct.PLL3.PLL3P = 2; + PeriphClkInitStruct.PLL3.PLL3Q = 7; + PeriphClkInitStruct.PLL3.PLL3R = 2; + PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_0; + PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOWIDE; + PeriphClkInitStruct.PLL3.PLL3FRACN = 0; + PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_PLL3; + PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + + // Initializes the CPU, AHB and APB buses clocks + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1 | RCC_CLOCKTYPE_D1PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; + RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; + RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); + + __HAL_RCC_CSI_ENABLE(); + + // Enable SYSCFG clock mondatory for I/O Compensation Cell + __HAL_RCC_SYSCFG_CLK_ENABLE(); + + // Enables the I/O Compensation Cell + HAL_EnableCompensationCell(); + + // Enable voltage detector + HAL_PWREx_EnableUSBVoltageDetector(); +} + +static inline void timer_board_delay(TIM_HandleTypeDef* tim_hdl, uint32_t ms) +{ + uint32_t startMs = __HAL_TIM_GET_COUNTER(tim_hdl); + while ((__HAL_TIM_GET_COUNTER(tim_hdl) - startMs) < ms) + { + asm("nop"); //do nothing + } +} + +static inline void board_stm32h7_post_init(void) +{ + // walkaround for reseting the ULPI PHY using Timer since systick is not + // available when RTOS is used. + + // Init timer + TIM_HandleTypeDef tim2Handle; + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + + __HAL_RCC_TIM2_CLK_ENABLE(); + + //Assuming timer clock is running at 260Mhz this should configure the timer counter to 1000Hz + tim2Handle.Instance = TIM2; + tim2Handle.Init.Prescaler = 60000U - 1U; + tim2Handle.Init.CounterMode = TIM_COUNTERMODE_UP; + tim2Handle.Init.Period = 0xFFFFFFFFU; + tim2Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; + tim2Handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + HAL_TIM_Base_Init(&tim2Handle); + + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + HAL_TIM_ConfigClockSource(&tim2Handle, &sClockSourceConfig); + + //Start the timer + HAL_TIM_Base_Start(&tim2Handle); + + // Reset PHY, change the delays as you see fit + timer_board_delay(&tim2Handle, 5U); + HAL_GPIO_WritePin(ULPI_RST_PORT, ULPI_RST_PIN, 1U); + timer_board_delay(&tim2Handle, 20U); + HAL_GPIO_WritePin(ULPI_RST_PORT, ULPI_RST_PIN, 0U); + timer_board_delay(&tim2Handle, 20U); + + //Disable the timer used for delays + HAL_TIM_Base_Stop(&tim2Handle); + __HAL_RCC_TIM2_CLK_DISABLE(); +} + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.mk b/hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.mk new file mode 100644 index 000000000..4dfcc1cac --- /dev/null +++ b/hw/bsp/stm32h7/boards/waveshare_openh743i_2/board.mk @@ -0,0 +1,19 @@ +CFLAGS += -DSTM32H743xx -DHSE_VALUE=8000000 + +# Default is HS port +PORT ?= 1 + +SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s +LD_FILE = $(BOARD_PATH)/STM32H743IITX_FLASH.ld + +# Use Timer module for ULPI PHY reset +CFLAGS += -DHAL_TIM_MODULE_ENABLED +SRC_C += \ + $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim.c \ + $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim_ex.c + +# For flash-jlink target +JLINK_DEVICE = stm32h743ii + +# flash target using jlink +flash: flash-jlink \ No newline at end of file diff --git a/hw/bsp/stm32h7/family.c b/hw/bsp/stm32h7/family.c index 2cbd87414..3e1ed9e84 100644 --- a/hw/bsp/stm32h7/family.c +++ b/hw/bsp/stm32h7/family.c @@ -75,13 +75,15 @@ void board_init(void) // Enable UART Clock UART_CLK_EN(); +#if CFG_TUSB_OS == OPT_OS_NONE // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); -#if CFG_TUSB_OS == OPT_OS_FREERTOS +#elif CFG_TUSB_OS == OPT_OS_FREERTOS // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) NVIC_SetPriority(OTG_FS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); NVIC_SetPriority(OTG_HS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); + #endif GPIO_InitTypeDef GPIO_InitStruct; @@ -123,7 +125,7 @@ void board_init(void) // OTG_FS is marked as RHPort0 by TinyUSB to be consistent across stm32 port // PA9 VUSB, PA10 ID, PA11 DM, PA12 DP - /* Configure DM DP Pins */ + // Configure DM DP Pins GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -131,7 +133,7 @@ void board_init(void) GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* This for ID line debug */ + // This for ID line debug GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -145,7 +147,7 @@ void board_init(void) __HAL_RCC_USB2_OTG_FS_CLK_ENABLE(); #if OTG_FS_VBUS_SENSE - /* Configure VBUS Pin */ + // Configure VBUS Pin GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -166,49 +168,23 @@ void board_init(void) // Despite being call USB2_OTG // OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port - /* CLK */ - GPIO_InitStruct.Pin = GPIO_PIN_5; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + struct { + GPIO_TypeDef* port; + uint32_t pin; + } const ulpi_pins[] = + { + ULPI_PINS + }; - /* D0 */ - GPIO_InitStruct.Pin = GPIO_PIN_3; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_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_OTG2_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_OTG2_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_OTG2_HS; - HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); - - /* DIR */ - GPIO_InitStruct.Pin = GPIO_PIN_11; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; - HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); + for (uint8_t i=0; i < sizeof(ulpi_pins)/sizeof(ulpi_pins[0]); i++) + { + GPIO_InitStruct.Pin = ulpi_pins[i].pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; + HAL_GPIO_Init(ulpi_pins[i].port, &GPIO_InitStruct); + } // Enable USB HS & ULPI Clocks __HAL_RCC_USB1_OTG_HS_ULPI_CLK_ENABLE(); @@ -230,6 +206,9 @@ void board_init(void) USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD; HAL_PWREx_EnableUSBVoltageDetector(); + + // For waveshare openh743 ULPI PHY reset walkaround + board_stm32h7_post_init(); #endif // rhport = 1 } @@ -263,7 +242,7 @@ int board_uart_write(void const * buf, int len) #if CFG_TUSB_OS == OPT_OS_NONE volatile uint32_t system_ticks = 0; -void SysTick_Handler (void) +void SysTick_Handler(void) { system_ticks++; } @@ -274,7 +253,7 @@ uint32_t board_millis(void) } #endif -void HardFault_Handler (void) +void HardFault_Handler(void) { asm("bkpt"); }