cancel
Showing results for 
Search instead for 
Did you mean: 

CDC USB fails at the Python level on the PC

T J
Lead

there is some code left out of the Cube initialisation that causes this issue

please put this back in...

using L432 today, but this issue is a HAL problem.

This corrected function fixes this issue. ( thanks to stack overflow)

https://stackoverflow.com/questions/56490843/what-is-issue-with-stm32-virtual-com-port-i-can-not-open-it

/**
  * @brief  Manage the CDC class requests
  * @param  cmd: Command code
  * @param  pbuf: Buffer containing command data (request parameters)
  * @param  length: Number of data to be sent (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
  /* USER CODE BEGIN 5 */
    
    static uint8_t lineCoding[7] // 115200bps, 1stop, no parity, 8bit 
        = { 0x00, 0xC2, 0x01, 0x00, 0x00, 0x00, 0x08 };
    
  switch(cmd)
  {
    case CDC_SEND_ENCAPSULATED_COMMAND:
 
    break;
 
    case CDC_GET_ENCAPSULATED_RESPONSE:
 
    break;
 
    case CDC_SET_COMM_FEATURE:
 
    break;
 
    case CDC_GET_COMM_FEATURE:
 
    break;
 
    case CDC_CLEAR_COMM_FEATURE:
 
    break;
 
  /*******************************************************************************/
  /* Line Coding Structure                                                       */
  /*-----------------------------------------------------------------------------*/
  /* Offset | Field       | Size | Value  | Description                          */
  /* 0      | dwDTERate   |   4  | Number |Data terminal rate, in bits per second*/
  /* 4      | bCharFormat |   1  | Number | Stop bits                            */
  /*                                        0 - 1 Stop bit                       */
  /*                                        1 - 1.5 Stop bits                    */
  /*                                        2 - 2 Stop bits                      */
  /* 5      | bParityType |  1   | Number | Parity                               */
  /*                                        0 - None                             */
  /*                                        1 - Odd                              */
  /*                                        2 - Even                             */
  /*                                        3 - Mark                             */
  /*                                        4 - Space                            */
  /* 6      | bDataBits  |   1   | Number Data bits (5, 6, 7, 8 or 16).          */
  /*******************************************************************************/
    case CDC_SET_LINE_CODING:
      memcpy(lineCoding, pbuf, sizeof(lineCoding));
    break;
 
    case CDC_GET_LINE_CODING:
      memcpy(pbuf, lineCoding, sizeof(lineCoding));
    break;
 
    case CDC_SET_CONTROL_LINE_STATE:
 
    break;
 
    case CDC_SEND_BREAK:
 
    break;
 
  default:
    break;
  }
 
  return (USBD_OK);
  /* USER CODE END 5 */
}

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Community member​ ,

Thanks for your feedback and sorry for the somewhat late reply.

You're right, when generating USB CDC class from CubeMX, the CDC_SET_LINE_CODING and CDC_GET_LINE_CODING USB request are not implemented in CDC_Control_FS function in usbd_cdc_if.c file.

Actually, what STM32CubeMX delivers by default is a template for a project, without forcing the user to use a specific configuration as each one has his own implementation. Thus, we put the CDC_Control_FS void under user section to make each one able to add his own code and what CubeMX ensures is to keep it after regeneration.

With this being said,  I will bring this point up internally and see how we can address a modification to improve the usbd_cdc_if generated by CubeMX.

Meanwhile, the Example selector allows you to browse a large set of CDC examples and to start a project based on a selected example. Those examples may be a good start point to successfully create your project:

0693W00000D2gl0QAB.png 

Thanks for your contribution.

Khouloud.

View solution in original post

5 REPLIES 5
TDK
Guru

These lines (well, equivalent lines) are in there in the template:

https://github.com/STMicroelectronics/STM32CubeL4/blob/5e1553e07706491bd11f4edd304e093b6e4b83a4/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc_if_template.c#L153

But for some reason they're not in the populated code. I would argue it's a CubeMX generation bug rather than HAL.

If you feel a post has answered your question, please click "Accept as Solution".
Amel NASRI
ST Employee

Hi @Community member​  & @TDK​ ,

That's quite interesting to deeply check the root cause of the issue.

So to be aligned on the conditions to reproduce it, do you confirm @Community member​ that you are using latest STM32CubeMX version to generate code?

If yes, then we need the help of our STM32CubeMX experts @Khouloud ZEMMELI​  @Khouloud OTHMAN​  in order to report it to development team who will take required corrective actions.

-Amel

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.

-Amel,

I am using 6.1.2. just noticed 6.3.0 is available,

I use the MDK-ARM updater(now 5.27) to update the Visual Studio project, because the GPDSC never works correctly

-TJ

T J
Lead

@TDK​  yes its a Cube issue, likely to be across all processors...

Hello @Community member​ ,

Thanks for your feedback and sorry for the somewhat late reply.

You're right, when generating USB CDC class from CubeMX, the CDC_SET_LINE_CODING and CDC_GET_LINE_CODING USB request are not implemented in CDC_Control_FS function in usbd_cdc_if.c file.

Actually, what STM32CubeMX delivers by default is a template for a project, without forcing the user to use a specific configuration as each one has his own implementation. Thus, we put the CDC_Control_FS void under user section to make each one able to add his own code and what CubeMX ensures is to keep it after regeneration.

With this being said,  I will bring this point up internally and see how we can address a modification to improve the usbd_cdc_if generated by CubeMX.

Meanwhile, the Example selector allows you to browse a large set of CDC examples and to start a project based on a selected example. Those examples may be a good start point to successfully create your project:

0693W00000D2gl0QAB.png 

Thanks for your contribution.

Khouloud.