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.

LAUNCHXL-CC2650: Launchpad "Reset Button" program glitch

Part Number: LAUNCHXL-CC2650
Other Parts Discussed in Thread: CCSTUDIO

I have been able to successfully record data from the ADC and send this data over BLE to a laptop. However, whenever the board is powered down (via unplugging the usb) or by pressing the "Reset" button on the launchpad, the code seems to bug. My project is based on Project Zero.

What works:

  1. I can reprogram the board and it will work fine. It sets all parameters properly, starts clocks, reads the ADC, and transmits with notification over BLE.

What doesn't work (after power down / reset):

  1. The device no longer advertises (advertises very briefly during startup initialization).
  2. The device no longer loops through main loop.

It seems to get stuck somewhere in the code, but since it is a reset, I cannot track it in the debugger. If there is any point in my main function loop that causes the code to leave the main task loop (ie go to Idle or other task) it never returns to my main loop [to see this I have used semaphores, task_sleep, etc].

Any help is appreciated!

  • Hi Josh,

    Do you know if it enters main() at all after reset? Can you toggle a pin or something as the first thing in main to verify?

    Cheers,
    Fredrik
  • My post was unclear. The program runs until the ProjectZero_taskFxn.  It performs all of the functions in ProjectZero_init(). Once it leaves the ProjectZero_taskFxn, however, it does not return. Here is a code snippet (I can add all of the code but I didn't want to overload the post).

    static void ProjectZero_taskFxn(UArg a0, UArg a1)
    {
      ProjectZero_init();              // Initialize application
      uint16_t timeSep = 1300;         // multiplier that separates data points ( should be greater than 1000), higher values have LESS separation
    
      // Application main loop
      for (;;)
      {
          // AFTER RESET FAILS HERE v
          Semaphore_pend(hSem, BIOS_WAIT_FOREVER );      // Block task
          GAPRole_GetParameter(GAPROLE_STATE, &state);   // Check if in a connection
          if ( state == 6 )                              // if connected measure, if not connected sleep in idle thread
          {
    
                while(currentSample < SAMPLECOUNT)
                {
                    PIN_setOutputValue(pinHandle, PIN_ID(25), 1); // Turn on LED
                    Task_sleep( 0.1 * (1000 / Clock_tickPeriod)); // Sleep during rise time of LED and PD
                    AUXADCGenManualTrigger();                     // Sample ADC
                    adcValue = AUXADCReadFifo();                  // Read last ADC result
                    PIN_setOutputValue(pinHandle, PIN_ID(25), 0); // Turn off LED
                    initLED0[2*currentSample] = adcValue & 0xff;  // Convert uint16 to two uint8's
                    initLED0[2*currentSample+1] = adcValue>>8;
    
                    PIN_setOutputValue(pinHandle, Board_LED0, 1); // Turn on LED
                    Task_sleep( 0.1 * (1000 / Clock_tickPeriod)); // Sleep during rise time of LED and PD
                    AUXADCGenManualTrigger();                     // Sample ADC
                    adcValue = AUXADCReadFifo();                  // Read last ADC result
                    PIN_setOutputValue(pinHandle, Board_LED0, 0); // Turn off LED
                    initLED1[2*currentSample] = adcValue & 0xff;  // Convert uint16 to two uint8's
                    initLED1[2*currentSample+1] = adcValue>>8;
    
                    Task_sleep(LED_PERIODIC_EVT_PERIOD / (SAMPLECOUNT*NUMSENSORS*(timeSep/1000)) * (1000 / Clock_tickPeriod)); // Sleep in idle thread (s) (ms) (us)
    
                    currentSample++;                              // Prepare next loop
                }
    
                DataService_SetParameter(DS_LED0_ID, CUSTOM_DATA_LEN, initLED0); // Set Attribute Value
                DataService_SetParameter(DS_LED1_ID, CUSTOM_DATA_LEN, initLED1); // Set Attribute Value
    
                currentSample = 0;
    
          } // END IF (STATE == 6) CONNECTED
      } // END MAIN APPLICATION FOR LOOP
    } // END TASK FUNCTION

    The code fails at the semaphore_pend, since at this point it leaves the task function (to idle or other thread, idk which). There is nothing wrong with the semaphore (to my knowledge), as I have replaced the semaphore (which is attached to a clock) with Task_Sleep instead and it has the same behavior. I have also replaced the semaphore with CPUdelay and was able to see the LED's blinking, meaning that the code would continue to run if it never leaves the task.

  • Hi,

    Are you using TI Compiler v5.2.6?

    Best wishes
  • I was using compiler version 16.9.3.LTS. After downloading and changing the compiler in Project Settings to 5.2.6 I get this error when switching:

    The log file says:

    !CONFIGURATION: 'com.ti.ccstudio.buildDefinitions.TMS470.Debug.1695854183' [Thu Aug 10 19:31:15 EDT 2017]

    !TOOL: 'com.ti.ccstudio.buildDefinitions.TMS470_5.2.hex.1480184981'

    !WARNING: Unresolved option: com.ti.ccstudio.buildDefinitions.TMS470_5.2.hex.MEMWIDTH

    !WARNING: Unresolved option: com.ti.ccstudio.buildDefinitions.TMS470_5.2.hex.ROMWIDTH

    !WARNING: Unresolved option: com.ti.ccstudio.buildDefinitions.TMS470_5.2.hex.OUTPUT_FORMAT

    And building gives this error.

  • In order to work around the above error I created a new workspace and imported a clean project_zero, then replaced the files with my own. I was able to build (with v5.2.6) with this new project and once again it operated correctly until reset/power down.....

    As a sanity test I loaded Project_Zero on the board with (v5.2.6) and it worked perfectly even after reset. I also built Project_Zero with v16.9.4.LTS and it also worked, even after reset. This leads me to believe it is not a compiler issue?

    Since my main.c file is mostly the same, I'll only post my project_zero.c here. Maybe a variable is defined improperly and not being cleared in a reset versus a reprogram??

    /*********************************************************************
     * INCLUDES
     */
    #include <string.h>                     // String functions. Memset and memcopy.
    
    //#define xdc_runtime_Log_DISABLE_ALL 1   // Add to disable logs from this file
    
    #include <ti/sysbios/knl/Task.h>        // Required for Tasks
    #include <ti/sysbios/knl/Semaphore.h>   // Used to block tasks
    #include <ti/sysbios/knl/Queue.h>       // Used for GAP state changes and passcode messages
    #include <ti/sysbios/knl/Clock.h>       // Periodic event clock
    #include <ti/sysbios/BIOS.h>            // Required for RTOS
    
    #include <ti/drivers/PIN.h>             // PIN setup and usage
    #include <ti/drivers/ADC.h>             // Unused ADC header with functions. Did not allow parameter setting.
    
    #include <driverlib/aux_adc.h>          // aux adc control functions
    #include <driverlib/aux_wuc.h>          // aux adc clock
    
    #include <xdc/runtime/Log.h>            // UART Logs (to Putty/terminal)
    #include <xdc/runtime/Diags.h>          //
    
    // Stack headers
    #include <hci_tl.h>
    #include <gap.h>
    #include <gatt.h>
    #include <gapgattserver.h>
    #include <gattservapp.h>
    #include <osal_snv.h>
    #include <gapbondmgr.h>
    #include <peripheral.h>
    #include <icall_apimsg.h>
    #include <devinfoservice.h>
    #include "util.h"
    #include "Board.h"
    #include "project_zero.h"
    
    // Bluetooth Developer Studio services
    #include "data_service.h"               // Custom Service
    
    
    /*********************************************************************
     * CONSTANTS
     */
    #define DEFAULT_ADVERTISING_INTERVAL          1600          // Advertising interval when device is discoverable (units of 625us, 160=100ms)
    
    // Limited discoverable mode advertises for 30.72s, and then stops
    // General discoverable mode advertises indefinitely
    #define DEFAULT_DISCOVERABLE_MODE             GAP_ADTYPE_FLAGS_GENERAL
    
    #define DEFAULT_PASSCODE                      000000        // Default pass-code used for pairing.
    
    // Task configuration
    #define PRZ_TASK_PRIORITY                     1
    
    #ifndef PRZ_TASK_STACK_SIZE
    #define PRZ_TASK_STACK_SIZE                   800
    #endif
    
    // Internal Events for RTOS application
    #define PRZ_STATE_CHANGE_EVT                  0x0001
    #define PRZ_CHAR_CHANGE_EVT                   0x0002
    #define PRZ_PERIODIC_EVT                      0x0004
    #define PRZ_CONN_EVT_END_EVT                  0x0008
    
    /**********************************************************************************/
    /*********************************************************************
     * CUSTOM VARIABLES and Constants
     */
    #define SAMPLECOUNT (CUSTOM_DATA_LEN/2) // This is because the uint16 is stored as two uint8's
    #define NUMSENSORS 2                    // Number of sensors
    
    uint8_t initLED0[CUSTOM_DATA_LEN] = {0};  // Placeholder variable for characteristic initialization
    uint8_t initLED1[CUSTOM_DATA_LEN] = {0};
    
    uint8_t currentSample = 0;    // Sample counter
    ADC_Handle   adc;             // adc handle
    ADC_Params   params;          // adc parameters
    uint16_t adcValue;            // adc read result
    uint8_t state;                // GAPROLE_STATE
    
    static PIN_Handle pinHandle;  // Pin driver handles
    static PIN_State pinState;    // Global memory storage for a PIN_Config table
    
    PIN_Config pinTable[] = {     // Initial Pin Config
        PIN_ID(25) | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // GPIO 25 launchpad (10 MODA)
        Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PIN_TERMINATE
    };
    
    static Clock_Struct periodicClock;          // Main task clock structure
    static void LED_Clock_Handler(UArg arg);    // Main task clock handler
    # define LED_PERIODIC_EVT_PERIOD      1000  // periodic event, period (in msec)
    Semaphore_Struct sem0;                      // Main task semaphore structure
    Semaphore_Handle hSem;                      // Main task semaphore handle
    
    /**********************************************************************************/
    /*********************************************************************
     * TYPEDEFSF
     */
    // Types of messages that can be sent to the user application task from other
    // tasks or interrupts. Note: Messages from BLE Stack are sent differently.
    typedef enum
    {
      APP_MSG_SERVICE_WRITE = 0,   /* A characteristic value has been written     */
      APP_MSG_SERVICE_CFG,         /* A characteristic configuration has changed  */
      APP_MSG_UPDATE_CHARVAL,      /* Request from ourselves to update a value    */
      APP_MSG_GAP_STATE_CHANGE,    /* The GAP / connection state has changed      */
      APP_MSG_BUTTON_DEBOUNCED,    /* A button has been debounced with new value  */
      APP_MSG_SEND_PASSCODE,       /* A pass-code/PIN is requested during pairing */
    } app_msg_types_t;
    
    // Struct for messages sent to the application task
    typedef struct
    {
      Queue_Elem       _elem;
      app_msg_types_t  type;
      uint8_t          pdu[];
    } app_msg_t;
    
    // Struct for messages about characteristic data
    typedef struct
    {
      uint16_t svcUUID; // UUID of the service
      uint16_t dataLen; //
      uint8_t  paramID; // Index of the characteristic
      uint8_t  data[];  // Flexible array member, extended to malloc - sizeof(.)
    } char_data_t;
    
    // Struct for message about sending/requesting passcode from peer.
    typedef struct
    {
      uint16_t connHandle;
      uint8_t  uiInputs;
      uint8_t  uiOutputs;
      uint32   numComparison;
    } passcode_req_t;
    
    // Struct for message about button state
    typedef struct
    {
      PIN_Id   pinId;
      uint8_t  state;
    } button_state_t;
    
    /*********************************************************************
     * LOCAL VARIABLES
     */
    
    static ICall_EntityID selfEntity; // Entity ID globally used to check for source and/or destination of messages
    static ICall_Semaphore sem; // Semaphore globally used to post events to the application thread
    
    static Queue_Struct applicationMsgQ; // Queue object used for application messages.
    static Queue_Handle hApplicationMsgQ;
    
    Task_Struct przTask; // Task configuration
    Char przTaskStack[PRZ_TASK_STACK_SIZE];
    
    // GAP - SCAN RSP data (max size = 31 bytes)
    static uint8_t scanRspData[] =
    {
      // No scan response data provided.
      0x00 // Placeholder to keep the compiler happy.
    };
    
    // GAP - Advertisement data (max size = 31 bytes, though this is best kept short to conserve power while advertising)
    static uint8_t advertData[] =
    {
      // Flags; this sets the device to use limited discoverable mode (advertises for 30 seconds at a time) or general
      // discoverable mode (advertises indefinitely), depending
      // on the DEFAULT_DISCOVERY_MODE define.
      0x02,   // length of this data
      GAP_ADTYPE_FLAGS,
      DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
    
      // complete name
      4, // name length+1
      GAP_ADTYPE_LOCAL_NAME_COMPLETE,
      'L', 'P', '1', // Name Seen before Pairing (Short for LED Probe)
    };
    
    // GAP GATT Attributes
    static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "LP"; // Name Seen After Pairing (not needed for bluePy)
    
    /*********************************************************************
     * LOCAL FUNCTIONS
     */
    
    static void ProjectZero_init( void );
    static void ProjectZero_taskFxn(UArg a0, UArg a1);
    
    static void user_processApplicationMessage(app_msg_t *pMsg);
    static void user_processGapStateChangeEvt(gaprole_States_t newState);
    static void user_gapStateChangeCB(gaprole_States_t newState);
    static void user_gapBondMgr_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
                                           uint8_t uiInputs, uint8_t uiOutputs, uint32 numComparison);
    static void user_gapBondMgr_pairStateCB(uint16_t connHandle, uint8_t state,
                                            uint8_t status);
    
    // Generic callback handlers for value changes in services.
    static void user_service_ValueChangeCB( uint16_t connHandle, uint16_t svcUuid, uint8_t paramID, uint8_t *pValue, uint16_t len );
    static void user_service_CfgChangeCB( uint16_t connHandle, uint16_t svcUuid, uint8_t paramID, uint8_t *pValue, uint16_t len );
    
    // Utility functions
    static void user_enqueueRawAppMsg(app_msg_types_t appMsgType, uint8_t *pData, uint16_t len );
    static void user_enqueueCharDataMsg(app_msg_types_t appMsgType, uint16_t connHandle,
                                        uint16_t serviceUUID, uint8_t paramID,
                                        uint8_t *pValue, uint16_t len);
    
    static char *Util_getLocalNameStr(const uint8_t *data);
    
    /*********************************************************************
     * PROFILE CALLBACKS
     */
    
    // GAP Role Callbacks
    static gapRolesCBs_t user_gapRoleCBs =
    {
      user_gapStateChangeCB     // Profile State Change Callbacks
    };
    
    // GAP Bond Manager Callbacks
    static gapBondCBs_t user_bondMgrCBs =
    {
      user_gapBondMgr_passcodeCB, // Passcode callback
      user_gapBondMgr_pairStateCB // Pairing / Bonding state Callback
    };
    
    /*
     * Callbacks in the user application for events originating from BLE services.
     */
    // Data Service callback handler.
    // The type Data_ServiceCBs_t is defined in data_service.h
    static DataServiceCBs_t user_Data_ServiceCBs =
    {
      .pfnChangeCb    = user_service_ValueChangeCB, // Characteristic value change callback handler
      .pfnCfgChangeCb = user_service_CfgChangeCB, // Noti/ind configuration callback handler
    };
    // *********************************************************************************************
    // *********************************************************************************************
    /*********************************************************************
     * PUBLIC FUNCTIONS
     */
    /*
     * @brief   Task creation function for the user task.
     */
    void ProjectZero_createTask(void)
    {
      Task_Params taskParams;
    
      // Configure task
      Task_Params_init(&taskParams);
      taskParams.stack = przTaskStack;
      taskParams.stackSize = PRZ_TASK_STACK_SIZE;
      taskParams.priority = PRZ_TASK_PRIORITY;
      Task_construct(&przTask, ProjectZero_taskFxn, &taskParams, NULL);
    }
    
    /***********************************************************************
     * @brief   Called before the task loop and contains application-specific
     *          initialization of the BLE stack, hardware setup, power-state
     *          notification if used, and BLE profile/service initialization.
     */
    static void ProjectZero_init(void)
    {
      // ******************************************************************
      // NO 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 via ICall to Stack.
      ICall_registerApp(&selfEntity, &sem);
      Log_info0("Initializing the user task, hardware, BLE stack and services.");
    
      // Initialize queue for application messages.
      // Note: Used to transfer control to application thread from e.g. interrupts.
      Queue_construct(&applicationMsgQ, NULL);
      hApplicationMsgQ = Queue_handle(&applicationMsgQ);
    
      // ******************************************************************
      // Hardware initialization
      // ******************************************************************
    
      /* Open LED pins */
      pinHandle = PIN_open(&pinState, pinTable);
      // Enable clock for ADC digital and analog interface (not currently enabled in driver)
      AUXWUCClockEnable(AUX_WUC_MODCLKEN0_ANAIF_M|AUX_WUC_MODCLKEN0_AUX_ADI4_M);
      // Set up ADC
      AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
      // Connect (DIO 30 on launch is 0 on AUX)(DIO 23 on launch is 7 on aux). See swcu117g 11.8 for MODA mapping.
      AUXADCSelectInput(ADC_COMPB_IN_AUXIO0);
    
      // ******************************************************************
      // BLE Stack initialization
      // ******************************************************************
    
      // Setup the GAP Peripheral Role Profile
      uint8_t initialAdvertEnable = TRUE;  // Advertise on power-up
    
      // By setting this to zero, the device will go into the waiting state after
      // being discoverable. Otherwise wait this long [ms] before advertising again.
      uint16_t advertOffTime = 0; // miliseconds
      GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable); // Set advertisement enabled.
      GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &advertOffTime);     // Configure the wait-time before restarting advertisement automatically
      GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);       // Initialize Scan Response data
      GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);           // Initialize Advertisement data
    
      Log_info1("Name in advertData array: \x1b[33m%s\x1b[0m", (IArg)Util_getLocalNameStr(advertData));
    
      // Set advertising interval
      uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;
      GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt);
      GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt);
      GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt);
      GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
    
      // Set duration of advertisement before stopping in Limited adv mode.
      GAP_SetParamValue(TGAP_LIM_ADV_TIMEOUT, 30); // Seconds
    
      // ******************************************************************
      // BLE Bond Manager initialization
      // ******************************************************************
      uint32_t passkey = 0; // passkey "000000" [up to "999999"]
      uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
      uint8_t mitm = TRUE;
      uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
      uint8_t bonding = TRUE;
    
      GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey);
      GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
      GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
      GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
      GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
    
      // ******************************************************************
      // BLE Service initialization
      // ******************************************************************
    
      // Add services to GATT server
      GGS_AddService(GATT_ALL_SERVICES);           // GAP
      GATTServApp_AddService(GATT_ALL_SERVICES);   // GATT attributes
      DevInfo_AddService();                        // Device Information Service
    
      // Set the device name characteristic in the GAP Profile
      GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);
    
      // Add services to GATT server and give ID of this task for Indication acks.
      DataService_AddService( selfEntity );
    
      // Register callbacks with the generated services that
      // can generate events (writes received) to the application
      DataService_RegisterAppCBs( &user_Data_ServiceCBs );
    
      // Initalization of characteristics in Data_Service that can provide data.
      DataService_SetParameter(DS_LED0_ID, sizeof(initLED0), initLED0);
      DataService_SetParameter(DS_LED1_ID, sizeof(initLED1), initLED1);
    
      // Start the stack in Peripheral mode.
      VOID GAPRole_StartDevice(&user_gapRoleCBs);
    
      // Start Bond Manager
      VOID GAPBondMgr_Register(&user_bondMgrCBs);
    
      // Register with GAP for HCI/Host messages
      GAP_RegisterForMsgs(selfEntity);
    
      // Register for GATT local events and ATT Responses pending for transmission
      GATT_RegisterForMsgs(selfEntity);
    
      // ******************************************************************
      // Custom Initialization
      // ******************************************************************
    
      // Construct semaphore used for pending in task
      Semaphore_Params sParams;
      Semaphore_Params_init(&sParams);
      sParams.mode = Semaphore_Mode_BINARY;
      Semaphore_construct(&sem0, 0, &sParams);
      hSem = Semaphore_handle(&sem0);
    
      // Set the Transmit Power of the Device, [ POWER_MINUS_21_DBM : 18,15,12,9,6,3 ] [ POWER_0_DBM : 1,2,3,4,5 ]
      HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_0_DBM);
    
      // Create clocks for internal periodic events.
      Util_constructClock(&periodicClock, LED_Clock_Handler, LED_PERIODIC_EVT_PERIOD, LED_PERIODIC_EVT_PERIOD, TRUE, PRZ_PERIODIC_EVT);
    }
    
    
    /* *****************************************************************************
     * *****************************************************************************
     * @brief   Application task entry point.
     *
     *          Invoked by TI-RTOS when BIOS_start is called. Calls an init function
     *          and enters an infinite loop waiting for messages.
     *
     *          Messages can be either directly from the BLE stack or from user code
     *          like Hardware Interrupt (Hwi) or a callback function.
     *
     *          The reason for sending messages to this task from e.g. Hwi's is that
     *          some RTOS and Stack APIs are not available in callbacks and so the
     *          actions that may need to be taken is dispatched to this Task.
     *
     * @param   a0, a1 - not used.
     */
    static void ProjectZero_taskFxn(UArg a0, UArg a1)
    {
      ProjectZero_init();              // Initialize application
    
      uint16_t timeSep = 1300;         // multiplier that separates data points ( should be greater than 1000), higher values have LESS separation
    
      // Application main loop
      for (;;)
      {
          // AFTER RESET FAILS HERE v
          Semaphore_pend(hSem, BIOS_WAIT_FOREVER );      // Block task: [BIOS_WAIT_FOREVER] OR [LED_PERIODIC_EVT_PERIOD*10*(1000 / Clock_tickPeriod)] to prevent getting stuck
          GAPRole_GetParameter(GAPROLE_STATE, &state);   // Check if in a connection
          if ( state == 6 )                              // if connected measure, if not connected sleep in idle thread
          {
    
                while(currentSample < SAMPLECOUNT)
                {
                    PIN_setOutputValue(pinHandle, PIN_ID(25), 1); // Turn on LED
                    Task_sleep( 0.1 * (1000 / Clock_tickPeriod)); // Sleep during rise time of LED and PD
                    AUXADCGenManualTrigger();                     // Sample ADC
                    adcValue = AUXADCReadFifo();                  // Read last ADC result
                    PIN_setOutputValue(pinHandle, PIN_ID(25), 0); // Turn off LED
                    initLED0[2*currentSample] = adcValue & 0xff;  // Convert uint16 to two uint8's
                    initLED0[2*currentSample+1] = adcValue>>8;
    
                    PIN_setOutputValue(pinHandle, Board_LED0, 1); // Turn on LED
                    Task_sleep( 0.1 * (1000 / Clock_tickPeriod)); // Sleep during rise time of LED and PD
                    AUXADCGenManualTrigger();                     // Sample ADC
                    adcValue = AUXADCReadFifo();                  // Read last ADC result
                    PIN_setOutputValue(pinHandle, Board_LED0, 0); // Turn off LED
                    initLED1[2*currentSample] = adcValue & 0xff;  // Convert uint16 to two uint8's
                    initLED1[2*currentSample+1] = adcValue>>8;
    
                    Task_sleep(LED_PERIODIC_EVT_PERIOD / (SAMPLECOUNT*NUMSENSORS*(timeSep/1000)) * (1000 / Clock_tickPeriod)); // Sleep in idle thread (s) (ms) (us)
    
                    currentSample++;                              // Prepare next loop
                }
    
                DataService_SetParameter(DS_LED0_ID, CUSTOM_DATA_LEN, initLED0); // Set Attribute Value
                DataService_SetParameter(DS_LED1_ID, CUSTOM_DATA_LEN, initLED1); // Set Attribute Value
    
                currentSample = 0;
    
          } // END IF (STATE == 6) CONNECTED
      } // END MAIN APPLICATION FOR LOOP
    } // END TASK FUNCTION
    
    /******************************************************************************
     *****************************************************************************
     *
     *  Handlers of system/application events deferred to the user Task context.
     *  Invoked from the application Task function above.
     *
     *  Further down you can find the callback handler section containing the
     *  functions that defer their actions via messages to the application task.
     *
     ****************************************************************************
     *****************************************************************************/
    
    /*********************************************************************
     * @fn      LED_Clock_Handler
     *
     * @brief   Handler function for clock timeouts.
     *
     * @param   arg - event type
     *
     * @return  none
     */
    static void LED_Clock_Handler(UArg arg)
    {
      // Store the event.
      //events |= arg;
    
      // Wake up the application.
      Semaphore_post(hSem);
    }
    
    
    
    /*
     * @brief   Handle application messages
     *
     *          These are messages not from the BLE stack, but from the
     *          application itself.
     *
     *          For example, in a Software Interrupt (Swi) it is not possible to
     *          call any BLE APIs, so instead the Swi function must send a message
     *          to the application Task for processing in Task context.
     *
     * @param   pMsg  Pointer to the message of type app_msg_t.
     *
     * @return  None.
     */
    static void user_processApplicationMessage(app_msg_t *pMsg)
    {
      char_data_t *pCharData = (char_data_t *)pMsg->pdu;
    
      switch (pMsg->type)
      {
        case APP_MSG_SERVICE_WRITE: /* Message about received value write */
          /* Call different handler per service */
          /*switch(pCharData->svcUUID) {
            case LED_SERVICE_SERV_UUID:
              user_LedService_ValueChangeHandler(pCharData);
              break;
            case DATA_SERVICE_SERV_UUID:
              user_DataService_ValueChangeHandler(pCharData);
              break;
    
    
          } */
          break;
    
        case APP_MSG_SERVICE_CFG: /* Message about received CCCD write */
          /* Call different handler per service */
          /*switch(pCharData->svcUUID) {
            case BUTTON_SERVICE_SERV_UUID:
              user_ButtonService_CfgChangeHandler(pCharData);
              break;
            case DATA_SERVICE_SERV_UUID:
              user_DataService_CfgChangeHandler(pCharData);
              break;
    
          } */
          break;
    
        case APP_MSG_UPDATE_CHARVAL: /* Message from ourselves to send  */
          // user_updateCharVal(pCharData);
          break;
    
        case APP_MSG_GAP_STATE_CHANGE: /* Message that GAP state changed  */
          user_processGapStateChangeEvt( *(gaprole_States_t *)pMsg->pdu );
          break;
    
        case APP_MSG_SEND_PASSCODE: /* Message about pairing PIN request */
          {
            passcode_req_t *pReq = (passcode_req_t *)pMsg->pdu;
            Log_info2("BondMgr Requested passcode. We are %s passcode %06d",
                      (IArg)(pReq->uiInputs?"Sending":"Displaying"),
                      DEFAULT_PASSCODE);
            // Send passcode response.
            GAPBondMgr_PasscodeRsp(pReq->connHandle, SUCCESS, DEFAULT_PASSCODE);
          }
          break;
    
        case APP_MSG_BUTTON_DEBOUNCED: /* Message from swi about pin change */
         /* {
            button_state_t *pButtonState = (button_state_t *)pMsg->pdu;
            user_handleButtonPress(pButtonState);
          } */
          break;
      }
    }
    
    /*
     * @brief   Process a pending GAP Role state change event.
     *
     * @param   newState - new state
     *
     * @return  None.
     */
    static void user_processGapStateChangeEvt(gaprole_States_t newState)
    {
      switch ( newState )
      {
        case GAPROLE_STARTED:
          {
            uint8_t ownAddress[B_ADDR_LEN];
            uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];
    
            GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
    
            // use 6 bytes of device address for 8 bytes of system ID value
            systemId[0] = ownAddress[0];
            systemId[1] = ownAddress[1];
            systemId[2] = ownAddress[2];
    
            // set middle bytes to zero
            systemId[4] = 0x00;
            systemId[3] = 0x00;
    
            // shift three bytes up
            systemId[7] = ownAddress[5];
            systemId[6] = ownAddress[4];
            systemId[5] = ownAddress[3];
    
            DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
    
            // Display device address
            char *cstr_ownAddress = Util_convertBdAddr2Str(ownAddress);
            Log_info1("GAP is started. Our address: \x1b[32m%s\x1b[0m", (IArg)cstr_ownAddress);
          }
          break;
    
        case GAPROLE_ADVERTISING:
          Log_info0("Advertising");
          break;
    
        case GAPROLE_CONNECTED:
          {
            uint8_t peerAddress[B_ADDR_LEN];
    
            GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress);
    
            char *cstr_peerAddress = Util_convertBdAddr2Str(peerAddress);
            Log_info1("Connected. Peer address: \x1b[32m%s\x1b[0m", (IArg)cstr_peerAddress);
           }
          break;
    
        case GAPROLE_CONNECTED_ADV:
          Log_info0("Connected and advertising");
          break;
    
        case GAPROLE_WAITING:
          Log_info0("Disconnected / Idle");
          break;
    
        case GAPROLE_WAITING_AFTER_TIMEOUT:
          Log_info0("Connection timed out");
          break;
    
        case GAPROLE_ERROR:
          Log_info0("Error");
          break;
    
        default:
          break;
      }
    }
    
    /******************************************************************************
     *****************************************************************************
     *
     *  Handlers of direct system callbacks.
     *
     *  Typically enqueue the information or request as a message for the
     *  application Task for handling.
     *
     ****************************************************************************
     *****************************************************************************/
    
    /*
     *  Callbacks from the Stack Task context (GAP or Service changes)
     *****************************************************************************/
    
    /**
     * Callback from GAP Role indicating a role state change.
     */
    static void user_gapStateChangeCB(gaprole_States_t newState)
    {
      Log_info1("(CB) GAP State change: %d.", (IArg)newState);
      user_enqueueRawAppMsg( APP_MSG_GAP_STATE_CHANGE, (uint8_t *)&newState, sizeof(newState) );
    }
    
    /*
     * @brief   Passcode callback.
     *
     * @param   connHandle - connection handle
     * @param   uiInputs   - input passcode?
     * @param   uiOutputs  - display passcode?
     * @param   numComparison - numeric comparison value
     *
     * @return  none
     */
    static void user_gapBondMgr_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
                                           uint8_t uiInputs, uint8_t uiOutputs, uint32 numComparison)
    {
      passcode_req_t req =
      {
        .connHandle = connHandle,
        .uiInputs = uiInputs,
        .uiOutputs = uiOutputs,
        .numComparison = numComparison
      };
    
      // Defer handling of the passcode request to the application, in case
      // user input is required, and because a BLE API must be used from Task.
      user_enqueueRawAppMsg(APP_MSG_SEND_PASSCODE, (uint8_t *)&req, sizeof(req));
    }
    
    /*
     * @brief   Pairing state callback.
     *
     * @param   connHandle - connection handle
     * @param   state      - pairing state
     * @param   status     - pairing status
     *
     * @return  none
     */
    static void user_gapBondMgr_pairStateCB(uint16_t connHandle, uint8_t state,
                                            uint8_t status)
    {
      if (state == GAPBOND_PAIRING_STATE_STARTED)
      {
        Log_info0("Pairing started");
      }
      else if (state == GAPBOND_PAIRING_STATE_COMPLETE)
      {
        if (status == SUCCESS)
        {
          Log_info0("Pairing completed successfully.");
        }
        else
        {
          Log_error1("Pairing failed. Error: %02x", status);
        }
      }
      else if (state == GAPBOND_PAIRING_STATE_BONDED)
      {
        if (status == SUCCESS)
        {
         Log_info0("Re-established pairing from stored bond info.");
        }
      }
    }
    
    /**
     * Callback handler for characteristic value changes in services.
     */
    static void user_service_ValueChangeCB( uint16_t connHandle, uint16_t svcUuid,
                                            uint8_t paramID, uint8_t *pValue,
                                            uint16_t len )
    {
      // See the service header file to compare paramID with characteristic.
      Log_info2("(CB) Characteristic value change: svc(0x%04x) paramID(%d). "
                "Sending msg to app.", (IArg)svcUuid, (IArg)paramID);
      user_enqueueCharDataMsg(APP_MSG_SERVICE_WRITE, connHandle, svcUuid, paramID,
                              pValue, len);
    }
    
    /**
     * Callback handler for characteristic configuration changes in services.
     */
    static void user_service_CfgChangeCB( uint16_t connHandle, uint16_t svcUuid,
                                          uint8_t paramID, uint8_t *pValue,
                                          uint16_t len )
    {
      Log_info2("(CB) Char config change: svc(0x%04x) paramID(%d). "
                "Sending msg to app.", (IArg)svcUuid, (IArg)paramID);
      user_enqueueCharDataMsg(APP_MSG_SERVICE_CFG, connHandle, svcUuid,
                              paramID, pValue, len);
    }
    
    /******************************************************************************
     *****************************************************************************
     *
     *  Utility functions
     *
     ****************************************************************************
     *****************************************************************************/
    
    /*
     * @brief  Generic message constructor for characteristic data.
     *
     *         Sends a message to the application for handling in Task context where
     *         the message payload is a char_data_t struct.
     *
     *         From service callbacks the appMsgType is APP_MSG_SERVICE_WRITE or
     *         APP_MSG_SERVICE_CFG, and functions running in another context than
     *         the Task itself, can set the type to APP_MSG_UPDATE_CHARVAL to
     *         make the user Task loop invoke user_updateCharVal function for them.
     *
     * @param  appMsgType    Enumerated type of message being sent.
     * @param  connHandle    GAP Connection handle of the relevant connection
     * @param  serviceUUID   16-bit part of the relevant service UUID
     * @param  paramID       Index of the characteristic in the service
     * @oaram  *pValue       Pointer to characteristic value
     * @param  len           Length of characteristic data
     */
    static void user_enqueueCharDataMsg( app_msg_types_t appMsgType,
                                         uint16_t connHandle,
                                         uint16_t serviceUUID, uint8_t paramID,
                                         uint8_t *pValue, uint16_t len )
    {
      // Called in Stack's Task context, so can't do processing here.
      // Send message to application message queue about received data.
      uint16_t readLen = len; // How much data was written to the attribute
    
      // Allocate memory for the message.
      // Note: The pCharData message doesn't have to contain the data itself, as
      //       that's stored in a variable in the service implementation.
      //
      //       However, to prevent data loss if a new value is received before the
      //       service's container is read out via the GetParameter API is called,
      //       we copy the characteristic's data now.
      app_msg_t *pMsg = ICall_malloc( sizeof(app_msg_t) + sizeof(char_data_t) +
                                      readLen );
    
      if (pMsg != NULL)
      {
        pMsg->type = appMsgType;
    
        char_data_t *pCharData = (char_data_t *)pMsg->pdu;
        pCharData->svcUUID = serviceUUID; // Use 16-bit part of UUID.
        pCharData->paramID = paramID;
        // Copy data from service now.
        memcpy(pCharData->data, pValue, readLen);
        // Update pCharData with how much data we received.
        pCharData->dataLen = readLen;
        // Enqueue the message using pointer to queue node element.
        Queue_enqueue(hApplicationMsgQ, &pMsg->_elem);
        // Let application know there's a message.
        Semaphore_post(sem);
      }
    }
    
    /*
     * @brief  Generic message constructor for application messages.
     *
     *         Sends a message to the application for handling in Task context.
     *
     * @param  appMsgType    Enumerated type of message being sent.
     * @oaram  *pValue       Pointer to characteristic value
     * @param  len           Length of characteristic data
     */
    static void user_enqueueRawAppMsg(app_msg_types_t appMsgType, uint8_t *pData,
                                      uint16_t len)
    {
      // Allocate memory for the message.
      app_msg_t *pMsg = ICall_malloc( sizeof(app_msg_t) + len );
    
      if (pMsg != NULL)
      {
        pMsg->type = appMsgType;
    
        // Copy data into message
        memcpy(pMsg->pdu, pData, len);
    
        // Enqueue the message using pointer to queue node element.
        Queue_enqueue(hApplicationMsgQ, &pMsg->_elem);
        // Let application know there's a message.
        Semaphore_post(sem);
      }
    }
    
    /*
     * @brief   Extract the LOCALNAME from Scan/AdvData
     *
     * @param   data - Pointer to the advertisement or scan response data
     *
     * @return  Pointer to null-terminated string with the adv local name.
     */
    static char *Util_getLocalNameStr(const uint8_t *data) {
      uint8_t nuggetLen = 0;
      uint8_t nuggetType = 0;
      uint8_t advIdx = 0;
    
      static char localNameStr[32] = { 0 };
      memset(localNameStr, 0, sizeof(localNameStr));
    
      for (advIdx = 0; advIdx < 32;) {
        nuggetLen = data[advIdx++];
        nuggetType = data[advIdx];
        if ( (nuggetType == GAP_ADTYPE_LOCAL_NAME_COMPLETE ||
              nuggetType == GAP_ADTYPE_LOCAL_NAME_SHORT) && nuggetLen < 31) {
          memcpy(localNameStr, &data[advIdx + 1], nuggetLen - 1);
          break;
        } else {
          advIdx += nuggetLen;
        }
      }
    
      return localNameStr;
    }
    
    /*********************************************************************
    *********************************************************************/
    

  • I found the solution. The issue is that the AUX ADC was causing the device to enter standby and never return (both compilers work fine 5.2.6 and 16.9.4.LTS). The fix:

    1. added #include <ti/drivers/power/PowerCC26XX.h> to the top of project_zero.c
    2. added Power_setConstraint(PowerCC26XX_SB_DISALLOW); after AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);