This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2540: problem with CC2540 usb peripheral

Part Number: CC2540

hi to all,

i am developing a device based on cc2540, i want to create something like bridge that wll forward all received packets from bluetooth to usb, but i have a problem with cc2540 usb. during data transfer some packets get lost and when i sniff to usb analeyzer it give me below log :

35.2   IN            00 00 00 01 00 08 39 00 00 00 00 00 00 00 00 00 ......6......... 4663.1.0
                          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 4663.1.16 
                          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 4663.1.32

35.2    USTS     c0000004 stall pid 4664.1.0 
35       RESET                                4665.1.0 
34       RESET                                4666.1.0 
34       ok                                        4666.2.0
35      ok                                         4665.2.0
35.2   RESET                                 4667.1.0
35.2   IN            00 00 00 01 00 08 36 00 00 00 00 00 00 00 00 00 ......6......... 4668.1.0
                          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 4668.1.16
                          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 4668.1.32

as you can see in this log every thing is ok untill the endpoint that i sending data from that return packet with stall pid and after that host try to reset the endpoint, and during these process i lost some packets.

here is part of my code that write data to endpoint:

uint8 usbfwVancFOBWrite(uint8 * data)
{
  uint32 stopPoint = 100;
  uint8 oldEndpoint;
  // Save the old index setting, then select endpoint 0 and fetch the control register
  oldEndpoint = USBFW_GET_SELECTED_ENDPOINT();

  
  USBFW_SELECT_ENDPOINT(USB_HID_VFOB_EP);
  if(USBCSOL & USBCSOL_OUTPKT_RDY) /* buffer is full */
  {
    // Read FIFO
    if(usbReadBlocked==0)
    {
      usbfwReadFifo(&USBF2, USBCNTL, _data);
      USBCSOL &= ~USBCSOL_OUTPKT_RDY;
    }
    USBFW_SELECT_ENDPOINT(oldEndpoint);
    //return 0;
  }
  
  USBFW_SELECT_ENDPOINT(USB_HID_VFOB_EP_WRITE);
  
  // Send IN packets
  while((USBCSIL & USBCSIL_INPKT_RDY) && stopPoint>0)
    stopPoint--;
  if(stopPoint!=0) /* check timeout event */
  {
    usbfwWriteFifo(&USBF2, 64, data);
    USBCSIL = USBCSIL_INPKT_RDY;
    USBCSIL = USBCSIL_SEND_STALL;
    while ((USBCSIL & USBCSIL_SENT_STALL) && stopPoint>0)
      stopPoint--;
  }
  USBCSIL = 0;  
  USBFW_SELECT_ENDPOINT(oldEndpoint);
    
  if(stopPoint==0)
    return 0; /* timeout event */
  else
    return 1; /* success send */
}

know can any one give me a advice to solve this problem???

thanks.

  • Hello Alireza,
    I don't know.

    Which SDK is used as a basis?
    Does this happen right after initialization and enumeration of the USB endpoint?
    Can you add a delay before you start to send packets over USB?
  • hi eirik and thanks for your response.
    no, it dose not happen in enumeration of the usb endpoint, this happen when i want to write to a usb endpoint with usbfwVancFOBWrite function(most of time this function work well but some time it send stall), as you can see at first in this function i try to empty the correspond OUT endpoint buffer(as you know Endpoint 2 In & out share same 64Byte buffer) and then i try to write to endpoint 2 In.

    in usbfwVancFOBWrite function "USBCSIL = USBCSIL_SEND_STALL;" code exist, can this line cause to this problem ?? (i did not write this function so i do not know what it means exactlly).

    thanks for your reponse.
  • Hello Alireza,

    Bulk transfers are explained will in this link: www.beyondlogic.org/.../usb4.shtml

    • IN: When the host is ready to receive bulk data it issues an IN Token. If the function receives the IN token with an error, it ignores the packet. If the token was received correctly, the function can either reply with a DATA packet containing the bulk data to be sent, or a stall packet indicating the endpoint has had a error or a NAK packet indicating to the host that the endpoint is working, but temporary has no data to send.

    After a STALL packets the endpoint must enter a idle state. In the BLE-CC254x-1.4.2.2 hostTest example for CC2540 USB the USB implementation will loop through

    void HalUARTPollUSB(void)

    {

    #if defined HAL_SB_BOOT_CODE

     while (USBIF)  usbirqHandler();

    #endif

     halUartPollEvt();

     halUartPollRx();

     halUartPollTx();

    }

    halUartPollEvt()->usbfwSetupHandler() will handle events such as STALL, RESET and more. You must check for events after every packet.