Showing posts with label CC2538. Show all posts
Showing posts with label CC2538. Show all posts

Monday, May 6, 2019

How to check APS ack in TI Z-Stack

The following steps show you how to check APS ack in TI Z-Stack using ON/OFF cluster toggle command in SampleSwitch example.

1. Setup OnOffOptions and use zcl_registerClusterOptionList in  zclSampleSw_Init to register receiving APS ack on ZCL_CLUSTER_ID_GEN_ON_OFF cluster command.
   
    zclOptionRec_t OnOffOptions[] =
    {
      {
         ZCL_CLUSTER_ID_GEN_ON_OFF, ( AF_EN_SECURITY | AF_ACK_REQUEST ),
      },
    };
    ZStatus_t status = zcl_registerClusterOptionList ( SAMPLESW_ENDPOINT, 1,
                                                                                    OnOffOptions );
 2.  Add "case AF_DATA_CONFIRM_CMD:..." in SYS_EVENT_MSG case of zclSampleSw_event_loop

    uint16 zclSampleSw_event_loop( uint8 task_id, uint16 events )
    {
      ...
     
      if ( events & SYS_EVENT_MSG )
      {
        while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclSampleSw_TaskID )) )
        {
          switch ( MSGpkt->hdr.event )
          {
            case AF_DATA_CONFIRM_CMD:
              afDataConfirm_t *SWafDataConfirm;
              SWafDataConfirm = (afDataConfirm_t *)MSGpkt;
              rcv_aps_ack_trans_id=SWafDataConfirm->transID;
              // You can use rcv_aps_ack_trans_id to check if it matches to APS_Counter when you send toggle command with zclGeneral_SendOnOff_CmdToggle
              break;
     ...

Friday, February 10, 2017

Use ZTool + Z-Stack 3.0 ZNP to set up a basic Zigbee 3.0 network

The following steps show you how to use ZTool + Z-Stack 3.0 ZNP to set up Zigbee 3.0 network:

1. You have to prepare two CC253x EVBs (CC2530DK, CC2531EMK, or CC2538EM) and run Z-Stack ZNP 3.0 FW on it.

2. You can run the following MT commands (TX in red) to setup Zigbee 3.0 coordinator.

10:36:58.53 COM1 SYS_OSAL_NV_WRITE (0x2109) --> Write startup option to clear NV when reset
    Id: 0x0003
    Offset: 0x00
    Len: 0x01
    Value: . (0x03)

10:36:58.55 COM1 SYS_OSAL_NV_WRITE_SRSP (0x6109)
    Status: SUCCESS (0x0)

10:37:06.11 COM1 SYS_RESET (0x4100) --> Do reset to clear NV
    Type: 0x00 (HARD RESET) (0x0)

10:37:08.18 COM1 SYS_RESET_RESPONSE (0x4180)
    Reason: 0x02
    TransportRev: 0x02
    Product: 0x00
    MajorRel: 0x02
    MinorRel: 0x07
    HwRev: 0x00

10:37:42.94 COM1 SYS_OSAL_NV_WRITE (0x2109) --> Write ZCD_NV_LOGICAL_TYPE to 0 which means coordinator
    Id: 0x0087
    Offset: 0x00
    Len: 0x01
    Value: . (0x00)

10:37:42.97 COM1 SYS_OSAL_NV_WRITE_SRSP (0x6109)
    Status: SUCCESS (0x0)



10:38:32.55 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Primary channel mask to channel 13 only
    isPrimary: TRUE (0x1)
    Channel: CHNL_0x00002000 (0x2000)

1
0:38:32.55 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:38:34.43 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Secondary channel to 0x0 to disable secondary channel mask
    isPrimary: FALSE (0x0)
    Channel: NONE (0x0)

10:49:01.44 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:38:45.58 COM1 APP_CNF_BDB_START_COMMISSIONING (0x2F05)
--> Start commissioning using network formation as parameter to start coordinator
    CommissioningMode: (0x04) Network Formation (0x4)

10:38:47.35 COM1 APP_CNF_BDB_START_COMMISSIONING_SRSP (0x6F05)
    Status: SUCCESS (0x0)

10:38:47.35 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:47.36 COM1 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 1 (0x1)
    Commissioning Mode: 0x02 (Formation) (0x2)
    Commissioning Mode: 254 (0xFE)

10:38:47.62 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:47.88 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.15 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.41 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.68 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.94 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:49.49 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 9 (0x9)

10:38:49.49 COM1 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 0x00 (Success) (0x0)
    Commissioning Mode: 0x02 (Formation) (0x2)
    Commissioning Mode: 69 (0x45)

10:39:11.49 COM1 UTIL_GET_DEVICE_INFO (0x2700) --> Get device info to confirm coordinator is setup correctly

10:39:11.5 COM1 UTIL_GET_DEVICE_INFO_RESPONSE (0x6700)
    Status: SUCCESS (0x0)
    IEEEAddr: 0x00124B0001025822
    ShortAddress: 0x0000
    DeviceType: COORDINATOR, ROUTER, END_DEVICE (0x7)
    DeviceState: DEV_ZB_COORD (0x9)
    NumAssocDevices: 0x00
    AssocDevicesList

10:39:26.7 COM1 SYS_OSAL_NV_WRITE (0x2109) --> Write ZCD_NV_ZDO_DIRECT_CB to 1 to receive ZDO related messages
    Id: 0x008F
    Offset: 0x00
    Len: 0x01
    Value: . (0x01)

10:39:26.71 COM1 SYS_OSAL_NV_WRITE_SRSP (0x6109)
    Status: SUCCESS (0x0) 


10:44:16.54 COM1 APP_CNF_BDB_START_COMMISSIONING (0x2F05) --> Start commissioning using network steering as parameter to be ready for device to join
    CommissioningMode: (0x02) Network Steering (0x2)

10:44:16.55 COM1 APP_CNF_BDB_START_COMMISSIONING_SRSP (0x6F05)
    Status: SUCCESS (0x0)

10:44:16.56 COM1 ZDO_MGMT_PERMIT_JOIN_RSP (0x45B6)
    SrcAddr: 0x0000
    Status: ZDP_SUCCESS (0x0)

10:44:16.57 COM1 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 0x00 (Success) (0x0)
    Commissioning Mode: 0x01 (Network Steering) (0x1)
    Commissioning Mode: 67 (0x43)


3. You can run the following MT commands to setup Zigbee 3.0 router.

10:43:43.75 COM99 SYS_OSAL_NV_WRITE (0x2109) --> Write ZCD_NV_LOGICAL_TYPE to 1 which means router
    Id: 0x0087
    Offset: 0x00
    Len: 0x01
    Value: . (0x01)

10:43:59.35 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Primary channel mask to channel 13 only
    isPrimary: TRUE (0x1)
    Channel: CHNL_0x00002000 (0x2000)
10:43:59.35 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:44:11.43 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Secondary channel to 0x0 to disable secondary channel mask
    isPrimary: FALSE (0x0)
    Channel: NONE (0x0)
10:44:11.45 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:44:26.46 COM99 APP_CNF_BDB_START_COMMISSIONING (0x2F05) --> Start commissioning using network steering as parameter to make device to start scan Zigbee network to join
    CommissioningMode: (0x02) Network Steering (0x2)

10:44:26.46 COM99 APP_CNF_BDB_START_COMMISSIONING_SRSP (0x6F05)
    Status: SUCCESS (0x0)

10:44:26.56 COM99 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 1 (0x1)
    Commissioning Mode: 0x01 (Network Steering) (0x1)
    Commissioning Mode: 0 (0x0)

10:44:26.8 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: INVALID_PARAMETER (0x2)

10:44:27.11 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: INVALID_PARAMETER (0x2)

10:44:27.37 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 3 (0x3)

10:44:27.88 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 5 (0x5)

10:44:28.24 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 7 (0x7)

10:44:28.9 COM99 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 0x00 (Success) (0x0)
--> Router joins coordinator successfully
    Commissioning Mode: 0x01 (Network Steering) (0x1)
    Commissioning Mode: 0 (0x0)

11:03:22.81 COM99 UTIL_GET_DEVICE_INFO (0x2700)--> Get device info to confirm router is setup correctly

11:03:22.81 COM99 UTIL_GET_DEVICE_INFO_RESPONSE (0x6700)
    Status: SUCCESS (0x0)
    IEEEAddr: 0x00124B0000E50127
    ShortAddress: 0x4EE6
    DeviceType: COORDINATOR, ROUTER, END_DEVICE (0x7)
    DeviceState: DEV_ROUTER (0x7)
    NumAssocDevices: 0x00
    AssocDevicesList
 

4. On Ztool of coordinator, you should see ZDO_END_DEVICE_ANNCE_IND pops when router joins coordinator.

10:44:28.84 COM1 ZDO_END_DEVICE_ANNCE_IND (0x45C1)
    SrcAddr: 0x4EE6
    NwkAddr: 0x4EE6
    IEEEAddr: 0x00124B0000E50127
    Capabilities: 0x8E

Thursday, October 27, 2016

How to create a periodic event for CC253x/CC254x Z-Stack and BLE Stack.

The following codes show example to create a periodic event that is triggered every 5 seconds for CC253x in Z-Stack and you can do it accordingly for CC254x in BLE Stack.

1. Add "#define PERIODIC_EVT 0x0001"in your code. Please note that event define has to be an unused bit mask of uint16.

2. Put  the following line at where you want to start PERIODIC_EVT

osal_start_timerEx( zcl_XXX_TaskID, PERIODIC_EVT, 10 );


2. Create PERIODIC_EVT processing in zcl_XXX_event_loop
if( events & PERIODIC_EVT )
{
  //Do things that need periodic processing here!
  ...
  osal_start_timerEx( zcl_XXX_TaskID, PERIODIC_EVT, 5000 );
  return (events ^ PERIODIC_EVT);
}

Wednesday, August 31, 2016

How to handle end node announcement, active endpoint response, and simple descriptor response in Z-Stack for CC2530 and CC2538.

When a Zigbee device joins network, it would broadcast end node announcement with its short and IEEE address. We can register a callback event in Z-Stack to receive end node announcement and store short/IEEE address of device to a device list. Then, we usually call ZDP_ActiveEPReq to request active endpoint and register a callback event in Z-Stack to receive active endpoint response and store it to device list. Finally, we can call ZDP_SimpleDescReq to request simple descriptor and register a callback event in Z-Stack to receive simple descriptor response and store it to device list too.

The following steps show you how to handle end node announcement in Z-Stack SampleLight.

1. Add "ZDO_RegisterForZDOMsg(task_id, Device_annce);" in zclSampleLight_Init().

2. Add the following codes to process Device_annce event in zclSampleLight_ProcessZDOMsgs and you would get end node announcement  information in devAnnce structure.

  ZDO_DeviceAnnce_t devAnnce;

if ( pMsg->clusterID == Device_annce )
      ZDO_ParseDeviceAnnce( pMsg, &devAnnce );





The following steps show you how to handle active endpoint response in Z-Stack SampleLight.

1. Add "ZDO_RegisterForZDOMsg(task_id, Active_EP_rsp);" in zclSampleLight_Init().

2. Add the following codes to process Active_EP_rsp event in zclSampleLight_ProcessZDOMsgs and you would get end node announcement information in pActiveEndpointRsp pointer of ZDO_ActiveEndpointRsp_t structure.

  ZDO_ActiveEndpointRsp_t *pActiveEndpointRsp;

  if ( pMsg->clusterID == Active_EP_rsp )
      pActiveEndpointRsp = ZDO_ParseEPListRsp( pMsg );


The following steps show you how to handle simple descriptor response in Z-Stack SampleLight.

1. Add "ZDO_RegisterForZDOMsg(task_id, Simple_Desc_rsp);" in zclSampleLight_Init().

2. Add the following codes to process Simple_Desc_rsp event in zclSampleLight_ProcessZDOMsgs and you would get simple descriptor in simpleDescRsp structure.

  ZDO_SimpleDescRsp_t simpleDescRsp;

  if ( pMsg->clusterID == Simple_Desc_rsp )
      ZDO_ParseSimpleDescRsp( pMsg, &simpleDescRsp );

Monday, August 22, 2016

How to use backdoor serial boot loader for CC2650/CC2640/CC2630/CC2538

The following steps show you how to use backdoor serial boot loader for CC2650/CC2640/CC2630/CC2538

1. CC2650/CC2640/CC2630/CC2538 support backdoor Serial Bootloader Interface by default. It might be sometimes overwritten by your application so you might need to do "Mass Erase" from Flash Programmer 2 to make it come back.


2. Hold "SELECT" and press "RESET" button on SmartRF06EB.

3. Select correct chip from virtual COM port simulated by SmartRF06EB. In my case, I use CC2650


4. Then click mouse right button to connect CC2650 from virtual COM port.


5. Select FW and download it to CC2650. You would get the following error and "Failed" on Flash Programmer2 but it actually program and verify successfully.

>Initiate access to target: COM53.
>Reading file: C:/ti/simplelink/ble_sdk_2_02_00_31/examples/hex/cc2650lp_host_test_rel.hex.
>Start flash erase ...
>Erase finished successfully.
>Start flash programming ...
>Warning: CC2650 bootloader will be disabled.
>Flash programming locked bootloader access. No further actions possible.
>Programming finished successfully.
>Start flash verify ...
>ERROR: No connection between interface and target.
>Reset target ...


6. Test your application on CC2650

Monday, January 4, 2016

Set the Logical Device type to Coordinator and router dynamically using Z-Stack on CC2538DK

Apply the following steps to SampleLight coordinator project and I can set the Logical Device type to Coordinator and router at run time.

1. Add "uint8 dev_type=0;" as global variable in ZDApp.c.

2. Add the red part in ZDAppDetermineDeviceType.

void ZDAppDetermineDeviceType( void )
{
  if (dev_type==0)
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else if(dev_type==1)
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;

  
  if ( zgDeviceLogicalType ==ZG_DEVICETYPE_COORDINATOR )
  {
    devStartMode = MODE_HARD;     // Start as a coordinator
    ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_COORDINATOR;
  }
  else
  ...

3. Revise the red part in ZDAppCheckForHoldKey.

void ZDAppCheckForHoldKey( void )
{
#if (defined HAL_KEY) && (HAL_KEY == TRUE)

  // Get Keypad directly to see if a HOLD is needed
  zdappHoldKeys = HalKeyRead();

  // Hold down the SW_BYPASS_START key (see OnBoard.h)
  // while booting to avoid starting up the device.
  if ( zdappHoldKeys == SW_BYPASS_START )
  {
    // Change the device state to HOLD on start up
    //devState = DEV_HOLD;
    dev_type=1;

  }
#endif // HAL_KEY
}
4. Revise the red part in ZGlobals.h

extern uint8 dev_type;
 
/*********************************************************************
 * MACROS
 */
#if defined( BUILD_ALL_DEVICES ) && !defined( ZSTACK_DEVICE_BUILD )
  #define ZSTACK_DEVICE_BUILD  (DEVICE_BUILD_COORDINATOR | DEVICE_BUILD_ROUTER | DEVICE_BUILD_ENDDEVICE)
#endif

// Setup to work with the existing (old) compile flags
#if 0
#if !defined ( ZSTACK_DEVICE_BUILD )
  #if defined ( ZDO_COORDINATOR )
    #define ZSTACK_DEVICE_BUILD  (DEVICE_BUILD_COORDINATOR)
  #elif defined ( RTR_NWK )
    #define ZSTACK_DEVICE_BUILD  (DEVICE_BUILD_ROUTER)
  #else
    #define ZSTACK_DEVICE_BUILD  (DEVICE_BUILD_ENDDEVICE)
  #endif
#endif
#else
#define ZSTACK_DEVICE_BUILD  (dev_type+1)
#endif

5. Compile the code and download it to CC2538DK. If I turn on CC2538DK without pressing any button, it will become ZC. If I turn on CC2538DK with UP key pressed, it will become ZR.

Monday, August 17, 2015

How to setup Contiki Sniffer for 6LowPAN using CC2531 USB dongle or CC2538EM

The following steps show you how to setup Contiki Sniffer on Mac OS for 6LowPAN using CC2531 USB dongle in details.

1. Download pyserial-2.7.tar.gz and untar it by running "tar zxvf pyserial-2.7.tar.gz" under console terminal of Mac OS.

2. Install pySerial by running "sudo python setup.py install" under console terminal of Mac OS.

3. Download sensniff.py.

4. Download Contiki_Sniffer_CC2531EMK.hex to CC2531 USB dongle using TI CC Debugger and Flash Programmer.

p.s. If you want to use CC2538EM as sniffer, you have to set "#define CC2538_RF_CONF_SNIFFER_USB  1" in C:\contiki\platform\cc2538dk\contiki-conf.h and do make under "C:\contiki\examples\cc2538dk\sniffer". You will get sniffer.bin under "C:\contiki\examples\cc2538dk\sniffer" and flash is to CC2538EM using Flash Programmer 2.

5. Plugin CC2351 USB dongle or CC2538EM into Mac USB port and you should see it enum like /dev/tty.usbmodem1421. Please note that 1421 might be different from device to device.

6. Run "python sensniff.py -d /dev/tty.usbmodem1421 -b 460800" under console terminal of Mac OS.

p.s. CC2531 USB dongle needs you to press S1 or S2 button to make it work after you plug it into UAB port. I don't know why but if you cannot make it work, try it.

7. Download and install wireshark.

8. Run wireshark. Go to Edit->Preferences->Protocols->6LowPAN and add "aaaa::" to Context 0:.

9. Go to Edit->Preferences->Protocols->IEEE802.15.4 and check "TI CC24xx FCS format".

10. Go to Capture -> options -> Manage Interfaces -> New. Input /tmp/sensniff to "Pipe:" and save.

11. Start a new live capture on wireshark and enjoy it.

Tuesday, July 21, 2015

Setup Compile Environment on Windows Cygwin For CC2650/CC2538 Contiki 6LowPAN

The following step-by-step guide shows you how to setup compile environment on Win 7 Cygwin to build Contiki 6LowPAN For CC2650STK, CC2650DK, and CC2538DK.

1. Download and install Cygwin. During Cygwin installation, you have to stop at "Select Packages", put "make" in the seach box, and make sure you select make utility in Devel Category.



2. Install ARM GNU Compiler toolchain. Download and install gcc-arm-none-eabi-4_9-2015q2-20150609-win32.exe. It would be installed to C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2015q2 and you have to add the path of the installed ARM GNU compiler binaries to PATH environment variable in the Cygwin terminal. To do this, you can add the following line to .bashrc file.

export PATH=/cygdrive/c/Program\ Files\ \(x86\)/GNU\ Tools\ ARM\ Embedded/4.9\ 2015q2/bin/:$PATH

You have to restart Cygwin to enable PATH varibale and type "which arm-none-eabi-gcc" to confirm Cygwin uses correct arm-none-eabi-gcc version.

3. Download and install Msysgit from http://msysgit.github.io/. Remember to select "Use Git Bash only" during installion.





you also have to add the path of the installed Git binaries to PATH environment variable in the Cygwin terminal. To do this, you can add the following line to .bashrc file. You have to restart Cygwin to enable PATH varibale

export PATH=/cygdrive/c/Program\ Files/GNU/bin/:$PATH

4. Switch to C drive by run "cd /cygdrive/c/" under Cygwin. Then, run "git clone --recursive https://github.com/contiki-os/contiki"



5. To build cc26xx-web-demo for CC2650STK, run "cd /cygdrive/c/contiki/examples/cc26xx/cc26xx-web-demo/" and then "make BOARD=sensortag/cc2650 cc26xx-web-demo.bin".



6. After finishing, you will have cc26xx-web-demo.bin under C:\contiki\examples\cc26xx\cc26xx-web-demo

7. You can download cc26xx-web-demo.bin to CC2650STK by using TI Flash Programmer2.

8. For CC2538DK, you can do similar steps to make it work.