Reputation: 6832
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:
usbd_cdc_if.c
set APP_RX_DATA_SIZE 64
and APP_TX_DATA_SIZE 64
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;
HAL_Delay(1000);
before the first instance of calling CDC_Transmit_FS
Minimum Heap Size
to 0x1000
in the CubeMX Device Configuration ToolHas anyone else seen something like this before? I'm not sure what to try next.
Upvotes: 1
Views: 818
Reputation: 6832
Actually, my problem was far more simple than I thought. In my infinite wisdom, I decided to try this on a breadboard I'd previously been using for CANbus testing, without disconnecting the CAN circuit.
(ref)
This was never going to work, as the CANbus pins I'd been trying to use (and left plugged in) share functionality with the USB port. The VCP immediately showed up and worked after I unplugged the breadboard wires I'd connected to PA11
and PA12
. I feel dumb, but relieved, right now.
Upvotes: 1