summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-10-18 22:16:21 +0700
committerhathach <[email protected]>2024-10-18 22:16:21 +0700
commit61b33ca926065cd25a2045077ab96dd990ce2560 (patch)
tree3ed93f81231a0099a4e2186bc22deed173d37da4
parent42b6f30edaf91196ecdaaebb36385bcc3f312d17 (diff)
testing hcd with f723 due to h743eval issue with mfx vbus drive.
-rw-r--r--hw/bsp/stm32f7/boards/stm32f723disco/board.cmake2
-rw-r--r--hw/bsp/stm32f7/boards/stm32f723disco/board.h41
-rw-r--r--hw/bsp/stm32f7/family.c24
-rw-r--r--src/common/tusb_types.h4
4 files changed, 50 insertions, 21 deletions
diff --git a/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake b/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake
index dd3c35b00..8a7b4cb27 100644
--- a/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake
+++ b/hw/bsp/stm32f7/boards/stm32f723disco/board.cmake
@@ -1,6 +1,6 @@
set(MCU_VARIANT stm32f723xx)
set(JLINK_DEVICE stm32f723ie)
-
+#set(JLINK_OPTION "-USB 000776606156")
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F723xE_FLASH.ld)
function(update_board TARGET)
diff --git a/hw/bsp/stm32f7/boards/stm32f723disco/board.h b/hw/bsp/stm32f7/boards/stm32f723disco/board.h
index 258786b7f..178fd6e5e 100644
--- a/hw/bsp/stm32f7/boards/stm32f723disco/board.h
+++ b/hw/bsp/stm32f7/boards/stm32f723disco/board.h
@@ -56,8 +56,7 @@
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
-static inline void board_clock_init(void)
-{
+static inline void board_clock_init(void) {
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
@@ -74,7 +73,7 @@ static inline void board_clock_init(void)
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000;
+ RCC_OscInitStruct.PLL.PLLM = HSE_VALUE / 1000000;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
@@ -98,6 +97,42 @@ static inline void board_clock_init(void)
//
//}
+typedef struct {
+ GPIO_TypeDef* port;
+ GPIO_InitTypeDef pin_init;
+ bool active_state;
+} board_pindef_t;
+
+static board_pindef_t vbus_pindef[] = {
+{
+ .port = GPIOG,
+ .pin_init = {
+ .Pin = GPIO_PIN_8, .Mode = GPIO_MODE_OUTPUT_OD, .Pull = GPIO_NOPULL,
+ .Speed = GPIO_SPEED_HIGH, .Alternate = 0
+ },
+ .active_state = false
+ },
+{
+ .port = GPIOH,
+ .pin_init = {
+ .Pin = GPIO_PIN_12, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL,
+ .Speed = GPIO_SPEED_HIGH, .Alternate = 0
+ },
+ .active_state = true
+ },
+};
+
+static inline void board_vbus_set(uint8_t rhport, bool state) {
+ static bool pin_inited[2] = { false, false };
+ board_pindef_t* pindef = &vbus_pindef[rhport];
+ if (!pin_inited[rhport]) {
+ HAL_GPIO_Init(pindef->port, &pindef->pin_init);
+ pin_inited[rhport] = true;
+ }
+
+ HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32f7/family.c b/hw/bsp/stm32f7/family.c
index 61f1d2a7f..1f49d7693 100644
--- a/hw/bsp/stm32f7/family.c
+++ b/hw/bsp/stm32f7/family.c
@@ -34,13 +34,13 @@
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
// Despite being call USB2_OTG
// OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port
void OTG_HS_IRQHandler(void) {
- tud_int_handler(1);
+ tusb_int_handler(1, true);
}
//--------------------------------------------------------------------+
@@ -65,7 +65,7 @@ void board_init(void) {
__HAL_RCC_GPIOJ_CLK_ENABLE();
#endif
- UART_CLK_EN();
+ UART_CLK_EN();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
@@ -122,9 +122,7 @@ void board_init(void) {
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&UartHandle);
-#if BOARD_TUD_RHPORT == 0
- // OTG_FS
-
+ //------------- rhport0: OTG_FS -------------//
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -171,9 +169,7 @@ void board_init(void) {
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
#endif // vbus sense
-#else
- // OTG_HS
-
+ //------------- rhport1: OTG_HS -------------//
#ifdef USB_HS_PHYC
// MCU with built-in HS PHY such as F723, F733, F730
@@ -261,12 +257,10 @@ void board_init(void) {
USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
#endif
- // Force device mode
- USB_OTG_HS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD;
- USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
-
-#endif // BOARD_TUD_RHPORT
-
+ // Turn on host vbus
+#if CFG_TUH_ENABLED
+ board_vbus_set(BOARD_TUH_RHPORT, true);
+#endif
}
//--------------------------------------------------------------------+
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h
index 53bb367cb..0faa6eee9 100644
--- a/src/common/tusb_types.h
+++ b/src/common/tusb_types.h
@@ -41,8 +41,8 @@
typedef enum {
TUSB_ROLE_INVALID = 0,
- TUSB_ROLE_DEVICE,
- TUSB_ROLE_HOST,
+ TUSB_ROLE_DEVICE = 0x1,
+ TUSB_ROLE_HOST = 0x2,
} tusb_role_t;
/// defined base on EHCI specs value for Endpoint Speed