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-CC2640R2: Using GAPRole_SetParameter() to change scanRspData and advertData during a connection. Failed in function GAPRole_SetParameter()

Part Number: LAUNCHXL-CC2640R2

Hi everyone,

I am new to cc2640r2. I was working on using UART to configure advertising parameters, actually the data in scanRspData and advertData.

My project is modified from here: https://github.com/ti-simplelink/ble_examples exactly this one: C:\ti\ble_examples-master\examples\rtos\CC2640R2_LAUNCHXL\ble5apps\spp_ble_server

I change adv. data by this procedure:

1.Resolve an order sent from Lighblue on my iPhone and post a event in my cc2640r2 program for which a task is waiting.

2.In that task, I call something like GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(changed_Data), changed_Data); and GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(changed_Data), changed_Data);

Now what I am facing:

I can not go through either of these functions. They just make the task never execute again. And the data will of course make no change.

I feel hard to discover the reason, when failure occurs the program just stop at here when I stop the debugger:

ICall_abort(void)
{
#ifdef HALNODEBUG
#elif  EXT_HAL_ASSERT
  HAL_ASSERT(HAL_ASSERT_CAUSE_ICALL_ABORT);
#else
  {
    volatile uint8_t j=1;
	while(j);
  }
#endif /* EXT_HAL_ASSERT */
  ICALL_HOOK_ABORT_FUNC();
  return(ICALL_ERRNO_SUCCESS);
}

And the error name seems ICALL_ERRNO_INVALID_SERVICE when I step into the last several steps.

This is my main file. It contains the task in the end:

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

 @file  main.c

 @brief main entry of the BLE stack sample application.

 Group: CMCU, SCS
 Target Device: CC2640R2

 ******************************************************************************

 Copyright (c) 2013-2017, Texas Instruments Incorporated
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 *  Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

 *  Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

 *  Neither the name of Texas Instruments Incorporated nor the names of
    its contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 ******************************************************************************
 Release Name: simplelink_cc2640r2_sdk_1_35_00_33
 Release Date: 2017-05-02 17:08:44
 *****************************************************************************/

/*******************************************************************************
 * INCLUDES
 */

#include <xdc/runtime/Error.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/drivers/Power.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>

#include <icall.h>
#include "hal_assert.h"
#include "bcomdef.h"
#include "peripheral.h"
#include "spp_ble_server.h"
#include "inc/sdi_task.h"

/* Header files required to enable instruction fetch cache */
#include <inc/hw_memmap.h>
#include <driverlib/vims.h>

#include "gap.h"

#ifndef USE_DEFAULT_USER_CFG

#include "ble_user_config.h"

// BLE user defined configuration
#ifdef ICALL_JT
icall_userCfg_t user0Cfg = BLE_USER_CFG;
#else  /* ! ICALL_JT */
bleUserCfg_t user0Cfg = BLE_USER_CFG;
#endif /* ICALL_JT */

#endif // USE_DEFAULT_USER_CFG

/*******************************************************************************
 * MACROS
 */

/*******************************************************************************
 * CONSTANTS
 */

/*******************************************************************************
 * TYPEDEFS
 */

/*******************************************************************************
 * LOCAL VARIABLES
 */

/*******************************************************************************
 * GLOBAL VARIABLES
 */

#ifdef CC1350_LAUNCHXL
#ifdef POWER_SAVING
// Power Notify Object for wake-up callbacks
Power_NotifyObj rFSwitchPowerNotifyObj;
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
                                uint32_t *clientArg);
#endif //POWER_SAVING

PIN_State  radCtrlState;
PIN_Config radCtrlCfg[] =
{
  Board_DIO1_RFSW   | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW  | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4GHz path*/
  Board_DIO30_SWPWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Power to the RF Switch */
  PIN_TERMINATE
};
PIN_Handle radCtrlHandle;
#endif //CC1350_LAUNCHXL

/*******************************************************************************
 * EXTERNS
 */

extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);

bStatus_t Change_name(void);
int Check_input(int len);
void User_Service_createTask(void);
void User_taskFxn(UArg a0, UArg a1);
extern uint8 data [20];
bStatus_t result = SUCCESS;
static uint8_t changed_Data[] =
{
 // complete name
 0x0F,   // length of this data
 GAP_ADTYPE_LOCAL_NAME_COMPLETE,
 'A',
 'B',
 'C',
 'S',
 'B',
 'L',
 'E',
 ' ',
 'S',
 'E',
 'R',
 'V',
 'E',
 'R',

 // connection interval range
 0x05,   // length of this data
 GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
 LO_UINT16(16),   // 100ms
 HI_UINT16(16),
 LO_UINT16(16),   // 1s
 HI_UINT16(16),

 // Tx power level
 0x02,   // length of this data
 GAP_ADTYPE_POWER_LEVEL,
 0       // 0dBm
};

Event_Struct usrEvent;
Event_Handle USREvent;
Task_Struct usrTask;
Char User_TaskStack[800];
int task_count = 0;
int count = 0;
volatile int i = 1;
//! \an order comes!
#define ORDER_PROCESS_EVENT             Event_Id_00

/*******************************************************************************
 * @fn          Main
 *
 * @brief       Application Main
 *
 * input parameters
 *
 * @param       None.
 *
 * output parameters
 *
 * @param       None.
 *
 * @return      None.
 */
int main()
{
  /* Register Application callback to trap asserts raised in the Stack */
  RegisterAssertCback(AssertHandler);
  PIN_init(BoardGpioInitTable);

#ifdef CC1350_LAUNCHXL
  // Enable 2.4GHz Radio
  radCtrlHandle = PIN_open(&radCtrlState, radCtrlCfg);

#ifdef POWER_SAVING
  Power_registerNotify(&rFSwitchPowerNotifyObj,
                       PowerCC26XX_ENTERING_STANDBY | PowerCC26XX_AWAKE_STANDBY,
                       (Power_NotifyFxn) rFSwitchNotifyCb, NULL);
#endif //POWER_SAVING
#endif //CC1350_LAUNCHXL

#if defined( USE_FPGA )
  // set RFC mode to support BLE
  // Note: This must be done before the RF Core is released from reset!
  SET_RFC_BLE_MODE(RFC_MODE_BLE);
#endif // USE_FPGA

#ifdef CACHE_AS_RAM
  // retain cache during standby
  Power_setConstraint(PowerCC26XX_SB_VIMS_CACHE_RETAIN);
  Power_setConstraint(PowerCC26XX_NEED_FLASH_IN_IDLE);
#else
  // Enable iCache prefetching
  VIMSConfigure(VIMS_BASE, TRUE, TRUE);
  // Enable cache
  VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
#endif //CACHE_AS_RAM

#if !defined( POWER_SAVING ) || defined( USE_FPGA )
  /* 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 | USE_FPGA

#ifdef ICALL_JT
  /* Update User Configuration of the stack */
  user0Cfg.appServiceInfo->timerTickPeriod = Clock_tickPeriod;
  user0Cfg.appServiceInfo->timerMaxMillisecond  = ICall_getMaxMSecs();
#endif  /* ICALL_JT */
  /* Initialize ICall module */
  ICall_init();

  /* Start tasks of external images - Priority 5 */
  ICall_createRemoteTasks();

  /* Kick off profile - Priority 3 */
  GAPRole_createTask();

  /* SDI UART Example Task - Priority 2 */
  SDITask_createTask();

  SPPBLEServer_createTask();

  User_Service_createTask();

  /* enable interrupts and start SYS/BIOS */
  BIOS_start();

  return 0;
}


/*******************************************************************************
 * @fn          AssertHandler
 *
 * @brief       This is the Application's callback handler for asserts raised
 *              in the stack.  When EXT_HAL_ASSERT is defined in the Stack
 *              project this function will be called when an assert is raised,
 *              and can be used to observe or trap a violation from expected
 *              behavior.
 *
 *              As an example, for Heap allocation failures the Stack will raise
 *              HAL_ASSERT_CAUSE_OUT_OF_MEMORY as the assertCause and
 *              HAL_ASSERT_SUBCAUSE_NONE as the assertSubcause.  An application
 *              developer could trap any malloc failure on the stack by calling
 *              HAL_ASSERT_SPINLOCK under the matching case.
 *
 *              An application developer is encouraged to extend this function
 *              for use by their own application.  To do this, add hal_assert.c
 *              to your project workspace, the path to hal_assert.h (this can
 *              be found on the stack side). Asserts are raised by including
 *              hal_assert.h and using macro HAL_ASSERT(cause) to raise an
 *              assert with argument assertCause.  the assertSubcause may be
 *              optionally set by macro HAL_ASSERT_SET_SUBCAUSE(subCause) prior
 *              to asserting the cause it describes. More information is
 *              available in hal_assert.h.
 *
 * input parameters
 *
 * @param       assertCause    - Assert cause as defined in hal_assert.h.
 * @param       assertSubcause - Optional assert subcause (see hal_assert.h).
 *
 * output parameters
 *
 * @param       None.
 *
 * @return      None.
 */
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
{
  // Open the display if the app has not already done so
#if !defined(Display_DISABLE_ALL)
  if ( !dispHandle )
  {
    dispHandle = Display_open(Display_Type_LCD, NULL);
  }
#endif

  //Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");

  // check the assert cause
  switch (assertCause)
  {
    case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
      //Display_print0(dispHandle, 0, 0, "***ERROR***");
      //Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
      break;

    case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
      // check the subcause
      if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
      {
        //Display_print0(dispHandle, 0, 0, "***ERROR***");
        //Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
      }
      else
      {
        //Display_print0(dispHandle, 0, 0, "***ERROR***");
        //Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
      }
      break;

    case HAL_ASSERT_CAUSE_ICALL_ABORT:
      //Display_print0(dispHandle, 0, 0, "***ERROR***");
      //Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
      HAL_ASSERT_SPINLOCK;
      break;

    case HAL_ASSERT_CAUSE_ICALL_TIMEOUT:
      //Display_print0(dispHandle, 0, 0, "***ERROR***");
      //Display_print0(dispHandle, 2, 0, ">> ICALL TIMEOUT!");
      HAL_ASSERT_SPINLOCK;
      break;

    case HAL_ASSERT_CAUSE_WRONG_API_CALL:
      //Display_print0(dispHandle, 0, 0, "***ERROR***");
      //Display_print0(dispHandle, 2, 0, ">> WRONG API CALL!");
      HAL_ASSERT_SPINLOCK;
      break;

  default:
      //Display_print0(dispHandle, 0, 0, "***ERROR***");
      //Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
      HAL_ASSERT_SPINLOCK;
  }

  return;
}


/*******************************************************************************
 * @fn          smallErrorHook
 *
 * @brief       Error handler to be hooked into TI-RTOS.
 *
 * input parameters
 *
 * @param       eb - Pointer to Error Block.
 *
 * output parameters
 *
 * @param       None.
 *
 * @return      None.
 */
void smallErrorHook(Error_Block *eb)
{
  for (;;);
}

#if defined (CC1350_LAUNCHXL) && defined (POWER_SAVING)
/*******************************************************************************
 * @fn          rFSwitchNotifyCb
 *
 * @brief       Power driver callback to toggle RF switch on Power state
 *              transitions.
 *
 * input parameters
 *
 * @param   eventType - The state change.
 * @param   eventArg  - Not used.
 * @param   clientArg - Not used.
 *
 * @return  Power_NOTIFYDONE to indicate success.
 */
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
                                uint32_t *clientArg)
{
  if (eventType == PowerCC26XX_ENTERING_STANDBY)
  {
    // Power down RF Switch
    PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 0);
  }
  else if (eventType == PowerCC26XX_AWAKE_STANDBY)
  {
    // Power up RF Switch
    PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 1);
  }

  // Notification handled successfully
  return Power_NOTIFYDONE;
}
#endif //CC1350_LAUNCHXL || POWER_SAVING


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

void User_Service_createTask(void)
{
  Task_Params taskParams;
  Event_Params evParams;

  Event_Params_init(&evParams);
  Event_construct(&usrEvent, &evParams);
  USREvent = Event_handle(&usrEvent);

  // Configure task
  Task_Params_init(&taskParams);
  taskParams.stack = User_TaskStack;
  taskParams.stackSize = 800;
  taskParams.priority = 2;

  Task_construct(&usrTask, User_taskFxn, &taskParams, NULL);
}

void User_taskFxn(UArg a0, UArg a1)
{
    for (;;)
    {
        uint32_t events;
        bStatus_t ret = SUCCESS;
        events = Event_pend(USREvent, Event_Id_NONE, ORDER_PROCESS_EVENT, BIOS_WAIT_FOREVER);
        {
            if (events & ORDER_PROCESS_EVENT)
            {
                task_count ++;
                ret = Change_name();
                events = events ^ ORDER_PROCESS_EVENT;
            }

        }
    }
}

// -----------------------------------------------------------------------------
//! \brief      check the configuration order
//!
//! \param[in]  int
//!
//! \return     int
// -----------------------------------------------------------------------------
int Check_input(int len)
{
    int flag = 0;

    if(data [0] == 0xee && data [len - 4] == 0xff && data [len - 3] == 0xfc && data [len - 2] == 0xff && data [len - 1] == 0xff){
        if(data [1] == 0x5A){
            Event_post(USREvent, ORDER_PROCESS_EVENT);
        }
        flag = 1;
        count++;
    }
    else{
        count--;
    }
    return (flag);
}

// -----------------------------------------------------------------------------
//! \brief      change BLE name
//!
//! \param[in]  void
//!
//! \return     bStatus_t
// -----------------------------------------------------------------------------
bStatus_t Change_name(void)
{
    //uint8_t initialAdvertEnable = TRUE;
    //uint8_t initialAdvertDisableable = FALSE;
    //gaprole_States_t gapRole_state;
    bStatus_t ret = SUCCESS;

    //ret = GAPRole_GetParameter(GAPROLE_STATE, &gapRole_state);//check the adv. data. for debug only.
    //ret = GAPRole_GetParameter(GAPROLE_STATE, advertData);//check the adv. data. for debug only.
    //ret = GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertDisableable);
    //ret = GAPRole_GetParameter(GAPROLE_STATE, &gapRole_state);
    //while(gapRole_state == GAPROLE_ADVERTISING){;}//make sure the advertising state is ended

    GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(changed_Data), changed_Data);

    //ret = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(changed_Data), changed_Data);
    //ret = GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);
    //ret = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
    //ret = GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable);


    return (ret);
}

Could you give me some advice on this? It troubles me for several days Thanks!