STM32L4 Won't Trigger USB Interrupt on One Project, But Will On Another
I have a custom board based around the STM32L496 that creates a USB HID device. I have two projects (built in IAR Embedded Workbench), both of which have this board and micro as their target. On the exact same board, one will enumerate USB at FS, one won't. On the one that doesn't enumerate, the OTG_FS_IRQHandler never fires. I can readily switch between projects, emulating using an STLink, and one works perfectly, while one doesn't work at all.
All of the libary code (HAL Drivers, USB Middleware, etc.) is 100% identical and taken directly from the latest version of STCube. I have verified it is identical using a WinMerge compare. My application code is virtually identical between the two projects. In fact, the "working" project is really a subset of the code in the non-working project.
To troubleshoot, I have combed through the two projects looking for differences that would explain the difference in behavior. I have isolated a subset of the code in the non-working project. This code does nothing but init the system clock, init the HAL, and init the USB. It's the first code hit when run from main(). This section of code works on the good project, but not on the bad project. I can set a breakpoint just after this init code, and the good project will have enumerated USB, while the bad project shows absolutely no USB traffic of any kind (verified on a protocol analyzer). A breakpoint in the IRQ handler in the bad project is never hit; the device state never changes from "Default" (i.e., never changes to Addressed, Configured or Suspended).
I'm getting kind of desperate here and starting to think of the possibility of weird, one-off issues. Obviously, there are differences in exactly which memory locations variables and functions are stored in; the bad project has more code that the linker is placing. But beyond memory location differences, can anyone think of anything else that might be stopping the IRQ from firing? Assume the code is indeed identical. I've included it here for the record.
HAL_Init();
RCC_Configuration();
SystemClock_Config();
MX_USB_OTG_FS_PCD_Init();
InitUsbVars();
/* Enable USB power on Pwrctrl CR2 register */
HAL_PWREx_EnableVddUSB();
/* Init Device Library */
USBD_Init(g_pdev, &HID_Desc, 0);
/* Add Supported Class */
USBD_RegisterClass(g_pdev, &USBD_HID);
/* Add Custom HID callbacks */
USBD_HID_RegisterInterface(g_pdev, &USBD_fops);
/* Start Device Process */
USBD_Start(g_pdev);
WaitUntilConfigured();enter code here
