AnsweredAssumed Answered

stm32f407 USB device transmit data to pc:0xc0000004

Question asked by yuanlong.xie on May 22, 2015
Hello,everyone!
I am using stm32f407 usb device to communicate with pc.I can get every packet from pc to stm32 correctly.Pc can receive the packet from stm32 firstly,but it can not get the packet after a while.Througth debugger,the transmit function is still working ,moreover it can return USBD OK!And the data of Txbuffer[2048] is just what i put there.Using Device-Monitoring-Studio,the error code is 0xc0000004.Here is my code.Thank for all your help!
Init function in main function:
  /* Init Device Library */
  USBD_Init(&USBD_Device, &VCP_Desc, 0);
   
  /* Add Supported Class */
  USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS);
   
  /* Add CDC Interface Class */
  USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
   
  /* Start Device Process */
  USBD_Start(&USBD_Device);
 
USB_SENDDATA function:
 
uint8_t usb_SendData(uint8_t *pbUsrBuf, uint32_t wNBytes)
{
   uint8_t USB_tx_check = 0;
   uint8_t Data_TR_Flag=0x00;
   for(u8 i=0;i< wNBytes ;i++)
      
   UserTxBuffer[i]= pbUsrBuf[i];
 
   USBD_CDC_SetTxBuffer(&USBD_Device, (uint8_t*)&UserTxBuffer, wNBytes);
   Data_TR_Flag = USBD_CDC_TransmitPacket(&USBD_Device);
    
  if(USB_tx_check == USBD_OK)    //上次数据已经发送完毕,可以向端点写数据了
  {
    Data_TR_Flag = 1;
  }
  else
    Data_TR_Flag = 0;
   
   return Data_TR_Flag;
}

Outcomes