cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F427 USB Vendor device

Lachezar
Associate II

Hello all,

For a first time i am trying to implement usb vendor device. I am using stm32 standard peripheral library. Basically  CDC class, having modified the interface recognition part. Can i have some direction what i am missing to implement. Here are some debug logs. 

> USB Host library started.
USB OTG HS HID Host

> USB Host library started.
> Device Attached
> Full speed device detected
VID : 1234h
PID : 0101h
Device address assigned
Manufacturer : PAX
Product : IM20
Serial Number : N/A
> Enumeration completed

I think this part is ok but still device does not want to speak with me. I used Wireshard to listen communication with PC and after this steps there is only one request step.

Lachezar_0-1699868646627.png

Req 1, with value 0x300- i send this and recive status ok.(i dont know what is that request, just send it because i see it on Wireshark listener). After i send request i am trying to send bulk packet and recive answer but nothing comes in. Here is my Init interface function and state machine for send/receive. 

 

static USBH_Status VS_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev, 
                                      void *phost)
{	
  USBH_HOST *pphost = phost;
  USBH_Status status = USBH_FAIL ;

  

      if((pphost->device_prop.Itf_Desc[0].bInterfaceClass  == VENDOR_SPECIFIC) )
      {
        if(pphost->device_prop.Ep_Desc[0][0].bEndpointAddress & 0x80)
        {
                                   

          VS_Machine.VSBulkInEp = (pphost->device_prop.Ep_Desc[0][0].bEndpointAddress);
          VS_Machine.VSBulkInEpSize  = pphost->device_prop.Ep_Desc[0][0].wMaxPacketSize;
        }
        else
        {
          VS_Machine.VSBulkOutEp = (pphost->device_prop.Ep_Desc[0][0].bEndpointAddress);
          VS_Machine.VSBulkOutEpSize  = pphost->device_prop.Ep_Desc[0] [0].wMaxPacketSize;      
        }
    
        if(pphost->device_prop.Ep_Desc[0][1].bEndpointAddress & 0x80)
        {
          VS_Machine.VSBulkInEp = (pphost->device_prop.Ep_Desc[0][1].bEndpointAddress);
          VS_Machine.VSBulkInEpSize  = pphost->device_prop.Ep_Desc[0][1].wMaxPacketSize;      
        }
        else
        {
          VS_Machine.VSBulkOutEp = (pphost->device_prop.Ep_Desc[0][1].bEndpointAddress);
          VS_Machine.VSBulkOutEpSize  = pphost->device_prop.Ep_Desc[0][1].wMaxPacketSize;      
        }
        VS_Machine.hc_num_in = USBH_Alloc_Channel(pdev,
                                                VS_Machine.VSBulkInEp);  
    

        VS_Machine.hc_num_out = USBH_Alloc_Channel(pdev, 
                                                VS_Machine.VSBulkOutEp);

        /* Open the new channels */
        USBH_Open_Channel  (pdev,
                            VS_Machine.hc_num_out,
                            pphost->device_prop.address,
                            pphost->device_prop.speed,
                            EP_TYPE_BULK,
                            VS_Machine.VSBulkOutEpSize);  
    
        USBH_Open_Channel  (pdev,
                            VS_Machine.hc_num_in,
                            pphost->device_prop.address,
                            pphost->device_prop.speed,
                            EP_TYPE_BULK,
                            VS_Machine.VSBulkInEpSize);    

    
        status = USBH_OK;
    
    }
    VS_RxParam.VSState = VS_READ_DATA;

    /*Initialize the class specific request with "GET_LINE_CODING"*/
    VS_ReqState = VS_GET_LINE_CODING_RQUEST ;


    return  status;
}

void vs_send_buffer(BYTE *buf, DWORD size)
{
    if(VS_TxStruct.tx_state == VS_IDLE)
    {
        VS_TxStruct.tx_buf = buf; 
        VS_TxStruct.tx_length = size;
        VS_TxStruct.tx_state = VS_SEND_DATA_START;  
    }
}

void VS_ProcessTransmission(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost)
{
//  static uint32_t len ;
  static uint32_t remainingDataLength;
  static uint8_t *datapointer , *datapointer_prev;

    URB_STATE URB_StatusTx = URB_IDLE;
    //  
    URB_StatusTx =   HCD_GetURB_State(pdev , VS_Machine.hc_num_out);

    switch(VS_TxStruct.tx_state)
    {
        case VS_IDLE :
            
        break;

        case VS_READ_DATA :
        break;

        case VS_SEND_DATA_START:
            if(( URB_StatusTx == URB_DONE ) || (URB_StatusTx == URB_IDLE))
            {
                datapointer = VS_TxStruct.tx_buf;
                remainingDataLength = VS_TxStruct.tx_length;
                VS_TxStruct.tx_state = VS_SEND_DATA;
            }
        break;

        case VS_SEND_DATA :
            if(( URB_StatusTx == URB_DONE ) || (URB_StatusTx == URB_IDLE))
            {
                if(remainingDataLength > VS_Machine.VSBulkOutEpSize)
                {
                    USBH_BulkSendData (pdev,
                        datapointer, 
                        VS_Machine.VSBulkOutEpSize , 
                        VS_Machine.hc_num_out);

                    datapointer = datapointer + VS_Machine.VSBulkOutEpSize;
                    remainingDataLength = remainingDataLength - VS_Machine.VSBulkOutEpSize;
                    VS_TxStruct.tx_state = VS_DATA_SENT;
    //                    xfer_error_count=0;
                }
                else if ( remainingDataLength == 0)
                {
                    /* If value was 0, and successful transfer, then change the state */
                    VS_TxStruct.tx_state = VS_DATA_SENT;
                }
                else
                {
                    USBH_BulkSendData (pdev,
                                 datapointer, 
                         remainingDataLength , 
                         VS_Machine.hc_num_out);

                    remainingDataLength = 0; /* Reset this value and keep in same state */  
                     VS_TxStruct.tx_state = VS_DATA_SENT;
                }
            }

          break;

          case VS_DATA_SENT :
              /*Check the status done for transmssion*/
            if(URB_StatusTx == URB_DONE )
            {         
                if(remainingDataLength)
                {
                    VS_TxStruct.tx_state = VS_SEND_DATA;
                }else
                {
                    VS_TxStruct.tx_state = VS_IDLE;
                }

            }

          break;

          case VS_BUSY :
          break;
      
          case VS_GET_DATA :   
          break;

          case VS_POLL :
          break;

          case VS_CTRL_STATE :
          break;

          default:
          break;
    }
}

static void VS_ProcessReception(USB_OTG_CORE_HANDLE *pdev, USBH_HOST *phost)
{
    URB_STATE URB_Status = URB_IDLE;
//  if(RX_Enabled == 1)
//  {
    URB_Status =   HCD_GetURB_State(pdev , VS_Machine.hc_num_in);  

    switch(VS_RxParam.VSState)
    {
        case VS_READ_DATA:
            if((URB_Status == URB_IDLE))
            {
                    USBH_BulkReceiveData(pdev,
                                 receive_buffer,
                                 VS_Machine.VSBulkInEpSize, 
                                 VS_Machine.hc_num_in);
            }
        VS_RxParam.VSState = VS_GET_DATA;

        break;

        case VS_GET_DATA:
            if((URB_Status == URB_DONE))
            {
                tete++;
            }
        break;
    }
}

 


All protocol  commands work when i am using the UART communication. 

 

2 REPLIES 2
Lachezar
Associate II

I figure out what was the problem, code works fine. 

KDJEM.1
ST Employee

Hello @Lachezar and welcome to the Community 🙂,

Glad to know that the issue is solved.

Could you please share the solution, it might help community members who have the same problem?

Thanks and best regards, 

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.