2025-08-13 8:53 AM
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.