AnsweredAssumed Answered

STm32F USB VCP example

Question asked by B Zikhali on Mar 10, 2015
Latest reply on Mar 16, 2015 by B Zikhali
I am building a microcontroller based on the STM32F302K8 chip and I am trying to send data to host PC via USB. My echo code below based on an example in the forums works:

static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
    static uint8_t buff_RX[256];
    static uint8_t buff_TX[256];
    int i = 0;
    for (i = 0; i < *Len; i++)
        buff_TX[i] = buff_RX[i];
    USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &buff_TX[0], *Len);
    USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &buff_RX[0]);
  return (USBD_OK);
  /* USER CODE END 7 */

But when I implement the following code to send from MCU to host, I fall into an Infinite Loop (Default_Handler in startup_stm32f302x8.s)

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
  uint8_t result = USBD_OK;
  int i;
  //memcpy(UserTxBufferFS, Buf, Len);   //not sure why but memcpy is not working here
   USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBufferFS, Len);
  result = USBD_CDC_TransmitPacket(hUsbDevice_0);
  /* USER CODE END 8 */
  return result;

I have looked all over the internet for a solution including the forums on this site, why is this happening? With regards to the recieve code, how is the loop reading from RX_Buff when it is set as the Receiving buffer only after the loop?

Does anyone have the USB as VCP examples mentioned in the Software Development Kit PDF? I have been to every nook and cranny of this website and all the links seem to be dead!