AnsweredAssumed Answered

STM32F072 DISCO USB cdc device sending data to PC

Question asked by aydin.oguz on Feb 24, 2014
Latest reply on Nov 8, 2016 by Muhammad Moiz khan
Hi, 
     I'm working on STM32F072-DISCO to send data over USB using cdc device. At this point, i am thinking that i achieved description part. So that i can see the device as a VCP when i plug it. But i m not able to send data over USB yet. These are my config files:

usb_conf.h:
#define USB_DEVICE_LOW_PWR_MGMT_SUPPORT
 
 
/* Configure the USB clock source as HSI48 with Clock Recovery System(CRS)*/
#define USB_CLOCK_SOURCE_CRS
 
/* Endpoints used by the device */
#define EP_NUM     (4) 
 
/* buffer table base address */
#define BTABLE_ADDRESS      (0x000)
 
/* EP0, RX/TX buffers base address */
#define ENDP0_RX_ADDRESS   (0x40)
#define ENDP0_TX_ADDRESS   (0x80)
 
#define INT_IN_TX_ADDRESS   (0xC0)
#define BULK_IN_TX_ADDRESS  (0x100)
#define BULK_OUT_RX_ADDRESS  (0x110)

usbd_conf.h:
#define USBD_CFG_MAX_NUM                1
#define USBD_ITF_MAX_NUM                1
 
//#define USBD_SELF_POWERED
 
#define USB_MAX_STR_DESC_SIZ            255
 
/** @defgroup USB_VCP_Class_Layer_Parameter
  * @{
  */
#define CDC_IN_EP                       0x81  /* EP1 for data IN */
#define CDC_OUT_EP                      0x01  /* EP1 for data OUT */
#define CDC_CMD_EP                      0x82  /* EP2 for CDC commands */
 
#define CDC_DATA_MAX_PACKET_SIZE       64   /* Endpoint IN & OUT Packet size */
#define CDC_CMD_PACKET_SZE             8    /* Control Endpoint Packet size */
 
#define CDC_IN_FRAME_INTERVAL          5    /* Number of frames between IN transfers */
#define APP_RX_DATA_SIZE               2048 /* Total size of IN buffer:
         
#define APP_FOPS                        VCP_fops

--------------------------------------------------------------------------------------------------------------------------------------------------
     And i'm trying to send data with this routine VCP_DataTx in my usbd_cdc_vcp.c file:

extern uint8_t  APP_Rx_Buffer []; /* Write CDC received data in this buffer.
                                     These data will be sent over USB IN endpoint
                                     in the CDC core functions. */
extern uint32_t APP_Rx_ptr_in;    /* Increment this pointer or roll it back to
                                     start address when writing received data
                                     in the buffer APP_Rx_Buffer. */
 
 
/* Private function prototypes -----------------------------------------------*/
static uint16_t VCP_Init     (void);
static uint16_t VCP_DeInit   (void);
static uint16_t VCP_Ctrl     (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
static uint16_t VCP_DataTx   (uint8_t* Buf, uint32_t Len);
static uint16_t VCP_DataRx   (uint8_t* Buf, uint32_t Len);
 
 
//static uint16_t VCP_COMConfig(uint8_t Conf);
 
 
CDC_IF_Prop_TypeDef VCP_fops =
{
  VCP_Init,
  VCP_DeInit,
  VCP_Ctrl,
  VCP_DataTx,
  VCP_DataRx
};
 
 
/* Private functions ---------------------------------------------------------*/
/**
  * @brief  VCP_Init
  *         Initializes the Media on the STM32
  * @param  None
  * @retval Result of the opeartion (USBD_OK in all cases)
  */
static uint16_t VCP_Init(void)
{
  return USBD_OK;
}
 
/**
  * @brief  VCP_DeInit
  *         DeInitializes the Media on the STM32
  * @param  None
  * @retval Result of the opeartion (USBD_OK in all cases)
  */
static uint16_t VCP_DeInit(void)
{
  return USBD_OK;
}
 
/**
  * @brief  VCP_Ctrl
  *         Manage the CDC class requests
  * @param  Cmd: Command code           
  * @param  Buf: Buffer containing command data (request parameters)
  * @param  Len: Number of data to be sent (in bytes)
  * @retval Result of the opeartion (USBD_OK in all cases)
  */
static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
{
  switch (Cmd)
  {
  case SEND_ENCAPSULATED_COMMAND:
    break;
 
 
  case GET_ENCAPSULATED_RESPONSE:
    break;
 
 
  case SET_COMM_FEATURE:
    break;
 
 
  case GET_COMM_FEATURE:
    break;
 
 
  case CLEAR_COMM_FEATURE:
    break;
 
 
  case SET_LINE_CODING:
    break;
 
 
  case GET_LINE_CODING:
    break;
 
 
  case SET_CONTROL_LINE_STATE:
    /* Not  needed for this driver */
    break;
 
 
  case SEND_BREAK:
    /* Not  needed for this driver */
    break;   
     
  default:
    break;
  }
 
 
  return USBD_OK;
}
 
/**
  * @brief  VCP_DataTx
  *         CDC received data to be send over USB IN endpoint are managed in
  *         this function.
  * @param  Buf: Buffer of data to be sent
  * @param  Len: Number of data to be sent (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
  */
static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
{
    uint32_t i=0;
        GPIO_SetBits(GPIOC, GPIO_Pin_9);
        GPIO_SetBits(GPIOC, GPIO_Pin_7);
        GPIO_SetBits(GPIOC, GPIO_Pin_8);
        GPIO_SetBits(GPIOC, GPIO_Pin_6);
   
    while(i < Len)
    {
        APP_Rx_Buffer[APP_Rx_ptr_in] = *(Buf + i);
        APP_Rx_ptr_in++;
        i++;
        /* To avoid buffer overflow */
        if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
        {
            APP_Rx_ptr_in = 0;
        
    }
  return USBD_OK;
}
 
/**
  * @brief  VCP_DataRx
  *         Data received over USB OUT endpoint are sent over CDC interface
  *         through this function.
  *          
  *         @note
  *         This function will block any OUT packet reception on USB endpoint
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result
  *         in receiving more data while previous ones are still not sent.
  *                
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
  */
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
  return USBD_OK;
}
 
void oz(void){
    uint8_t oz[4] = {0x4f,0x67,0x75,0x7a};
    VCP_DataTx (oz,4);
}

     Unfortunately,  these configs didnt work for me  or  i m missing another thing. I'm really  stuck here. Any help will be highly appreciated.

Best Regards,
Oguz.





Outcomes