2025-08-19 7:24 AM
Hello all
I'm trying to use the HAL library for STM32U5G9 and have encountered errors in the code, which I don't know how to solve
Description Resource Path Location Type
'PCD_SNG_BUF' undeclared (first use in this function) usbd_conf.c /usb_hal/Middleware/ST/USB_DEVICE/Target line 447 C/C++ Problem
'USB_LP_IRQn' undeclared (first use in this function) usbd_conf.c /usb_hal/Middleware/ST/USB_DEVICE/Target line 87 C/C++ Problem
'USB_LP_IRQn' undeclared (first use in this function) usbd_conf.c /usb_hal/Middleware/ST/USB_DEVICE/Target line 117 C/C++ Problem
'USBWakeUp_IRQn' undeclared (first use in this function) usbd_conf.c /usb_hal/Middleware/ST/USB_DEVICE/Target line 93 C/C++ Problem
'USBWakeUp_IRQn' undeclared (first use in this function) usbd_conf.c /usb_hal/Middleware/ST/USB_DEVICE/Target line 119 C/C++ Problem
and these are the relevant lines
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x00, PCD_SNG_BUF, 0x0C);
/////////////////////////////////////////////////
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
if(pcdHandle->Instance==USB)
{
/* USER CODE BEGIN USB_MspInit 0 */
/* USER CODE END USB_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(USB_LP_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
if(pcdHandle->Init.low_power_enable == 1)
{
/* Enable EXTI Line 18 for USB wakeup */
__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
HAL_NVIC_SetPriority(USBWakeUp_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USBWakeUp_IRQn);
}
/* USER CODE BEGIN USB_MspInit 1 */
/* USER CODE END USB_MspInit 1 */
}
}
/////////////////////////////////////////////
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
if(pcdHandle->Instance==USB)
{
/* USER CODE BEGIN USB_MspInit 0 */
/* USER CODE END USB_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(USB_LP_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
if(pcdHandle->Init.low_power_enable == 1)
{
/* Enable EXTI Line 18 for USB wakeup */
__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
HAL_NVIC_SetPriority(USBWakeUp_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USBWakeUp_IRQn);
}
/* USER CODE BEGIN USB_MspInit 1 */
/* USER CODE END USB_MspInit 1 */
}
}
I have even attached the C file.
Admittedly, I ported these files from the STM32CUBEG4, so it may not be compatible with u5, but surely modifications could be made to make it more accessible?
Kind regards
2025-08-19 7:29 AM
The compiler says that PCD_SNG_BUF is not defined. Is it? Where? Ensure it is defined prior to being used. Use Search -> File... from the menu to see where it exists within the project files.
It's not defined anywhere in the C file you attached.
2025-08-19 2:36 PM
Check stm32u5xx_hal_conf.h as to what's being pulled in.
Check command line defines passed to the compiler, the part designation for sure.
Make sure the IRQ Handlers and enumerations are consistent between the STM32 models. Check naming in startup.s and enumerations for STM32U5G9 specifically.
Find-in-Files, or grep for : USBWakeUp_IRQn USB_LP_IRQn, etc
2025-08-20 1:55 AM
Hi
It was defined in some other header file as 0U, and the code has been amended to reflect that
2025-08-20 1:58 AM
Hi, this is the part I'm struggling with currently. The comments say
/* Enable EXTI Line 18 for USB wakeup */
__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
HAL_NVIC_SetPriority(USBWakeUp_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USBWakeUp_IRQn);
but I'm not sure that the stm32u5g9 has that same configuration as well
or rather, I don't know how to read this
STM32U5 series Arm<Sup>®</Sup>-based 32-bit MCUs - Reference manual
I've attached the reference manual for use
2025-08-20 6:07 AM
Are there U5 examples you could start from instead? Yes, quite a few things will be different between those two chips.