mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-16 05:42:56 +00:00
usb on u5a5 hs work well with correct VBVALEXTOEN/VBVALOVAL set
This commit is contained in:
parent
9f0223dccd
commit
db3ff4b352
@ -217,7 +217,7 @@ function(family_configure_common TARGET RTOS)
|
|||||||
if (NOT TARGET segger_rtt)
|
if (NOT TARGET segger_rtt)
|
||||||
add_library(segger_rtt STATIC ${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c)
|
add_library(segger_rtt STATIC ${TOP}/lib/SEGGER_RTT/RTT/SEGGER_RTT.c)
|
||||||
target_include_directories(segger_rtt PUBLIC ${TOP}/lib/SEGGER_RTT/RTT)
|
target_include_directories(segger_rtt PUBLIC ${TOP}/lib/SEGGER_RTT/RTT)
|
||||||
target_compile_definitions(segger_rtt PUBLIC SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL)
|
#target_compile_definitions(segger_rtt PUBLIC SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(${TARGET} PUBLIC segger_rtt)
|
target_link_libraries(${TARGET} PUBLIC segger_rtt)
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -6,5 +6,6 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32U5A5ZJTXQ_FLASH.ld)
|
|||||||
function(update_board TARGET)
|
function(update_board TARGET)
|
||||||
target_compile_definitions(${TARGET} PUBLIC
|
target_compile_definitions(${TARGET} PUBLIC
|
||||||
STM32U5A5xx
|
STM32U5A5xx
|
||||||
|
HSE_VALUE=16000000UL
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -38,8 +38,8 @@ extern "C"
|
|||||||
#define LED_STATE_ON 1
|
#define LED_STATE_ON 1
|
||||||
|
|
||||||
// BUTTON
|
// BUTTON
|
||||||
#define BUTTON_PORT GPIOA
|
#define BUTTON_PORT GPIOC
|
||||||
#define BUTTON_PIN GPIO_PIN_0
|
#define BUTTON_PIN GPIO_PIN_13
|
||||||
#define BUTTON_STATE_ACTIVE 1
|
#define BUTTON_STATE_ACTIVE 1
|
||||||
|
|
||||||
// UART Enable for STLink VCOM
|
// UART Enable for STLink VCOM
|
||||||
@ -101,6 +101,8 @@ static void SystemClock_Config(void) {
|
|||||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
|
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
|
||||||
|
|
||||||
// USB Clock
|
// USB Clock
|
||||||
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||||
|
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USBPHY;
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USBPHY;
|
||||||
PeriphClkInit.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_HSE;
|
PeriphClkInit.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_HSE;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
CFLAGS += \
|
CFLAGS += \
|
||||||
-DSTM32U5A5xx \
|
-DSTM32U5A5xx \
|
||||||
|
-DHSE_VALUE=16000000UL \
|
||||||
|
|
||||||
# All source paths should be relative to the top level.
|
# All source paths should be relative to the top level.
|
||||||
LD_FILE = ${BOARD_PATH}/STM32U5A5ZJTXQ_FLASH.ld
|
LD_FILE = ${BOARD_PATH}/STM32U5A5ZJTXQ_FLASH.ld
|
||||||
|
@ -124,7 +124,7 @@ void board_init(void) {
|
|||||||
|
|
||||||
HAL_UART_Init(&UartHandle);
|
HAL_UART_Init(&UartHandle);
|
||||||
|
|
||||||
/* Configure USB FS GPIOs */
|
/* Configure USB GPIOs */
|
||||||
/* Configure DM DP Pins */
|
/* Configure DM DP Pins */
|
||||||
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
@ -153,6 +153,12 @@ void board_init(void) {
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* Enable USB power on Pwrctrl CR2 register */
|
||||||
|
HAL_PWREx_EnableVddUSB();
|
||||||
|
|
||||||
|
/* USB clock enable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||||
|
|
||||||
// Enable VBUS sense (B device) via pin PA9
|
// Enable VBUS sense (B device) via pin PA9
|
||||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
|
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
|
||||||
#else
|
#else
|
||||||
@ -164,11 +170,6 @@ void board_init(void) {
|
|||||||
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
|
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
|
||||||
#endif // vbus sense
|
#endif // vbus sense
|
||||||
|
|
||||||
/* Enable USB power on Pwrctrl CR2 register */
|
|
||||||
HAL_PWREx_EnableVddUSB();
|
|
||||||
|
|
||||||
/* USB clock enable */
|
|
||||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
|
||||||
#else
|
#else
|
||||||
// STM59x/Ax/Fx/Gx only have 1 USB HS port
|
// STM59x/Ax/Fx/Gx only have 1 USB HS port
|
||||||
|
|
||||||
@ -177,15 +178,7 @@ void board_init(void) {
|
|||||||
NVIC_SetPriority(OTG_HS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
NVIC_SetPriority(OTG_HS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Disable VBUS sense (B device)
|
|
||||||
USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
|
|
||||||
|
|
||||||
// B-peripheral session valid override enable
|
|
||||||
USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
|
|
||||||
USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
|
|
||||||
|
|
||||||
/* USB clock enable */
|
/* USB clock enable */
|
||||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
|
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
|
||||||
__HAL_RCC_USBPHYC_CLK_ENABLE();
|
__HAL_RCC_USBPHYC_CLK_ENABLE();
|
||||||
|
|
||||||
@ -195,6 +188,13 @@ void board_init(void) {
|
|||||||
|
|
||||||
/*Configuring the SYSCFG registers OTG_HS PHY*/
|
/*Configuring the SYSCFG registers OTG_HS PHY*/
|
||||||
HAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
|
HAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
|
||||||
|
|
||||||
|
// Disable VBUS sense (B device)
|
||||||
|
USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
|
||||||
|
|
||||||
|
// B-peripheral session valid override enable
|
||||||
|
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
|
||||||
|
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
|
||||||
#endif // USB_OTG_FS
|
#endif // USB_OTG_FS
|
||||||
|
|
||||||
|
|
||||||
|
@ -1074,7 +1074,6 @@ void dcd_int_handler(uint8_t rhport) {
|
|||||||
|
|
||||||
if (int_status & GINTSTS_ENUMDNE) {
|
if (int_status & GINTSTS_ENUMDNE) {
|
||||||
// ENUMDNE is the end of reset where speed of the link is detected
|
// ENUMDNE is the end of reset where speed of the link is detected
|
||||||
|
|
||||||
dwc2->gintsts = GINTSTS_ENUMDNE;
|
dwc2->gintsts = GINTSTS_ENUMDNE;
|
||||||
|
|
||||||
tusb_speed_t speed;
|
tusb_speed_t speed;
|
||||||
@ -1094,6 +1093,8 @@ void dcd_int_handler(uint8_t rhport) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO must update GUSBCFG_TRDT according to link speed
|
||||||
|
|
||||||
dcd_event_bus_reset(rhport, speed, true);
|
dcd_event_bus_reset(rhport, speed, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
* This file is part of the TinyUSB stack.
|
* This file is part of the TinyUSB stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _DWC2_STM32_H_
|
#ifndef DWC2_STM32_H_
|
||||||
#define _DWC2_STM32_H_
|
#define DWC2_STM32_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -124,35 +124,36 @@ static const dwc2_controller_t _dwc2_controller[] = {
|
|||||||
// SystemCoreClock is already included by family header
|
// SystemCoreClock is already included by family header
|
||||||
// extern uint32_t SystemCoreClock;
|
// extern uint32_t SystemCoreClock;
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE
|
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) {
|
||||||
static inline void dwc2_dcd_int_enable(uint8_t rhport) {
|
|
||||||
NVIC_EnableIRQ((IRQn_Type) _dwc2_controller[rhport].irqnum);
|
NVIC_EnableIRQ((IRQn_Type) _dwc2_controller[rhport].irqnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE
|
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
|
||||||
static inline void dwc2_dcd_int_disable(uint8_t rhport) {
|
|
||||||
NVIC_DisableIRQ((IRQn_Type) _dwc2_controller[rhport].irqnum);
|
NVIC_DisableIRQ((IRQn_Type) _dwc2_controller[rhport].irqnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
TU_ATTR_ALWAYS_INLINE
|
TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
|
||||||
static inline void dwc2_remote_wakeup_delay(void) {
|
|
||||||
// try to delay for 1 ms
|
// try to delay for 1 ms
|
||||||
uint32_t count = SystemCoreClock / 1000;
|
uint32_t count = SystemCoreClock / 1000;
|
||||||
while (count--) __NOP();
|
while (count--) __NOP();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MCU specific PHY init, called BEFORE core reset
|
// MCU specific PHY init, called BEFORE core reset
|
||||||
|
// - dwc2 3.30a (H5) use USB_HS_PHYC
|
||||||
|
// - dwc2 4.11a (U5) use femtoPHY
|
||||||
static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||||
if (hs_phy_type == HS_PHY_TYPE_NONE) {
|
if (hs_phy_type == HS_PHY_TYPE_NONE) {
|
||||||
// Enable on-chip FS PHY
|
// Enable on-chip FS PHY
|
||||||
dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN;
|
dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN;
|
||||||
} else {
|
} else {
|
||||||
|
#if CFG_TUSB_MCU != OPT_MCU_STM32U5
|
||||||
// Disable FS PHY, TODO on U5A5 (dwc2 4.11a) 16th bit is 'Host CDP behavior enable'
|
// Disable FS PHY, TODO on U5A5 (dwc2 4.11a) 16th bit is 'Host CDP behavior enable'
|
||||||
dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN;
|
dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Enable on-chip HS PHY
|
// Enable on-chip HS PHY
|
||||||
if (hs_phy_type == HS_PHY_TYPE_UTMI || hs_phy_type == HS_PHY_TYPE_UTMI_ULPI) {
|
if (hs_phy_type == HS_PHY_TYPE_UTMI || hs_phy_type == HS_PHY_TYPE_UTMI_ULPI) {
|
||||||
#ifdef USB_HS_PHYC
|
#ifdef USB_HS_PHYC
|
||||||
// Enable UTMI HS PHY
|
// Enable UTMI HS PHY
|
||||||
dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN;
|
dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN;
|
||||||
|
|
||||||
@ -184,7 +185,9 @@ static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
|||||||
|
|
||||||
// Enable PLL internal PHY
|
// Enable PLL internal PHY
|
||||||
USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN;
|
USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN;
|
||||||
#endif
|
#else
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,4 +235,4 @@ static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _DWC2_STM32_H_ */
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user