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.

CC2640R2F: CC2640R2F

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2340R5, CC2651R3

After porting a working reader app from blestack to the ble5stack, I cannot get past the device initialization,

i.e the breakpoint set in GAP_DEVICE_INIT_DONE_EVENT: in SimpleCentral_processGapMsg() is not hit.

The thread goes something like this:

SimpleCentral_init() GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (void *)attDeviceName);

icall_directAPI() errno = ICall_waitMatch(ICALL_TIMEOUT_PREDEFINE, matchLiteCS, NULL, NULL, (void **)&pCmdStatus);

if (errno == ICALL_ERRNO_TIMEOUT) { ICall_abort(); }

The ICall_waitMatch() takes about 5 seconds and then returns with ICALL_ERRNO_TIMEOUT.

It's likely something wrong with the porting, so I can use your help in figuring out what needs to change.

It may be more productive to have a remote debug session to go through the ported reader project and step through the code.

Let me know if that's possible and if so a convenient time to meet.

static void SimpleCentral_init(void)
{
  uint8_t i;

  // ******************************************************************
  // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
  // ******************************************************************
  // Register the current thread as an ICall dispatcher application
  // so that the application can send and receive messages.
  ICall_registerApp(&selfEntity, &syncEvent);

	uint32_t ccReg;

	 ccMode = CC_MODE_NORMAL;

	 curRssi = 0;
	 sendRssiMsg = FALSE;

	// Create an RTOS queue for message from profile to be sent to app.
	appMsgQueue = Util_constructQueue(&appMsg);

	//Create a queue to hold messages to send
	sendMsgQueue = Util_constructQueue(&sendMsg);

	// Setup discovery delay as a one-shot timer
	Util_constructClock(&startDiscClock, SimpleBLECentral_startDiscHandler,
						DEFAULT_SVC_DISCOVERY_DELAY, 0, false, 0);

	Util_constructClock(&oneMinClock, oneMinuteClockHandler,
						ONE_MINUTE_DELAY, 0, false, 0);

	Util_constructClock(&discCompleteClock, discCompleteHandler,
						SVC_DISCOVERY_COMPLETE, 0, false, 0);

	dispHandle = Display_open(SBC_DISPLAY_TYPE, NULL);

	// Initialize internal data
	for (i = 0; i < MAX_NUM_BLE_CONNS; i++)
	{
	  readRssi[i].connHandle = CONNHANDLE_INVALID;
	  readRssi[i].pClock = NULL;
	}

	GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN,
					 (void *)attDeviceName);

	//Set default values for Data Length Extension
	//Extended Data Length Feature is already enabled by default
	//in build_config.opt in stack project.
	{
	  //Set initial values to maximum, RX is set to max. by default(251 octets, 2120us)
#define APP_SUGGESTED_PDU_SIZE 251 //default is 27 octets(TX)
#define APP_SUGGESTED_TX_TIME 2120 //default is 328us(TX)

	  //This API is documented in hci.h
	  //See the LE Data Length Extension section in the BLE5-Stack User's Guide for information on using this command:
	  //http://software-dl.ti.com/lprf/ble5stack-latest/
	  //HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME);
	}

	// Initialize GATT Client
	VOID GATT_InitClient();

	// Register to receive incoming ATT Indications/Notifications
	GATT_RegisterForInd(selfEntity);

	// Initialize GATT attributes
	GGS_AddService(GATT_ALL_SERVICES);		   // GAP
	GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes

	// Register for GATT local events and ATT Responses pending for transmission
	GATT_RegisterForMsgs(selfEntity);

	// Accept all parameter update requests
	GAP_SetParamValue(GAP_PARAM_LINK_UPDATE_DECISION, GAP_UPDATE_REQ_ACCEPT_ALL);

	// Register with GAP for HCI/Host messages (for RSSI)
	GAP_RegisterForMsgs(selfEntity);

	// Initialize GAP layer for Central role and register to receive GAP events
	GAP_DeviceInit(GAP_PROFILE_CENTRAL, selfEntity, addrMode, NULL);

}

  • Hey Tony,

    Thanks for posting on e2e. Can you clarify which SDK version you are on?

    When going from blestack to ble5stack, the first thing that pops in mind is a potential issue with memory consumption. The CC2640R2F has fairly limited memory when it comes to ble5. Can you add HEAPMGR_METRICS to your predefined symbols, rebuild the project, and check to see if there is any memory allocation failures?

    Here's a section of our User's Guide that can help. https://software-dl.ti.com/simplelink/esd/simplelink_cc2640r2_sdk/5.30.00.03/exports/docs/ble5stack/ble_user_guide/html/ble-stack-5.x-guide/debugging-index.html#debugging-common-heap-issues

  • The SDK is simplelink_cc2640r2_sdk_4_10_00_10

    It doesn't seem to have a heap issue... here's the screen dump at breakpoint 

  • Hi Tony,

    Thank you for reaching out and providing these details.

    Here are a few leads I can think of:

    - for sanity, could you please try to run the out of the box (unmodified) ble5 simple_central example? 

    - for sanity, could you please verify the return value of the function ICall_registerApp(). You can use the snippet bellow:

      volatile ICall_Errno errno;
      errno = ICall_registerApp(&selfEntity, &syncEvent);

    - for sanity, could you please specify how many ICall enabled tasks you have?

    - could you please verify the content of the main.c file? Among others, I would like you verify the following code is called:

    int main()
    {
    
    //...
    
      Board_initGeneral();
    
    //...
    
      /* Initialize ICall module */
      ICall_init();
    
      /* Start tasks of external images - Priority 5 */
      ICall_createRemoteTasks();
    
      /* Kick off application - Priority 1 */
      SimpleCentral_createTask();
    
    //...
    
    }

    In case this does not help, I would like we review together the porting process you have followed.

    Best regards,

  • - for sanity, could you please try to run the out of the box (unmodified) ble5 simple_central example? 

    [tony] I have ran the simple central example on the launchpad with no problems.

    - for sanity, could you please verify the return value of the function ICall_registerApp(). You can use the snippet bellow:

      volatile ICall_Errno errno;  errno = ICall_registerApp(&selfEntity, &syncEvent);

    [tony] the return code is 0

    - for sanity, could you please specify how many ICall enabled tasks you have?

    [tony] I've added 1 task to support PTM mode over the UART

    - could you please verify the content of the main.c file? Among others, I would like you verify the following code is called:

    [tony] see the inserted main.c

    int main()
    {
      /* Register Application callback to trap asserts raised in the Stack */
      RegisterAssertCback(AssertHandler);
    
      Board_initGeneral();
    
      // Enable iCache prefetching
      VIMSConfigure(VIMS_BASE, TRUE, TRUE);
    
      // Enable cache
      VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
    
    #if !defined( POWER_SAVING )
      /* Set constraints for Standby, powerdown and idle mode */
      // PowerCC26XX_SB_DISALLOW may be redundant
      Power_setConstraint(PowerCC26XX_SB_DISALLOW);
      Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
    #endif // POWER_SAVING
    
      user0Cfg.appServiceInfo->timerTickPeriod = Clock_tickPeriod;
      user0Cfg.appServiceInfo->timerMaxMillisecond  = ICall_getMaxMSecs();
    
      /* Initialize ICall module */
      ICall_init();
    
      /* Start tasks of external images - Priority 5 */
      ICall_createRemoteTasks();
    
    // TSL  
      if (!(PIN_getInputValue(CC_TEST))) // Normal mode
      {
          /* create serial task - Priority 1 */
          serial_createTask();
      }
    
    #if 0
      /* Kick off profile - Priority 3 */
      GAPCentralRole_createTask();
    #endif
      
      /* Kick off application - Priority 1 */
      SimpleCentral_createTask();
    
      /* enable interrupts and start SYS/BIOS */
      BIOS_start();
    
      return 0;
    }
    
    

    In case this does not help, I would like we review together the porting process you have followed.

    [tony] that would be great. I'm available today

  • Clement,

    I'm in California Pacific time zone.

    Please let me know when you would be available for this review.

    Thanks.

  • Hi Tony,

    I am seeing your message just now (I am based in Europe). For the moment, I suggest we keep investigate the issue here.

    - Can you run a test for me where you completely remove support for PTM? That way we can understand if this is the source of the issue.

    - Could you also use the ROV to see if you can spot some issues? You can refer to the debugging guide for details.

    Best regards,

  • Clement,

    After the PTM code is disabled from the build, i.e. PTM_INCLUDE is not defined, the CC startup can complete device initialization - GAP_DEVICE_INIT_DONE_EVENT is received from the stack.

    I can continue without the PTM for now, but eventually I need to get PTM working to support manufacturing.

    Any idea to overcome that would be appreciated.

    Tony

    #pragma optimize=none
    static void SimpleCentral_init(void)
    {
      uint8_t i;
      volatile ICall_Errno errno;
    
      // ******************************************************************
      // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
      // ******************************************************************
      // Register the current thread as an ICall dispatcher application
      // so that the application can send and receive messages.
      errno = ICall_registerApp(&selfEntity, &syncEvent);
    
    #ifdef PTM_INCLUDE
      if ((PIN_getInputValue(CC_TEST)))
    	{
      
    		ccMode = CC_MODE_PTM;
      
    		/* Start task for NPI task */
    		NPITask_createTask(ICALL_SERVICE_CLASS_BLE);
      
    		//prevent PM
    		Power_setConstraint(PowerCC26XX_SB_DISALLOW);
    		Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
      
    		// Intercept NPI RX events.
    		NPITask_registerIncomingRXEventAppCB(SBP_handleNPIRxInterceptEvent, INTERCEPT);
      
    		// Register for Command Status information
    		HCI_TL_Init(NULL, (HCI_TL_CommandStatusCB_t) SBP_sendToNPI, NULL, selfEntity);
      
    		// Register for Events
    		HCI_TL_getCmdResponderID(ICall_getLocalMsgEntityId(ICALL_SERVICE_CLASS_BLE_MSG, selfEntity));
      
    		//enable PTM
    		HCI_EXT_EnablePTMCmd();
      
    	}
    	else  // proceed as normal application
    #endif
    	{
    		uint32_t ccReg;
      
    		 ccMode = CC_MODE_NORMAL;
      
    		 curRssi = 0;
    		 sendRssiMsg = FALSE;
      
    	   // Create an RTOS queue for message from profile to be sent to app.
    		appMsgQueue = Util_constructQueue(&appMsg);
      
    		//Create a queue to hold messages to send
    		sendMsgQueue = Util_constructQueue(&sendMsg);
      
    		// Setup discovery delay as a one-shot timer
    		Util_constructClock(&startDiscClock, SimpleBLECentral_startDiscHandler,
    							DEFAULT_SVC_DISCOVERY_DELAY, 0, false, 0);
      
    		Util_constructClock(&oneMinClock, oneMinuteClockHandler,
    							ONE_MINUTE_DELAY, 0, false, 0);
      
    		Util_constructClock(&discCompleteClock, discCompleteHandler,
    							SVC_DISCOVERY_COMPLETE, 0, false, 0);
      
    		dispHandle = Display_open(SBC_DISPLAY_TYPE, NULL);
      
    		// Initialize internal data
    		for (i = 0; i < MAX_NUM_BLE_CONNS; i++)
    		{
    		  readRssi[i].connHandle = CONNHANDLE_INVALID;
    		  readRssi[i].pClock = NULL;
    		}
      
    		GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN,
    						 (void *)attDeviceName);
    		
    		//Set default values for Data Length Extension
    		//Extended Data Length Feature is already enabled by default
    		//in build_config.opt in stack project.
    		{
    		  //Set initial values to maximum, RX is set to max. by default(251 octets, 2120us)
      #define APP_SUGGESTED_PDU_SIZE 251 //default is 27 octets(TX)
      #define APP_SUGGESTED_TX_TIME 2120 //default is 328us(TX)
    		
    		  //This API is documented in hci.h
    		  //See the LE Data Length Extension section in the BLE5-Stack User's Guide for information on using this command:
    		  //http://software-dl.ti.com/lprf/ble5stack-latest/
    		  //HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME);
    		}
    		
    		// Initialize GATT Client
    		VOID GATT_InitClient();
    		
    		// Register to receive incoming ATT Indications/Notifications
    		GATT_RegisterForInd(selfEntity);
    		
    		// Initialize GATT attributes
    		GGS_AddService(GATT_ALL_SERVICES);		   // GAP
    		GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes
    		
    		// Register for GATT local events and ATT Responses pending for transmission
    		GATT_RegisterForMsgs(selfEntity);
    		
    	
    		// Accept all parameter update requests
    		GAP_SetParamValue(GAP_PARAM_LINK_UPDATE_DECISION, GAP_UPDATE_REQ_ACCEPT_ALL);
    		
    		// Register with GAP for HCI/Host messages (for RSSI)
    		GAP_RegisterForMsgs(selfEntity);
    		
    		// Initialize GAP layer for Central role and register to receive GAP events
    		GAP_DeviceInit(GAP_PROFILE_CENTRAL, selfEntity, addrMode, NULL);
    		
    		dispHandle = Display_open(Display_Type_ANY, NULL);
    		
      
    		// reset patch state
    		resetPatchState();
      
    		sendPrintString(CC_STARTUP_STRING);
    		sendVersion(swVersion, sizeof(swVersion));
      
    		ccReg = (uint32_t)HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL);
      //	  sendPrintString("RESETCTL Register:");
      //	  sendPrintBytes(&ccReg, 4);
      
    		sendResetReason(ccReg&0xFF);
      
    		cryptoInit();
      
    #ifdef LF_CLOCK_OUTPUT_TEST
    		IOCPortConfigureSet( IOID_0, IOC_PORT_AON_CLK32K, IOC_STD_OUTPUT );
    		AONIOC32kHzOutputEnable();
    #endif
    	 }
    }
    
    

  • Hi Tony,

    After the PTM code is disabled from the build, i.e. PTM_INCLUDE is not defined, the CC startup can complete device initialization - GAP_DEVICE_INIT_DONE_EVENT is received from the stack.

    This is a great step forward in this debugging effort.

    Let's now try to review what are the consequences of enabling PTM:

    - it should not require an additional ICall enabled task, but, as it is an easy test, I would like you double check if increasing the value of the following preprocessor defines could help: ICALL_MAX_NUM_TASKS (App), ICALL_MAX_NUM_ENTITIES (App) and OSAL_MAX_NUM_PROXY_TASKS (Stack) [just add 1 to all the defines at the same time, rebuild all and test]

    - additional RAM consumption - Can you comment whether the NPI task (in NPITask_createTask function) is created using "Task_create" or "Task_construct"? Changing to "Task_create" would save RAM when NPI is not used.
    Could you please try this and let us know if it helps the behavior when PTM is enabled but not used?

    - Could you also use the ROV to see if you can spot some issues in the NPI task? You can refer to the debugging guide for details.

    I hope this will help,

    Best regards,

  • First, I'll address the questions regarding PTM, then I'll report some new findings to the running ported code.

    1. adding 1 to the three tasks did not change the behavior

    2. changing the Task_construct to Task_create works, so this is only code change that can make device complete initialiation.

    Now I am dealing with a heap memory issue when the reader connects to the sensor and the GAP_LINK_ESTABLISHED_EVENT is not hit...

    The ble sniffer trace shows that reader is sending the CONNECT_IND packet on one of the advertising channels, but the heap memory failed.

    the reader calls connectPatch() to scan for the advertising packets from the sensor based on the public BD address.

    The heap stats are:

    heapmgrMemFail 0.
    heapmgrMemUB 3536
    HEAPMGR_SIZE 3659
    heapHiWaterMark 3563

    so I think the heap memory is still OK after this call.

    When the reader detects the sensor advertising packets, the CONNECT_IND is sent, it looks like during this time the heap memory is corrupted and heapmgrMemFail  is no longer 0.

    heapmgrMemFail 293
    heapmgrMemUB 3632
    HEAPMGR_SIZE 3659
    heapHiWaterMark 3563

    I'll try to get familiar with the ROV, but let me know if you would like to see more code and offer suggestions to debug the heap memory issue.

    static void connectPatch(uint8_t addrType, uint8_t* addr)
    {
      if (state == BLE_STATE_IDLE)
      {
    
              disablePowerSaving();
    
    		  GapInit_connect(addrType, addr,
                      DEFAULT_INIT_PHY, 0);
     
    
              state = BLE_STATE_CONNECTING;
    
      }
      return;
    }
    

  • Below are the heap mgr stats for the reader app  between blestack and ble5stack taken at device_init_done event.

    // blestack heapmgrMemFail 0 heapmgrMemUB 2884 HEAPMGR_SIZE 4751 heapHiWaterMark 4655
    //ble5stack heapmgrMemFail 0 heapmgrMemUB 3536 HEAPMGR_SIZE 3659 heapHiWaterMark 3563

    The heap size drop by 1100 bytes and the upper bound increased by 650 bytes.

    Any suggestions to trim the ble5stack heap usage for basic connect and disconnect without 4.2 pairing and bonding ?

  • Hi Tony,

    Thank you for the updates.

    I would recommend you review https://software-dl.ti.com/simplelink/esd/simplelink_cc2640r2_sdk/5.30.00.03/exports/docs/ble5stack/ble_user_guide/html/ble-stack-5.x/creating-a-custom-bluetooth-low-energy-application-cc2640.html#ram-optimization

    If this is not sufficient, you may want to consider migrating to a different device such as CC2651R3 or CC2340R5.

    Best regards,

  • I've removed the NPI code that supports PTM to see how much the heap can be enlarged and found that it is quite significant.

    It went from 3659 to 5415 bytes.

    With the larger heap, the reader application can run and can communicate with the sensor similar to the reader app built with the ble 4.2 stack.

    The heapmgrMemUB went up to 5196, so clearly exceeded the 3659 available when the app was built with PTM code.

    For now, I can continue with the development.

    In the future, we can either have a separate build for PTM and for the reader application or we can migrate to a different device.

    I will defer this decision at a later date.

    Thanks for your help and we can close this issue.

    Tony