Skip to main content
Visitor II
August 13, 2025
Solved

STM32U5G9 not detecting USB for unknown reason

  • August 13, 2025
  • 2 replies
  • 1286 views

Hi

 

For some reason, an interrupt isn't being triggered when I connect the USB to my stm32 board, and the reason is baffling to me. I have attached the relevant excerpt of my code 

 

static inline void core_initialisation(void) //from page 3403
{
	USB_OTG_CfgTypeDef usb_config;


	usb_config.dev_endpoints = 6; // Typical number for HS device endpoints
	usb_config.Host_channels = 12; // Typical max host channels for HS core
	usb_config.dma_enable = 0; // Disable DMA (set 1 if your HW supports and you want DMA)
	usb_config.speed = USB_OTG_SPEED_HIGH; // High Speed
	usb_config.ep0_mps = 64; // Endpoint 0 max packet size (64 bytes for HS control EP)
	usb_config.phy_itface = USB_OTG_HS_EMBEDDED_PHY ; // Use embedded PHY (if your MCU supports it)
	usb_config.Sof_enable = 1; // Enable SOF (Start Of Frame) output
	usb_config.low_power_enable = 0; // Disable low power mode (set 1 to enable)
	usb_config.lpm_enable = 0; // Disable Link Power Management
	usb_config.battery_charging_enable = 0; // Disable battery charging feature
	usb_config.vbus_sensing_enable = 1; // Enable VBUS sensing
	usb_config.use_dedicated_ep1 = 0; // Usually 0 unless you need dedicated EP1 interrupt
	usb_config.use_external_vbus = 0; // Disable external VBUS (set 1 if external VBUS pin used)

	HAL_StatusTypeDef status = USB_CoreInit(USB_OTG_HS, usb_config);

	if (status == HAL_OK) {
	 log_info("It worked");
	} else {
		log_info("It didn't");
	 // Initialization error handling
	}

	SET_BIT(USB_OTG_HS->GINTMSK, 				//rhis is all set
	 USB_OTG_GINTMSK_USBRST | // USB reset interrupt mask
	 USB_OTG_GINTMSK_ENUMDNEM | // Enumeration done interrupt mask
	 USB_OTG_GINTMSK_SOFM | // Start of frame mask
	 USB_OTG_GINTMSK_USBSUSPM | // USB suspend mask
	 USB_OTG_GINTMSK_WUIM | // Wakeup interrupt mask
	 USB_OTG_GINTMSK_IEPINT | // IN endpoint interrupt mask
	 USB_OTG_GINTMSK_OEPINT | // OUT endpoint interrupt mask
	 USB_OTG_GINTMSK_RXFLVLM // Rx FIFO non-empty mask
	 );
	USB_EnableGlobalInt(USB_OTG_HS);

}

static void initialise_device_core()
{

	core_initialisation();

	USB_OTG_CfgTypeDef usb_config;


	usb_config.dev_endpoints = 6; // Typical number for HS device endpoints
	usb_config.Host_channels = 12; // Typical max host channels for HS core
	usb_config.dma_enable = 0; // Disable DMA (set 1 if your HW supports and you want DMA)
	usb_config.speed = USB_OTG_SPEED_HIGH; // High Speed
	usb_config.ep0_mps = 64; // Endpoint 0 max packet size (64 bytes for HS control EP)
	usb_config.phy_itface = USB_OTG_HS_EMBEDDED_PHY ; // Use embedded PHY (if your MCU supports it)
	usb_config.Sof_enable = 1; // Enable SOF (Start Of Frame) output
	usb_config.low_power_enable = 0; // Disable low power mode (set 1 to enable)
	usb_config.lpm_enable = 0; // Disable Link Power Management
	usb_config.battery_charging_enable = 0; // Disable battery charging feature
	usb_config.vbus_sensing_enable = 1; // Enable VBUS sensing
	usb_config.use_dedicated_ep1 = 0; // Usually 0 unless you need dedicated EP1 interrupt
	usb_config.use_external_vbus = 0; // Disable external VBUS (set 1 if external VBUS pin used)


	HAL_StatusTypeDef status = USB_DevInit(USB_OTG_HS, usb_config);

		if (status == HAL_OK) {
		 log_info("It worked");
		} else {
			log_info("It didn't");
		 // Initialization error handling
		}

		USB_DriveVbus(USB_OTG_HS, 1);

}

static void gintsts_handler()
{


	volatile uint32_t gintsts = USB_ReadInterrupts(USB_OTG_HS_GLOBAL);
	//->GINTSTS;

	if (gintsts & USB_OTG_GINTSTS_USBRST) //USB RESET SIGNAL.
	{
		usbrst_handler();
//		// Clears the interrupt.
		SET_BIT(USB_OTG_HS_GLOBAL->GINTSTS, USB_OTG_GINTSTS_USBRST);
	}
	else if (gintsts & USB_OTG_GINTSTS_ENUMDNE) //ENUMERATION DONE
	{
		enumdne_handler();
////		// Clears the interrupt.
		SET_BIT(USB_OTG_HS_GLOBAL->GINTSTS, USB_OTG_GINTSTS_ENUMDNE);
	}
	else if (gintsts & USB_OTG_GINTSTS_RXFLVL)	//FIFO NOT EMPTY
	{
		rxflvl_handler();
//		// Clears the interrupt.
		SET_BIT(USB_OTG_HS_GLOBAL->GINTSTS, USB_OTG_GINTSTS_RXFLVL);
	}
	else if (gintsts & USB_OTG_GINTSTS_IEPINT)
	{
		iepint_handler();
////		// Clears the interrupt.
		SET_BIT(USB_OTG_HS_GLOBAL->GINTSTS, USB_OTG_GINTSTS_IEPINT);	//interrupt happened at in endpoint
	}
	else if (gintsts & USB_OTG_GINTSTS_OEPINT)
	{
		oepint_handler();
////		// Clears the interrupt.
		SET_BIT(USB_OTG_HS_GLOBAL->GINTSTS, USB_OTG_GINTSTS_OEPINT);
	}

	usb_events.on_usb_polled();

}

 

Any advice or comments would be much appreciated. 

 

Board is stm32u5g9. 

    This topic has been closed for replies.
    Best answer by AScha.3

    Aaa, now i understand (i dont have/tried U5G9 :( there is no (old) USB by STM .

    So you have to copy/install it yourself, or try it with the USBX (from Azure):

    there you can choose, which kind of USB device you want.

    read

    https://community.st.com/t5/stm32-mcus/how-to-implement-usbx-in-standalone-mode/ta-p/614435

     

     

    2 replies

    Maaz1Author
    Visitor II
    August 14, 2025

    I have attached the clk_test.ioc file if anyone would be kind enough to help

    Maaz1Author
    Visitor II
    August 15, 2025

    @AScha.3  @KDJEM.1 

     

    I have uploaded the schematic. If anyone can please have a look and let me know if there is some hardware problem I am missing.

     

    Kind regards

    Super User
    August 15, 2025

    Hi,

    > interrupt isn't being triggered when I connect the USB to my stm32 board

    and board is ? STM32U5G9J-DK2 ?

    What did you with the board ? made program...flash..?

    Connect to which USB ?

    AScha3_0-1755256812581.png

    CN8 is for connect/debug .

    Maaz1Author
    Visitor II
    August 15, 2025

    I did it to CN2

     

    STM32U5G9J-DK2

    flashed my board with stm32cubeprogrammer