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.

CC1352R: BLE Stack calls never complete

Part Number: CC1352R
Other Parts Discussed in Thread: SYSCONFIG

I'm encountering issues dealing with TI BLE Stack in my application. I am porting my application from SDK 3.20 to version 4.40 and of course everything worked perfectly in the 3.20 implementation.

The problem is this: I initialize the ICall stack and create an ICall Task, then I create some application tasks and from one of them I want to initialize the BLE Stack. I register that application task as an ICall dispatcher, then I proceed to call some BLE APIs as shown below. The problem occurs when calling HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME); or GAP_DeviceInit(GAP_PROFILE_PERIPHERAL, selfEntity, addrMode, NULL); The call never return and following the execution step by step I found out that the program seems to be stuck in an infinite loop inside the OSAL task manager, it seems like the call needs a response message from the BLE Stack which never arrives.

Here is the main.c initialization:

static Task_Handle *BLE5taskHandler, *RF868taskHandler;

Error_Block eb;
Error_init(&eb);

RegisterAssertCback(AssertHandler);
Board_init();

// Enable iCache prefetching
VIMSConfigure(VIMS_BASE, TRUE, TRUE);
// Enable cache
VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);

/* Update User Configuration of the stack */
user0Cfg.appServiceInfo->timerTickPeriod = Clock_tickPeriod;
user0Cfg.appServiceInfo->timerMaxMillisecond  = ICall_getMaxMSecs();

/* Initialize ICall module */
ICall_init();

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

Peripherals_createTask();
BLE5taskHandler = ICall_getRemoteTaskHandle(0);
BLE5_createTask();
RF868taskHandler = RF868_createTask();
PeopleCounter_createTask();

/* initialize and open the DMM policy manager */
DMMPolicy_init();
DMMPolicy_Params_init(&dmmPolicyparams);
dmmPolicyparams.numPolicyTableEntries = DMMPolicy_ApplicationPolicySize;
dmmPolicyparams.policyTable = DMMPolicy_ApplicationPolicyTable;
DMMPolicy_open(&dmmPolicyparams);

/* initialize and open the DMM scheduler */
DMMSch_init();
DMMSch_Params_init(&dmmSchParams);
DMMSch_open(&dmmSchParams);

/* register clients with DMM scheduler */
/* Set the stacks in default states */
DMMSch_registerClient(BLE5taskHandler, DMMPolicy_StackRole_BlePeripheral);
DMMPolicy_updateStackState(DMMPolicy_StackRole_BlePeripheral, DMMPOLICY_STACKSTATE_BLEPERIPH_ADV);
DMMSch_registerClient(RF868taskHandler, DMMPolicy_StackRole_WsnNode);
DMMPolicy_updateStackState(DMMPolicy_StackRole_WsnNode, DMMPOLICY_STACKSTATE_CUSTOM_SLEEPING);

BIOS_start();

return 0;



And here is the body of BLE.c, which is the application task I've described before:

// Register the current thread as an ICall dispatcher application so that the application can send and receive messages
ICall_registerApp(&selfEntity, &syncEvent);

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

// Create one-shot clock for internal periodic events.
Util_constructClock(&clkPeriodic, BLE5_clockHandler, BLE_PERIODIC_EVT_PERIOD, 0, false, (UArg)&argPeriodic);

// Set the Device Name characteristic in the GAP GATT Service
GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);

// Configure GAP
{
    uint16_t paramUpdateDecision = DEFAULT_PARAM_UPDATE_REQ_DECISION;

    // Pass all parameter update requests to the app for it to decide
    GAP_SetParamValue(GAP_PARAM_LINK_UPDATE_DECISION, paramUpdateDecision);
}

// Setup the GAP Bond Manager
setBondManagerParameters();

// Initialize GATT attributes
GGS_AddService(GATT_ALL_SERVICES);              // GAP GATT Service
GATTServApp_AddService(GATT_ALL_SERVICES);      // GATT Service
DevInfo_AddService();                           // Device Information Service
MicrologProfile_AddService(GATT_ALL_SERVICES);  // GATT Profile

// Register callback with Microlog GATT Profile
MicrologProfile_RegisterAppCBs(&BLE5_MicrologProfileCBs);

// Start Bond Manager and register callback
VOID GAPBondMgr_Register(&BLE5_BondMgrCBs);

// Register with GAP for HCI/Host messages. This is needed to receive HCI events
GAP_RegisterForMsgs(selfEntity);

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

// Set default values for Data Length Extension
// Extended Data Length Feature is already enabled by default

// Set initial values to maximum, RX is set to max. by default(251 octets, 2120us)
// Some brand smartphone is essentially needing 251/2120, so we set them here.
#define APP_SUGGESTED_PDU_SIZE 251 //default is 27 octets(TX)
#define APP_SUGGESTED_TX_TIME 2120 //default is 328us(TX)

/* This fails*/
HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME);

// Initialize GATT Client
GATT_InitClient();

// Initialize Connection List
BLE5_clearConnListEntry(LINKDB_CONNHANDLE_ALL);

//Initialize GAP layer for Peripheral role and register to receive GAP events
GAP_DeviceInit(GAP_PROFILE_PERIPHERAL, selfEntity, addrMode, NULL);  /* This fails */

// Initialize array to store connection handle and RSSI values
BLE5_initPHYRSSIArray();
  • Hi Lorenzo, 

    In what way does the HCI_LE_WriteSuggestedDefaultDataLenCmd fail?

    Thanks, 
    Elin 

  • Hi Elin,

    It doesn't fail in the sense that I receive an error or the return is wrong... Simply it doens't return. Debugging the code I've found out that the OSAL task manager never give the control back to my application. ICall is waiting a message from the BLE Stack (I guess) which never arrives.

    My application tasks never run after that call. But there is no call to Icall_abort() so I guess there is nothing wrong with the stack configuration...?

    Lorenzo Venturelli

  • Hi Elin,

    I am investigating the problem, and this is what I have found out:

    I tried to disable my BLE application task to test the rest of my application. Now I do not create the BLE application task, so I do not go through the code I have posted above (file BLE.c).

    I have 3 more tasks that are running with no problem, so the SDK migration seems to be affecting only the BLE Stack.

    I one of those tasks manage the internal NV memory and it does so through OSAL Stack. This is not working either. I register this application task to ICall as well but when I call the OSAL NV APIs they fail (this time they do return a value that is not SUCCESS). The functions I use to manage the NV are these:

    // Read the Internal Flash memory through the NVS API interface
    bool intFlashRead(void)
    {
        uint8 status = SUCCESS;
    
        status = osal_snv_read(SNV_ID_APP, sizeof(Parameters), (uint8 *)&parameters);
    
        if (status == SUCCESS)      // Check the operation exit status
        {
            if (ParametersChecksum(VERIFICA_CHECKSUM))
            {
                return(true); // No errors
            }
        }
        return false;
    }
    
    // Write the Internal Flash memory through the NVS API interface
    bool intFlashWrite(void)
    {
        uint8 status = SUCCESS;
    
        ParametersChecksum(CALCOLA_CHECKSUM);
        status = osal_snv_write(SNV_ID_APP, sizeof(Parameters), (uint8 *)&parameters);
        if(status == SUCCESS) // Check the operation exit status
        {
            return(true); // No errors
        }
        else
        {
            return(false); // An error is occurred
        }
    }

  • Hi Lorenzo,

    1) Regarding ICALL: Can you post the screen shot of the call stack when this happens.

    2) Regarding SNV: What value are you using for SNV_ID_APP? We changed the valid range for this from 0x80 etc to 0x100.

  • Hi Marie,

    I have changed the SNV_ID_APP from 0x80 to 0x100 but nothing is changed. In the first image you can see the stack after my call to osal_nv_read.

    Here it is the stack for ICall but I must specify that the application is not stuck in a point (like a while(1)), it is instead juping between some functions related to Icall and Osal. There is a loop in the porcess of "waiting Icall messages".

    For what I can see the loop consists in this:

    1) ICall_fetchMsg gets a NULL msg

    2) osal_run_system wakes up and then sleep

    3) osal_start_system does something

    And repeat

    Here there is osal_nvs stack

    Here there is Icall mess stack

    I don't know if this is normal but the stack looks pretty huge. I do not understand where might I have misconfigured something. Are there configuration directives that are changed in this SDK update?

  • Hi again Marie,

    I could manage to resolve my BLE Stack issues by completely replacing the stack files in my project and cleaning up the import links. I suppose that something in the stack has been moved or renamed... Anyway I took the stack files from one of the provided examples within the new SDK and now everything seems to work.

    I am still stuck with the osal_snv problem. I have tried to perform a simple write -> read operation in an example project (simple_peripherals) but it doesn't work. I am using 0x100 as SNV_ID_APP and I have double checked the NV module settings (defined by Sysconfig).

  • Hi Lorenzo,

    I'm happy to hear you resolved one of the issues.

    Regarding SNV, 

    1) Can you copy-paste your code snippet into your peripheral task and test if it works? If this is the case, your SNV task is not correctly registered with ICALL.

    2) You say you get a non-success return status. Can you give me the exact status and API which returns it?

  • Hi Marie,

    Let me explain how my project is structured, just to clarify: I have several Tasks that are not important for this issue and I have 2 tasks which are registered to ICall. One of them is my BLE app task and the other one is my SNV task. In both of them I call 

    ICall_registerApp
     before anything else and this API returns 
    ICALL_ERRNO_SUCCESS
     in both cases.

    As you have suggested I tried to copy-paste my calls to SNV APIs from the SNV task into the BLE app task but nothing is changed.

    Here there are the APIs I call and what they return:

    osal_snv_read --> NV_OPER_FAILED
    osal_snv_write --> FAILURE

    Just to clarify, the SNV_ID_APP that I use for both calls is BLE_NVID_CUST_START, just to avoid any problem caused by a difference between SDK versions.

    I have also replaced every SDK file related to NV into the Drivers/NV folder with the new ones provided with "Project Zero" from SDK 4.40. The files are: 

    crc.c; crc.h; nvintf.h, nvocmp.c nvocmp.h

  • Hi Lorenzo,

    Here is the full guide for how to add an ICALL enabled stack:

    https://dev.ti.com/tirex/content/simplelink_cc13x2_26x2_sdk_4_40_04_04/docs/ble5stack/ble_user_guide/html/ble-stack-5.x/creating-a-custom-bluetooth-low-energy-application-cc13x2_26x2.html#creating-additional-icall-enabled-tasks

    It looks like you're missing the step where you increase the max number of ICall enabled stacts in SysCfg. 

  • Hi Marie,

    thank you for this feedback. I did increase the max number of ICall Entries from 6 to 7 as well as the number of ICall Tasks from 3 to 4. What I have found out (accidentally to be honest) is that everything works if I increase the number of ICall Tasks to 5. So now my configuration is 7 entries and 5 tasks.

    Thank you again for your support!