cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5G9 not detecting USB for unknown reason

Maaz1
Associate III

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. 

18 REPLIES 18

as in i set it to detect an interrupt, so when i pull the plug off and then reattach it, it should trigger a usb reset. Or atleast that's how I think it should be doing, I am not sure. What were you thinking?

If you want it to do anything, you set it in Cube to the device , maybe it should be : CDC (serial com.)

AScha3_0-1755273535853.png

and

AScha3_1-1755273579708.png

+ check if for your board some jumpers or pins have to be set, to enable power on the USB,

and the USB interrupt enabled (in NVIC).

Then connecting to a PC should start enumeration and you get a "serial" in the system.

You did this ?

If you feel a post has answered your question, please click "Accept as Solution".

I've done the first pic, set Vbus internal fs phy. I don't know where you got the second pic from?

here...

AScha3_0-1755279436531.png

 

>I've done the first pic

Thats : decision ->  host or device

 

>second pic

...then set, what it should be/do : serial CDC , keyboard HID , storage ...etc.

Otherwise it cannot "guess" , what you expect.

If you feel a post has answered your question, please click "Accept as Solution".

Hello

I have attached my clock ioc file and I can't find the USB_DEVICE option like the one you presented on your screenshot. Maybe I'm doing something wrong?

Maaz1_0-1755502790993.png

 

How did yiu ge the USB_Device part?

As always... :)

in IDE -> Cube -> pinout A-Z

AScha3_0-1755626352817.png

you see host or device - what you set to be active - then choose, what it should do:

AScha3_1-1755626485978.png

here OTG -->host  , then host --> MSC or other:

do same for device , what you want. (but device AND host same time dont work, so only one at a time is possible.)

+

read:

https://community.st.com/t5/stm32-mcus/usb-device-not-recognized/ta-p/49487

 

 

If you feel a post has answered your question, please click "Accept as Solution".

Maaz1_0-1755676187436.png

I'm still not getting USB_DEVICE, but USBX or USBPD

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

 

 

If you feel a post has answered your question, please click "Accept as Solution".