cancel
Showing results for 
Search instead for 
Did you mean: 

Transmit data through CDC VCP Failed error

AElta.1
Associate II

I am trying transmit data using CDC(virtual port) in NUCLEO-H743Zi2, but I am getting this error when I plug in my VCP port to my pc (Unknown USB Device (Device Descriptor Request Failed)), I could not find a way to fix it.

My hardware settings:

MCU speed set to MAX(480Mhz)

USB_OTG_FS : Device Only | VBUS sensing | enabled Activate SOF

USB_Device : CDC(VPC).

my transmission code:

/* USER CODE BEGIN PD */
#include "main.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"
#include "string.h"
/* USER CODE END PD */
char *data = "Hello there";
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART3_UART_Init();
  MX_DMA_Init();
  MX_SPI1_Init();
  MX_USB_DEVICE_Init();
 /* Infinite loop */
            while (1) {
    /* USER CODE END WHILE */
            	CDC_Transmit_FS((uint8_t *) data , strlen(data));
            	            	HAL_Delay (1000);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

The debugging steps I followed:

  1. Changed min heap size = 0x2000 and min stack size = 0x2000 (I tried several values)
  2. downloaded the VCP driver even though I am using win10.
  3. The global interrupt is enabled.
  4. set get Line coding function:
USBD_CDC_LineCodingTypeDef LineCoding = {
 115200,                       /* baud rate */
0x00,                         /* stop bits-1 */
  0x00,                         /* parity - none */
 0x08                          /* nb. of bits 8 */
};
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
switch(cmd)
  {
case CDC_SET_LINE_CODING:
    LineCoding.bitrate = (uint32_t) (pbuf[0] | (pbuf[1] << 8) |
    	                                         (pbuf[2] << 16) | (pbuf[3] << 24));
    	        LineCoding.format = pbuf[4];
    	        LineCoding.paritytype = pbuf[5];
    	        LineCoding.datatype = pbuf[6];
    break;
 
    case CDC_GET_LINE_CODING:
    	 pbuf[0] = (uint8_t) (LineCoding.bitrate);
    	        pbuf[1] = (uint8_t) (LineCoding.bitrate >> 8);
    	        pbuf[2] = (uint8_t) (LineCoding.bitrate >> 16);
    	        pbuf[3] = (uint8_t) (LineCoding.bitrate >> 24);
    	        pbuf[4] = LineCoding.format;
    	        pbuf[5] = LineCoding.paritytype;
    	        pbuf[6] = LineCoding.datatype;
break;
...
  }
 
  return (USBD_OK);
  /* USER CODE END 5 */
}

But still I am getting (Unknown USB Device (Device Descriptor Request Failed) before running the code and after.

5 REPLIES 5
Imen.D
ST Employee

Hello @AElta.1​ 

Do you have drivers installed STM32 Virtual COM Port Driver ?

 I advise you to follow this FAQ: USB device not recognized, it may help you:

  • Try increase the heap size or configure the USB library to use static allocation, as recommended in the FAQ.

You may get inspired from CDC_Standalone examples within STM32H7 MCU package, which can help you to develop your application:

\STM32Cube_FW_H7_V1.10.0\Projects\STM32H743I-EVAL\Applications\USB_Device\CDC_Standalone\

Note: When DMA is used, the MX_DMA_Init shall always be called before any other  peripheral initialization. Please refer to this post.

Please keep me informed if you still need help.

If my answer fully solved your issue, please mark it as best by clicking on the "Select as Best" button. This will help other users find this solution more quickly.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

hi I tried what u suggested but I am sill facing the same issue

0693W00000SvyAbQAJ.png

Check if USB_OTG_FS_DP and USB_OTG_FS_DM wires are swapped.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

I thought using Nucleo-H743ZI2 will connect the USB_OTG_FS pin to USB automatically

Even though I checked and no wrong connections.

Hi @AElta.1​ ,

Please check these FAQs:

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen