I'm trying to figure out how to enable USB VCP functionality on my STM32F103-based Blue Pill board. In following Shawn Hymell's guide and attempting to troubleshoot with this other SO Q/A, I currently have the following (minified) main.c
: (Git Gist with full file)
#include "main.h"
#include "usb_device.h"
#include <string.h>
int main(void) {
char msg[50];
uint8_t state = 0;
HAL_StatusTypeDef ret_status;
MX_USB_DEVICE_Init();
sprintf(msg, "Restart!\n");
ret_status = HAL_UART_Transmit(&huart1, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
HAL_Delay(1000);
while (1) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, state ? GPIO_PIN_RESET : GPIO_PIN_SET);
sprintf(msg, "Hello World! LED State: %d\n", state);
ret_status = HAL_UART_Transmit(&huart1, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
ret_status = CDC_Transmit_FS((uint8_t*)msg, strlen(msg));
state = state == 1 ? 0 : 1;
HAL_Delay(500);
}
}
I can tell that the program is (otherwise) running properly because the UART adapter shows that char msg
is being output at the correct interval and the board's PC13
LED is flashing. However, my Windows 10 computer doesn't even recognize that there is a USB device plugged in, only showing the FTDI adapter's COM port and my STLink v2:
As of now, I've tried the following potential fixes from the other SO Q/A:
- In
usbd_cdc_if.c
setAPP_RX_DATA_SIZE 64
andAPP_TX_DATA_SIZE 64
- In
usbd_cdc_if.c
add below code to the CDC_Control_FS() function:
case CDC_SET_LINE_CODING:
tempbuf[0]=pbuf[0];
tempbuf[1]=pbuf[1];
tempbuf[2]=pbuf[2];
tempbuf[3]=pbuf[3];
tempbuf[4]=pbuf[4];
tempbuf[5]=pbuf[5];
tempbuf[6]=pbuf[6];
break;
case CDC_GET_LINE_CODING:
pbuf[0]=tempbuf[0];
pbuf[1]=tempbuf[1];
pbuf[2]=tempbuf[2];
pbuf[3]=tempbuf[3];
pbuf[4]=tempbuf[4];
pbuf[5]=tempbuf[5];
pbuf[6]=tempbuf[6];
break;
- Add
HAL_Delay(1000);
before the first instance of callingCDC_Transmit_FS
- Confirmed that the USB cable I'm using has data lines
- Setting
Minimum Heap Size
to0x1000
in the CubeMX Device Configuration Tool
Has anyone else seen something like this before? I'm not sure what to try next.