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.

USB interaction with GenericApp

Other Parts Discussed in Thread: CC2531, Z-STACK

Hi,

I would like to communicate with CC2531 USB dongle running GenericApp from a PC application. I refered to other threads on the forum viz. https://e2e.ti.com/support/wireless_connectivity/f/156/t/141671 etc. But I don't couldn't understand how to proceed ahead. Any examples, guidance is appreciated.

BR

Srikanth

  • Hi, refer to this thread, you might find it helpful

  • I have give you some guide at e2e.ti.com/.../434040. If you still have other problems, can you be more specific and elaborate.
  • The post (e2e.ti.com/.../1553009) is displaying 11 replies but showing only 1 reply.
    Also, the folder C:\Texas Instruments\ZStack-CC2530-2.5.1a\Projects\zstack\Samples doesn't has any SampleLight project.

    BR
    Srikanth
  • Hi,

    When you open this thread, go to the bottom of the page, and click on the left arrow (bold gray), all the answers will be displayed now.

    A have attached a picture that shows this arrow.

  • Hi,

    From the above thread, I understand that if I program GenericApp on CC2531 USB dongle, it will be automatically recognised by the PC. Is there any sample code to use USB driver inside CC2531 dongle to send and receive messages from the PC?

    BR
    Srikanth
  • As I know, GenericApp is the only example that runs with CC2531 USB dongle.
  • But, is there any section of code inside GenericApp that actually uses the USB functionality? Can you please point it, if any.

    BR
    Srikanth
  • Hi,

    In this case USB functionality (access) is wrapped by UART module, for example, search for HalUARTRx through entire project

    (use Ctrl+Shift+F) which is a Rx function for UART. There you'll notice, under '#if HAL_UART_USB', a call for HalUARTRx(buf, len);

     

    HalUARTRx() and other USB related functions are found in _hal_uart_usb.c, this file included with #include, means you won't

    find it in the workspace tree, it can be found here: "...\ZStack istallation folde\Components\hal\target\CC2530USB"

    Good luck

  • Thanks for the reply. Do I need to install device driver at C:\...\swrc088c\driver aswell to use the dongle?

    BR
    Srikanth
  • Not sure, it depends on how the USB dongle is recognized by windows, is it a HID device (in this case you don't need install

    any driver), or a CDC device, for CDC device you may need install LUFA driver (serial over USB): lufa_driver.zip

    The VID and PID must be changed according to the information you get from device manager

  • Hi,
    I installed CDC driver on my PC and tried to send message from USB dongle to PC application. I used below code taken from other thread on the forum. But I'm not receiving any messages. Can you please suggest necessary corrections required in below code.



    halUARTCfg_t uartConfig;
    uint8 welcome[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890...\r\n";
    uartConfig.configured = TRUE;
    uartConfig.baudRate = HAL_UART_BR_115200;
    uartConfig.flowControl = FALSE;
    uartConfig.flowControlThreshold = 48;
    uartConfig.rx.maxBufSize = 128;
    uartConfig.tx.maxBufSize = 128;
    uartConfig.idleTimeout = 6;
    uartConfig.intEnable = TRUE;
    uartConfig.callBackFunc = SerialApp_CallBack;

    HalUARTOpen (HAL_UART_PORT_0, &uartConfig);

    HalUARTWrite(HAL_UART_PORT_0, welcome, (uint8)osal_strlen( (char*)welcome ));

    BR
    Srikanth
  • Hi,
    Please ignore the earlier message. I forgot to add port.Open(); in my C# program. I'm perfectly receiving the data from the USB dongle.

    Can you please explain how incase of HID example, data is transmitted without the need of the driver?

    Thanks
    Srikanth
  • Hi,

    First of all, I'm glad you making a progress with USB.

    HID is a part of a standard drivers package that is part of modern OS.

    With that being said, I must ask you what is the final aim of your project.
    If it's an application that involves a PC process that is communicating with, let's say, ZigBee network through
    USB dongle, where USB dongle used as coordinator to form ZigBee network, then you are slightly missing the point.
    For that purpose you could program your dongle with ZigBee CC2531ZNP firmware (part of Z-stack), or use Z-STACK-LINUX-GATEWAY,
    it's way easier to develop in that way.

  • Hi,

    Thanks for your replies.
    But, is it possible to work with ZNP from a Windows PC?
    Also is linux gateway compulsory when running the ZAP on linux?

    BR
    Srikanth
  • 1. Yes, it is no problem to work with ZNP from windows PC. ZTool is a demo for this.
    2. Yes, linux gateway is compulsory for ZAP on linux.
  • Where can I find APIs and their documentation for working with ZNP on windows?
    I refered to C:\Texas Instruments\ZStack-CC2530-2.5.1a\Documents\CC2530ZNP Interface Specification.pdf and C:\Texas Instruments\ZStack-CC2530-2.5.1a\Projects\zstack\ZNP\CC253x.
    But, it doesn't seem to be of good help for starting up.

    BR
    Srikanth
  • You can also refer to Z-Stack Monitor and Test API.pdf.

  • Hi,

    I'm initializing USB inside GenericApp_Init and my writes using HalUARTWrite are working. However, I'm having problem while reading the data sent by PC. The call back function to read the data is not being invoked. I have enabled HAL_UART_ISR in the program. Is there any thing else I'm missing?

    BR
    Srikanth
  • GenericApp for USB already has UART enable for MT command. What do you intend to do now?
  • I want CC2531 USB dongle running GenericApp to receive data from PC through USB. As explained in earlier post, the writes are working but the read is not working in the dongle.

    BR
    Srikanth
  • You can use read to get message. The UART message from CC2531 USB dongle is unsolicited.
  • Hi,

    I'm using below code in my callback function:

    static void GenericApp_CallBack(uint8 port, uint8 event)
    {
    static uint8 s_RxBuf [128];
    uint16 bufLen;
    bufLen = Hal_UART_RxBufLen(HAL_UART_PORT_0);
    HalUARTRead(HAL_UART_PORT_0, s_RxBuf , bufLen);
    HalUARTWrite( HAL_UART_PORT_0, s_RxBuf, (uint8)osal_strlen( (char*)s_RxBuf ));
    }

    in my PC i'm writing '123' to the COM port (port.Writeline("123");). basically, I'm trying to send back the same data I received back to the PC from the callback function

    However, I'm receving a big string 123. 123. 123. 123. 123................................ back in my PC.

    Do I need to clear Read & Write buffers in after calling HalUARTRead & HalUARTWrite to avoid receiving multiplied data?

    BR
    Srikanth
  • Where do you add this callback function in GenericApp?
  • Hi,

    The function is added in GenericApp.c. It is initialised inside in GenericApp_Init.

    BR

    Srikanth

  • Can you show me how do you initialize it in GenericApp_Init?
  • Hi, pls see my generic app init below:

    halUARTCfg_t uartConfig;

    void GenericApp_Init( uint8 task_id )
    {
    GenericApp_TaskID = task_id;
    GenericApp_NwkState = DEV_INIT;
    GenericApp_TransID = 0;

    // Device hardware initialization can be added here or in main() (Zmain.c).
    // If the hardware is application specific - add it here.
    // If the hardware is other parts of the device add it in main().

    GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
    GenericApp_DstAddr.endPoint = 0;
    GenericApp_DstAddr.addr.shortAddr = 0;

    // Fill out the endpoint description.
    GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
    GenericApp_epDesc.task_id = &GenericApp_TaskID;
    GenericApp_epDesc.simpleDesc
    = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
    GenericApp_epDesc.latencyReq = noLatencyReqs;

    // Register the endpoint description with the AF
    afRegister( &GenericApp_epDesc );

    // Register for all key events - This app will handle all key events
    RegisterForKeys( GenericApp_TaskID );

    // Update the display
    #if defined ( LCD_SUPPORTED )
    HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 );
    #endif

    ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp );
    ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp );

    #if defined( IAR_ARMCM3_LM )
    // Register this task with RTOS task initiator
    RTOS_RegisterApp( task_id, GENERICAPP_RTOS_MSG_EVT );
    #endif




    uartConfig.configured = TRUE;
    uartConfig.baudRate = HAL_UART_BR_115200;
    uartConfig.flowControl = FALSE;
    uartConfig.flowControlThreshold = 48;
    uartConfig.rx.maxBufSize = 128;
    uartConfig.tx.maxBufSize = 128;
    uartConfig.idleTimeout = 6;
    uartConfig.intEnable = TRUE;
    uartConfig.callBackFunc = GenericApp_CallBack;
    HalUARTOpen (HAL_UART_PORT_0, &uartConfig);
    }

    BR
    Srikanth

  • When you do this, do you disable ZTOOL_P1 and MT_TASK in your compile options? If not, please disable them and test again.
  • Hi, I will verify and get back in some time.

    I'm also exploring to use CC2531 USB stick as ZNP on Windows. Will it require usage of ZCL API in ZAP?

    BR
    Srikanth
  • It depends on your application. If your application only wants to use Zigbee mesh, it is not mandatory to use ZCL.
  • The SampleLight and SampleSwitch projects at C:\Texas Instruments\Z-Stack Home 1.2.2.42930\Projects\zstack\ZAP are based on ZCL. Are there any examples without using ZCL?

    BR
    Srikanth
  • You can use GenericApp ZAP example in Z-Stack Mesh 1.0.0 which doesn't use ZCL.
  • Hi,

    Found out the issue with write function inside the call back function.

    static void GenericApp_CallBack(uint8 port, uint8 event)
    {
    static uint8 s_RxBuf [128]; 
    uint16 bufLen; 
    bufLen = Hal_UART_RxBufLen(HAL_UART_PORT_0);
    HalUARTRead(HAL_UART_PORT_0, s_RxBuf , bufLen);
    HalUARTWrite( HAL_UART_PORT_0, s_RxBuf, (uint8)osal_strlen( (char*)s_RxBuf )); 
    }

    correct version of HalUARTWrite is as below and not as given in the above function. It is the issue with length of the data being written

    HalUARTWrite( HAL_UART_PORT_0, s_RxBuf, bufLen ); 

    BR

    Srikanth

  • It's good to know you find out where the problem is.