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.