Exemplo n.º 1
0
/**
  * @brief  USBD_CDC_DataOut
  *         Data received on non-control Out endpoint
  * @param  pdev: device instance
  * @param  epnum: endpoint number
  * @retval status
  */
static uint8_t  USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
{      
  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  USBD_CDC_EP_HandleTypeDef* hEP_Rx;
  if (epnum == CDC_OUT_EP) {
    hEP_Rx = &hcdc->CDC_Rx;
  } else if (epnum == ODRIVE_OUT_EP) {
    hEP_Rx = &hcdc->ODRIVE_Rx;
  } else {
    return USBD_FAIL;
  }
  
  /* Get the received data length */
  hEP_Rx->Length = USBD_LL_GetRxDataSize (pdev, epnum);
  
  /* USB data will be immediately processed, this allow next USB traffic being 
  NAKed till the end of the application Xfer */
  if(pdev->pClassData != NULL)
  {
    ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hEP_Rx->Buffer, &hEP_Rx->Length, epnum);

    return USBD_OK;
  }
  else
  {
    return USBD_FAIL;
  }
}
Exemplo n.º 2
0
/**
* @brief  MSC_BOT_CBW_Decode
*         Decode the CBW command and set the BOT state machine accordingtly  
* @param  pdev: device instance
* @retval None
*/
static void  MSC_BOT_CBW_Decode (USBD_HandleTypeDef  *pdev)
{
  USBD_MSC_BOT_HandleTypeDef  *hmsc = pdev->pClassData;  
  
  hmsc->csw.dTag = hmsc->cbw.dTag;
  hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
  
  if ((USBD_LL_GetRxDataSize (pdev ,MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
      (hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE)||
        (hmsc->cbw.bLUN > 1) || 
          (hmsc->cbw.bCBLength < 1) || 
            (hmsc->cbw.bCBLength > 16))
  {
    
    SCSI_SenseCode(pdev,
                   hmsc->cbw.bLUN, 
                   ILLEGAL_REQUEST, 
                   INVALID_CDB);
    
    hmsc->bot_status = USBD_BOT_STATUS_ERROR;   
    MSC_BOT_Abort(pdev);
 
  }
  else
  {
    if(SCSI_ProcessCmd(pdev,
                       hmsc->cbw.bLUN,
                       &hmsc->cbw.CB[0]) < 0)
    {
      if(hmsc->bot_state == USBD_BOT_NO_DATA)
      {
       MSC_BOT_SendCSW (pdev,
                         USBD_CSW_CMD_FAILED); 
      }
      else
      {
        MSC_BOT_Abort(pdev);
      }
    }
    /*Burst xfer handled internally*/
    else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && 
             (hmsc->bot_state != USBD_BOT_DATA_OUT) &&
             (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) 
    {
      if (hmsc->bot_data_length > 0)
      {
        MSC_BOT_SendData(pdev,
                         hmsc->bot_data, 
                         hmsc->bot_data_length);
      }
      else if (hmsc->bot_data_length == 0) 
      {
        MSC_BOT_SendCSW (pdev,
                         USBD_CSW_CMD_PASSED);
      }
    }
  }
}
Exemplo n.º 3
0
/**
  * @brief  USBD_CDC_DataOut
  *         Data received on non-control Out endpoint
  * @param  pdev: device instance
  * @param  epnum: endpoint number
  * @retval status
  */
static uint8_t  USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
{
    USBD_CDC_HandleTypeDef   *hcdc = pdev->pClassData;

    /* Get the received data length */
    hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);

    /* USB data will be immediately processed, this allow next USB traffic being
    NAKed till the end of the application Xfer */
    if(pdev->pClassData != NULL)
    {
        ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);

        return USBD_OK;
    }
    else
    {
        return USBD_FAIL;
    }
}
Exemplo n.º 4
0
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
{      
  USBD_CDC_HandleTypeDef *hcdc = context;
  uint32_t RxLength;
  unsigned index;

  for (index = 0; index < NUM_OF_CDC_UARTS; index++,hcdc++)
  {
    if (parameters[index].data_out_ep == epnum)
    {
      /* Get the received data length */
      RxLength = USBD_LL_GetRxDataSize (pdev, epnum);

      /* hand the data to the HAL */
      HAL_UART_Transmit_DMA(&hcdc->UartHandle, (uint8_t *)hcdc->OutboundBuffer, RxLength);

      break;
    }
  }

  return USBD_OK;
}
Exemplo n.º 5
0
/**
  * @brief  USBD_RAW_DataOut
  *			Data received on non-control Out endpoint (receive a packet from pc)
  *         handle data OUT Stage
  * @param  pdev: device instance
  * @param  epnum: endpoint index
  * @retval status
  */
static uint8_t  USBD_RAW_DataOut (USBD_HandleTypeDef *pdev,   uint8_t epnum)
{

	uint16_t size = USBD_LL_GetRxDataSize(pdev,epnum);

	//Before add, check if not buffer overflow
	if((rx_raw_FrameLen+size) >  SIZE_FRAME){
	  rx_raw_FrameLen = 0; //if buffer overflow restart at 0
	}
	//Copy packet at the end of Frame buffer
	memcpy (rx_raw_Frame+rx_raw_FrameLen,rx_raw_packet,size);
	rx_raw_FrameLen +=size;

	//last packet because packet lenght <  packet max  process trame
	if(size <  RAW_EP_SIZE){
	  //process command in the main loop to decrease the heap
	 // startProcessCommand = 1;
		processCommand();
	}else{
		// initiate next USB packet transfer,we don't have received full trame
	 USBD_LL_PrepareReceive(&hUsbDeviceFS,RAW_EPOUT_ADDR,rx_raw_packet,RAW_EP_SIZE);
	}
    return USBD_OK;
}
Exemplo n.º 6
0
/**
* @brief  USBD_GetRxCount
*         returns the received data length
* @param  pdev: device instance
* @param  ep_addr: endpoint address
* @retval Rx Data blength
*/
uint16_t  USBD_GetRxCount (USBD_HandleTypeDef  *pdev , uint8_t ep_addr)
{
  return USBD_LL_GetRxDataSize(pdev, ep_addr);
}