testing hcd with f723 due to h743eval issue with mfx vbus drive.

This commit is contained in:
hathach 2024-10-18 22:16:21 +07:00
parent 42b6f30eda
commit 61b33ca926
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
4 changed files with 50 additions and 21 deletions

View File

@ -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)

View File

@ -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

View File

@ -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
}
//--------------------------------------------------------------------+

View File

@ -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