2025-09-04 12:06 AM
Hi,
I tried to bring up the USB host on the USB-A connector, but without success.
As a starting point, I took the example project:
STM32CubeN6\Projects\STM32N6570-DK\Applications\USBX\Ux_Host_DualClass (for the USB Type-C connector), replaced USB1 with USB2 throughout the code, and enabled the USB power switch via GPIO.
The device receives 5V, but no USB2 interrupt is triggered.
Below is my USB2 initialization. In line 18, I tried
RCC_USBPHY2REFCLKSOURCE_HSE_DIRECT, and
RCC_USBOTGHS2CLKSOURCE_HSE_DIRECT,
but neither case works.
It seems I’m missing something else. What could be wrong on my side?
void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
{
if (hhcd->Instance == USB2_OTG_HS)
{
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
/* USER CODE END USB_OTG_HS_MspInit 0 */
/* Enable VDDUSB */
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableVddUSBVMEN();
while(__HAL_PWR_GET_FLAG(PWR_FLAG_USB33RDY));
HAL_PWREx_EnableVddUSB();
/** Initializes the peripherals clock
*/
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USBOTGHS2;
PeriphClkInitStruct.UsbOtgHs2ClockSelection = RCC_USBOTGHS2CLKSOURCE_HSE_DIRECT;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/** Set USB OTG HS PHY2 Reference Clock Source */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USBPHY2;
PeriphClkInitStruct.UsbPhy2ClockSelection = RCC_USBPHY2REFCLKSOURCE_HSE_DIRECT;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
__HAL_RCC_GPIOA_CLK_ENABLE();
LL_AHB5_GRP1_ForceReset(RCC_AHB5RSTR_OTG2PHYCTLRST);
__HAL_RCC_USB2_OTG_HS_FORCE_RESET();
__HAL_RCC_USB2_OTG_HS_PHY_FORCE_RESET();
LL_RCC_HSE_SelectHSEDiv2AsDiv2Clock();
LL_AHB5_GRP1_ReleaseReset(RCC_AHB5RSTR_OTG2PHYCTLRST);
/* Peripheral clock enable */
__HAL_RCC_USB2_OTG_HS_CLK_ENABLE();
/* Required few clock cycles before accessing USB PHY Controller Registers */
HAL_Delay(1);
USB2_HS_PHYC->USBPHYC_CR &= ~(0x7 << 0x4);
USB2_HS_PHYC->USBPHYC_CR |= (0x1 << 16) |
(0x2 << 4) |
(0x1 << 2) |
0x1U;
__HAL_RCC_USB2_OTG_HS_PHY_RELEASE_RESET();
/* Required few clock cycles before Releasing Reset */
HAL_Delay(1);
__HAL_RCC_USB2_OTG_HS_RELEASE_RESET();
/* Peripheral PHY clock enable */
__HAL_RCC_USB2_OTG_HS_PHY_CLK_ENABLE();
/* USB_OTG_HS interrupt Init */
HAL_NVIC_SetPriority(USB2_OTG_HS_IRQn, 7, 0);
HAL_NVIC_EnableIRQ(USB2_OTG_HS_IRQn);
/* USER CODE BEGIN USB_OTG_HS_MspInit 1 */
/* USER CODE END USB_OTG_HS_MspInit 1 */
}
}
Solved! Go to Solution.
2025-09-16 12:18 AM - edited 2025-09-16 12:20 AM
Hi @FBL ,
Nice to hear that! If it could also be synced with the corresponding .ioc file and made for Appli (not FSBL), that would be great. ;)
As for my issue: the root cause is that the USBX host thread is waiting for an event from USBPD, which is disabled.
To fix it, HAL_HCD_Start(&hhcd_USB2_OTG_HS) needs to be called unconditionally. Hope it saves someone's time :)
static VOID app_ux_host_thread_entry(ULONG thread_input)
{
/* USER CODE BEGIN app_ux_host_thread_entry */
/* Initialization of USB host */
USBX_APP_Host_Init();
/* Start USB Host */
HAL_HCD_Start(&hhcd_USB2_OTG_HS); // start here, since no USBPD for USB2
while (1)
{
/* wait for message queue from callback event */
if(tx_queue_receive(&ux_app_MsgQueue_UCPD, &USB_Host_State_Msg, TX_WAIT_FOREVER)!= TX_SUCCESS)
{
Error_Handler();
}
/* Check if received message equal to START_USB_HOST */
if (USB_Host_State_Msg == START_USB_HOST)
{
/* Start USB Host */
HAL_HCD_Start(&hhcd_USB2_OTG_HS);
}
2025-09-11 7:37 AM
Hi @ERROR
Make sure that the interrupt handler is implemented in your code and correctly linked to the vector table.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-09-15 1:19 AM
Hi @FBL ,
Thank you for the advice. The listing and the map-file look okay for me. I get back to it later.
Have a good day!
2025-09-15 6:17 AM
Hi @ERROR
Meanwhile, an internal ticket is submitted to dedicated team to provide an example firmware for USB2 instance on N6 DK (217474).
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-09-16 12:18 AM - edited 2025-09-16 12:20 AM
Hi @FBL ,
Nice to hear that! If it could also be synced with the corresponding .ioc file and made for Appli (not FSBL), that would be great. ;)
As for my issue: the root cause is that the USBX host thread is waiting for an event from USBPD, which is disabled.
To fix it, HAL_HCD_Start(&hhcd_USB2_OTG_HS) needs to be called unconditionally. Hope it saves someone's time :)
static VOID app_ux_host_thread_entry(ULONG thread_input)
{
/* USER CODE BEGIN app_ux_host_thread_entry */
/* Initialization of USB host */
USBX_APP_Host_Init();
/* Start USB Host */
HAL_HCD_Start(&hhcd_USB2_OTG_HS); // start here, since no USBPD for USB2
while (1)
{
/* wait for message queue from callback event */
if(tx_queue_receive(&ux_app_MsgQueue_UCPD, &USB_Host_State_Msg, TX_WAIT_FOREVER)!= TX_SUCCESS)
{
Error_Handler();
}
/* Check if received message equal to START_USB_HOST */
if (USB_Host_State_Msg == START_USB_HOST)
{
/* Start USB Host */
HAL_HCD_Start(&hhcd_USB2_OTG_HS);
}