AnsweredAssumed Answered

STM32F103 Virtual Com Port problem

Question asked by Teddy Bonkers on Jul 30, 2015
Hello

I have been trying to implement the VCP on a chip I am working on. I do not have any experience with USB and I just want to get this working so I can send some data to the device (will focus on USB later). I am using Eclipse + GCC and Cube for the initialising code. My PC recognizes the chip as COM port so far. Here's my code:
nt main(int argc, char* argv[])
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    SystemClock_Config();
    HAL_Init();
    MX_USB_DEVICE_Init();
 
    uint8_t data[] = "Hello";
    HAL_Delay(1000);
 
    // Infinite loop
    while (1)
    {
        HAL_Delay(1000);
        CDC_Transmit_FS(data, 5);
 
    }
}
 
void MX_USB_DEVICE_Init(void)
{
  /* Init Device Library,Add Supported Class and Start the library*/
  USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
 
  USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC);
 
  USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
 
  USBD_Start(&hUsbDeviceFS);
 
}

However, when I call CDC_Transmit_FS(), I get a hard fault in the function USBD_CDC_SetTxBuffer(). The function CDC_Init_FS() is never called and the USBD_CDC_SetTxBuffer() function uses a variable that is never initialized. I saw a thread with a problem identical to mine at http://electronics.stackexchange.com/questions/161772/stm32-usb-vcp-bug but I can't make it work.

Thanks!



Outcomes