2026-03-11 7:59 AM - last edited on 2026-03-12 4:28 AM by mƎALLEm
Hi,
I have created a project in STM32CUBEIDE for STM32U575ZITQ for USB CDC. I am getting an
85 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
| ^~~~~~~~~~~~~~~~~~~
| HAL_PWREx_PVMConfig
../USB/Core/Src/usbd_conf.c:85:68: error: 'PCD_SNG_BUF' undeclared (first use in this function)
85 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
I am following the link below to create the project:
I have tried with USBX but no result. After that I followed above link to create a USB CDC project.
Regards,
Abhishek
Solved! Go to Solution.
2026-03-12 2:46 AM
Hello @APD and welcome to STcommunity!
the article you followed is based on STM32H5 product which doesn't use the same USB controller as your specific STM32U575 so instance names are not the same.
the STM32H5 uses USB_DRD_FS like the STM32U545 etc...
while STM32U575 uses USB_OTG_FS
Can you try these steps and see if it work :
Start by creating a new project using the STM32CubeMX by clicking [File -> New -> STM32 Project].
Once the project creation is done, enable the USB peripheral [USB] peripheral in device only mode, located in the [Connectivity] section.
Enable the [CRS SYNC SOURCE USB] option in CRS SYNC, located in the [RCC] section.
Enable the [CORE] in THREADX, located in the [Middleware and software packages] section.
Increment the [TX_MINIMUM_STACK] to 800 bytes.
Enable the [Core system] [Device CoreStack FS] [Device Controllers FS] [CDC ACM] in USBX, located in the [Middleware and software packages] section.
Change [UXDevice memory pool size] to 12*1024.
Change [USBX Device system Stack size] to 6*1024.
In the [CLOCK CONFIGURATION], just ensure that the USB is getting a 48MHZ signal.
In the project manager, select advanced settings and fill the options like this.
Now, name your project and generate your code.
Now, we just need to add these parts of code in our project:
In app_usbx_device.c:
/* USER CODE BEGIN Includes */
#include "main.h"
/* USER CODE END Includes */
/* USER CODE BEGIN PV */
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
static TX_THREAD ux_cdc_write_thread;
TX_EVENT_FLAGS_GROUP EventFlag;
TX_QUEUE ux_app_MsgQueue;
/* USER CODE END PV */
in MX_USBX_Device_Init
/* USER CODE BEGIN MX_USBX_Device_Init1 */
if (tx_thread_create(&ux_cdc_write_thread, "cdc_acm_write_usbx_app_thread_entry",
usbx_cdc_acm_write_thread_entry, 1, pointer,
1024, 20, 20, TX_NO_TIME_SLICE,
TX_AUTO_START) != TX_SUCCESS)
{
return TX_THREAD_ERROR;
}
/* Create the event flags group */
if (tx_event_flags_create(&EventFlag, "Event Flag") != TX_SUCCESS)
{
return TX_GROUP_ERROR;
}
/* USER CODE END MX_USBX_Device_Init1 */static VOID app_ux_device_thread_entry(ULONG thread_input)
{
/* USER CODE BEGIN app_ux_device_thread_entry */
MX_USB_OTG_FS_PCD_Init();
/* USER CODE BEGIN USB_Device_Init_PreTreatment_1 */
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, USBD_MAX_EP0_SIZE / 4);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, USBD_CDCACM_EPIN_FS_MPS / 4);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, USBD_CDCACM_EPINCMD_FS_MPS / 4);
ux_dcd_stm32_initialize((ULONG)USB_OTG_FS, (ULONG)&hpcd_USB_OTG_FS);
HAL_PCD_Start(&hpcd_USB_OTG_FS);
/* USER CODE END app_ux_device_thread_entry */
}
/* USER CODE BEGIN PV */
UX_SLAVE_CLASS_CDC_ACM *cdc_acm;
extern TX_EVENT_FLAGS_GROUP EventFlag;
/* USER CODE END PV */VOID USBD_CDC_ACM_Activate(VOID *cdc_acm_instance)
{
/* USER CODE BEGIN USBD_CDC_ACM_Activate */
cdc_acm = (UX_SLAVE_CLASS_CDC_ACM*) cdc_acm_instance;
/* USER CODE END USBD_CDC_ACM_Activate */
return;
}
/* USER CODE BEGIN 1 */
VOID usbx_cdc_acm_write_thread_entry(ULONG thread_input)
{
UX_PARAMETER_NOT_USED(thread_input);
ULONG actual_length;
unsigned int counter = 1;
/* Buffer must be large enough for base_msg + number + CRLF + '\0' */
char Tx_Buffer[16];
/* Base message without number */
const char base_msg[] ="helloworld";
while (1)
{
/* Format: base message + incrementing number + CRLF */
int len = snprintf(Tx_Buffer, sizeof(Tx_Buffer), "%s%u\r\n", base_msg, counter);
/* Check for truncation or error (optional but good practice) */
/* Formatting error or truncated – handle as needed, e.g. clip len */
len = sizeof(Tx_Buffer);
/* Transmit the string over USB CDC ACM */
ux_device_class_cdc_acm_write(cdc_acm, (UCHAR *)Tx_Buffer, (ULONG)len, &actual_length);
/* Increment counter so next message has next number */
counter++;
/* Delay between transmissions */
tx_thread_sleep(10UL);
}
}
/* USER CODE END 1 */
In ux_device_cdc_acm.h:
/* USER CODE BEGIN 1 */
VOID usbx_cdc_acm_write_thread_entry(ULONG thread_input);
/* USER CODE END 1 */
Here all the code implementation is done! You can build and flash the code into your device and try it!
You can also follow this example
BR
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2026-03-12 2:46 AM
Hello @APD and welcome to STcommunity!
the article you followed is based on STM32H5 product which doesn't use the same USB controller as your specific STM32U575 so instance names are not the same.
the STM32H5 uses USB_DRD_FS like the STM32U545 etc...
while STM32U575 uses USB_OTG_FS
Can you try these steps and see if it work :
Start by creating a new project using the STM32CubeMX by clicking [File -> New -> STM32 Project].
Once the project creation is done, enable the USB peripheral [USB] peripheral in device only mode, located in the [Connectivity] section.
Enable the [CRS SYNC SOURCE USB] option in CRS SYNC, located in the [RCC] section.
Enable the [CORE] in THREADX, located in the [Middleware and software packages] section.
Increment the [TX_MINIMUM_STACK] to 800 bytes.
Enable the [Core system] [Device CoreStack FS] [Device Controllers FS] [CDC ACM] in USBX, located in the [Middleware and software packages] section.
Change [UXDevice memory pool size] to 12*1024.
Change [USBX Device system Stack size] to 6*1024.
In the [CLOCK CONFIGURATION], just ensure that the USB is getting a 48MHZ signal.
In the project manager, select advanced settings and fill the options like this.
Now, name your project and generate your code.
Now, we just need to add these parts of code in our project:
In app_usbx_device.c:
/* USER CODE BEGIN Includes */
#include "main.h"
/* USER CODE END Includes */
/* USER CODE BEGIN PV */
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
static TX_THREAD ux_cdc_write_thread;
TX_EVENT_FLAGS_GROUP EventFlag;
TX_QUEUE ux_app_MsgQueue;
/* USER CODE END PV */
in MX_USBX_Device_Init
/* USER CODE BEGIN MX_USBX_Device_Init1 */
if (tx_thread_create(&ux_cdc_write_thread, "cdc_acm_write_usbx_app_thread_entry",
usbx_cdc_acm_write_thread_entry, 1, pointer,
1024, 20, 20, TX_NO_TIME_SLICE,
TX_AUTO_START) != TX_SUCCESS)
{
return TX_THREAD_ERROR;
}
/* Create the event flags group */
if (tx_event_flags_create(&EventFlag, "Event Flag") != TX_SUCCESS)
{
return TX_GROUP_ERROR;
}
/* USER CODE END MX_USBX_Device_Init1 */static VOID app_ux_device_thread_entry(ULONG thread_input)
{
/* USER CODE BEGIN app_ux_device_thread_entry */
MX_USB_OTG_FS_PCD_Init();
/* USER CODE BEGIN USB_Device_Init_PreTreatment_1 */
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, USBD_MAX_EP0_SIZE / 4);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, USBD_CDCACM_EPIN_FS_MPS / 4);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, USBD_CDCACM_EPINCMD_FS_MPS / 4);
ux_dcd_stm32_initialize((ULONG)USB_OTG_FS, (ULONG)&hpcd_USB_OTG_FS);
HAL_PCD_Start(&hpcd_USB_OTG_FS);
/* USER CODE END app_ux_device_thread_entry */
}
/* USER CODE BEGIN PV */
UX_SLAVE_CLASS_CDC_ACM *cdc_acm;
extern TX_EVENT_FLAGS_GROUP EventFlag;
/* USER CODE END PV */VOID USBD_CDC_ACM_Activate(VOID *cdc_acm_instance)
{
/* USER CODE BEGIN USBD_CDC_ACM_Activate */
cdc_acm = (UX_SLAVE_CLASS_CDC_ACM*) cdc_acm_instance;
/* USER CODE END USBD_CDC_ACM_Activate */
return;
}
/* USER CODE BEGIN 1 */
VOID usbx_cdc_acm_write_thread_entry(ULONG thread_input)
{
UX_PARAMETER_NOT_USED(thread_input);
ULONG actual_length;
unsigned int counter = 1;
/* Buffer must be large enough for base_msg + number + CRLF + '\0' */
char Tx_Buffer[16];
/* Base message without number */
const char base_msg[] ="helloworld";
while (1)
{
/* Format: base message + incrementing number + CRLF */
int len = snprintf(Tx_Buffer, sizeof(Tx_Buffer), "%s%u\r\n", base_msg, counter);
/* Check for truncation or error (optional but good practice) */
/* Formatting error or truncated – handle as needed, e.g. clip len */
len = sizeof(Tx_Buffer);
/* Transmit the string over USB CDC ACM */
ux_device_class_cdc_acm_write(cdc_acm, (UCHAR *)Tx_Buffer, (ULONG)len, &actual_length);
/* Increment counter so next message has next number */
counter++;
/* Delay between transmissions */
tx_thread_sleep(10UL);
}
}
/* USER CODE END 1 */
In ux_device_cdc_acm.h:
/* USER CODE BEGIN 1 */
VOID usbx_cdc_acm_write_thread_entry(ULONG thread_input);
/* USER CODE END 1 */
Here all the code implementation is done! You can build and flash the code into your device and try it!
You can also follow this example
BR
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2026-03-14 10:31 AM
Thanks, Code worked and able to get the USB virtual COM PORT.
2026-03-14 10:51 AM
Please provide me with the steps to test the VCP port through UART. I need the example or steps to configure the USB as MSC and read the Micro SD card using SDIO 4-bit. I hope I need to configure the FATFS configuration to achieve the same.