cancel
Showing results for 
Search instead for 
Did you mean: 

How to make STM32F103C8T6 (blue pill) USB CDC work properly

RLu
Associate

I have such dev board and try to run it as virtual com port. I created project cubemx, enable only usb as device in CDC mode. After generating and running project with next small fixes I run it on board.

int main(void)

{

//....skip

 while (1)

 {

   /* USER CODE END WHILE */

    const char* str = "Test\n";

    CDC_Transmit_FS((uint8_t*)str, 5);

    HAL_Delay(1000);

   /* USER CODE BEGIN 3 */

 }

gtkterm connects to the dev but no received and sent data.

When I started to debug interrupt handler I found that usb device always in USBD_STATE_DEFAULT mode since start and state isn't being changed instead of ISRs..

USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)

{

 if (pdev->dev_state == USBD_STATE_CONFIGURED)

 {

   if (pdev->pClass->SOF != NULL)

   {

     pdev->pClass->SOF(pdev);

   }

 }

 return USBD_OK;

}

I have read many tutorials and sample but the result is negative.

I have done USB CDC device successfully on STM32L476-DISCOVERY.

This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

This thread relates to a so-called Blue Pill, which uses illegally cloned STM32F103. ST resources are only dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes products work properly with the firmware we provide.

We recommend to purchase genuine products from STMicroelectronics and purchase them from known and trusted distributors.

This thread will now be locked. However, if you face difficulties while using genuine ST products, we’re here to assist you. Please feel free to start a new thread, and our team, along with community members, will be ready to help you with any issues/questions you encounter.

Thank you for your understanding.

Regards
/Peter

In order 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.

View solution in original post

2 REPLIES 2
RLu
Associate

Finally I found the bug. CubeMX doesn't generate whole setup.

Next code must be added into usbd_cdc_if.c:

/* Private variables ---------------------------------------------------------*/
USBD_CDC_LineCodingTypeDef LineCoding =
{
    9600,   /* baud rate*/
    0x00,   /* stop bits-1*/
    0x00,   /* parity - none*/
    0x08    /* nb. of bits 8*/
};
/* USER CODE END PV */

And:

    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;
 
    case CDC_SET_CONTROL_LINE_STATE:

Is this bug or not?

Peter BENSCH
ST Employee

This thread relates to a so-called Blue Pill, which uses illegally cloned STM32F103. ST resources are only dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes products work properly with the firmware we provide.

We recommend to purchase genuine products from STMicroelectronics and purchase them from known and trusted distributors.

This thread will now be locked. However, if you face difficulties while using genuine ST products, we’re here to assist you. Please feel free to start a new thread, and our team, along with community members, will be ready to help you with any issues/questions you encounter.

Thank you for your understanding.

Regards
/Peter

In order 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.