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.

Sample code for CC2540 USB CDC class

Other Parts Discussed in Thread: CC2540, Z-STACK

hi,

i am new to CC2540..i want to transfer any data from Usb dongle to  Hperterminal (PC)..

i have searched TI web site for sample code ..i didn't get no sample code for USB CDC class..

 

Can u tell me any one work on the USB cdc class?..

post the code...

 

Regards,

aaji

 

 

 

  • Hello,

     The CC2540USB dongle supplied with the mini kit uses USB. You can find source code for that at HostTestRelease project - code directory HAL/TARGET/USB.

    -Greg

  • Is there any simple way (like those HAL_UART, HAL_UART_USB etc) to use the USB CDC (virtual com port) for my application only? Because in HostTestRelease sample project HCI takes control over the UART/USB port and I even cant see what happen there as TI doesnt provide the source for the HCI module. I still will need the HCI functionality in my application, but without any serial/usb communications in or out the MCU.

    Thanks

  • If you are using the BLE stack but don't want to HCI exposed external to the chip (in other words, only the HCI API can be used so the HCI is just in software; UART or USB for the HCI is not used), then you should use a "single chip" library instead of a "network processor" library. Please see the SW Developer's guide for more information on the differences between the two types of libraries.

    Also FYI- this is the code used by the HCI (only in network processor libraries) to initialize the UART interface; regardless of whether it is true UART or USB CDC virtual UART. You can use this same code in your application to initialize the UART:

      halUARTCfg_t uartConfig;

      // configure UART
      uartConfig.configured           = TRUE;
      uartConfig.baudRate             = HCI_UART_BR;
      uartConfig.flowControl          = HCI_UART_FC;
      uartConfig.flowControlThreshold = HCI_UART_FC_THRESHOLD;
      uartConfig.rx.maxBufSize        = HCI_UART_RX_BUF_SIZE;
      uartConfig.tx.maxBufSize        = HCI_UART_TX_BUF_SIZE;
      uartConfig.idleTimeout          = HCI_UART_IDLE_TIMEOUT;
      uartConfig.intEnable            = HCI_UART_INT_ENABLE;
      uartConfig.callBackFunc         = hciSerialPacketParser;

      // start UART
      // Note: Assumes no issue opening UART port.
      (void)HalUARTOpen (HCI_UART_PORT, &uartConfig);


  •  Hi Willis,
    Could you, please, check in your files ;) what are the current versions for _hal_uart_usb.c and hal_uart.c for cc2540USB, because from the versions I have (those supplied with the z-stack zip) seems all the code for configuring you gave me before, except "uartConfig.callBackFunc=hciSerialPacketParser;" is useless for USB CDC virtual UART?
    Thanks

     

      Filename:       _hal_uart_usb.c
      Revised:        $Date: 2009-10-30 19:20:01 -0700 (Fri, 30 Oct 2009) $
      Revision:       $Revision: 21028 $

    static void HalUARTOpenUSB(halUARTCfg_t *config)
    {
      // Synchronize initial value to any value between 0 and 255
      halUartRxH = halUartRxT;
    #if !defined HAL_USB_BOOT_CODE
      uartCB = config->callBackFunc;
    #else
      (void)config;
    #endif
    }

      Filename:     hal_uart.c
      Revised:      $Date: 2010-10-05 15:11:32 -0700 (Tue, 05 Oct 2010) $
      Revision:     $Revision: 24012 $

    uint8 HalUARTOpen(uint8 port, halUARTCfg_t *config)
    {
    ...
    #if (HAL_UART_USB)
      HalUARTOpenUSB(config);
    #endif
    ...
    }

  • Is there any additional documentation on how to set up USB CDC ?  The sample code that Willis provided is missing the most necessary part, the uart callback.  I do not find this routine in any of the sample apps, so it must be part of the provided binary libraries.   Also it is not clear how this will configure the USB since the HalUartOpenUSB ignores all of the configuration besides the callback.

  • You just create a C-function according to the callback prototype and in that function you just switch on the reason:

    void myUartCB(uint8 port, uint8 event);

    void myUartCB(uint8 port, uint8 event)
    {
      (void)port;

      switch (event)
      {
      case HAL_UART_RX_FULL:
      case HAL_UART_RX_ABOUT_FULL:
      case HAL_UART_RX_TIMEOUT:
        // Make a call to HalUARTRead() and parse the incoming data.
        break;

      case HAL_UART_TX_FULL:
        // Stop sending so much data so fast.
        break;

      case HAL_UART_TX_EMPTY:
        // Send some more data outgoing data with a call to HalUARTWrite().
        break;

      default:
        // Not expected.
        break;
      }
    }

     

    Does this answer help:

    http://e2e.ti.com/support/low_power_rf/f/538/t/212926.aspx

     

  • hello !

    I am a new to cc2540,when  i read  the TI BLE project"HostTestRelease " ,there were some C source code as follows which confused me very much!!!

     //************************************************************************

    static uint8 processExtMsg( hciPacket_t *pMsg )
    {
    uint8 deallocateIncoming;
    bStatus_t stat = SUCCESS;
    uint8 rspDataLen = 0;
    hciExtCmd_t msg;
    uint8 *pBuf = pMsg->pData;

    // Parse the header
    msg.pktType = *pBuf++;
    msg.opCode = BUILD_UINT16( pBuf[0], pBuf[1] );
    pBuf += 2;

    msg.len = *pBuf++;
    msg.pData = pBuf;

    switch( msg.opCode >> 7 )
    {
    case HCI_EXT_L2CAP_SUBGRP:
    stat = processExMsgL2CAP( (msg.opCode & 0x007F), &msg );
    break;

    case HCI_EXT_ATT_SUBGRP:
    stat = processExMsgATT( (msg.opCode & 0x007F), &msg );
    break;

    case HCI_EXT_GATT_SUBGRP:
    stat = processExMsgGATT( (msg.opCode & 0x007F), &msg, &rspDataLen );
    break;

    case HCI_EXT_GAP_SUBGRP:
    stat = processExMsgGAP( (msg.opCode & 0x007F), &msg, &rspDataLen );
    break;

    case HCI_EXT_UTIL_SUBGRP:
    stat = processExMsgUTIL( (msg.opCode & 0x007F), &msg, &rspDataLen );
    break;

    default:
    stat = FAILURE;
    break;
    }

    //**************************************************

    " msg.opCode >> 7   "    this C code  is wrong ,because the result could not match any of the case  result,  it needs to change as this " (msg.opCode >> 7)&0x0007 " 

    what i change  is correct ? 

    thank you for your reply!

  • Hello James,

    Since the msg.opCode is built from pBuf[0] and pBuf[1], you would have to look at these values to see how they match the case statement.

    Thanks,