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.

CC2640 SimpleBLEobserver, issue in function parameters, unexplainable behavior at function call.

I modified the SimpleBLEObserver_addDeviceInfo() function with two more parameters as I want to store the pEvtData related to each device found.

the below function call works ok. The deviceInfo.dataLen is correctly transmitted to the function.

    case GAP_DEVICE_INFO_EVENT:
      {
        SimpleBLEObserver_addDeviceInfo(pEvent->deviceInfo.addr,
                                        pEvent->deviceInfo.addrType, pEvent->deviceInfo.rssi, pEvent->deviceInfo.dataLen, pEvent->deviceInfo.pEvtData);
      }
      break;

However if I swap the last two parameters like this

    case GAP_DEVICE_INFO_EVENT:
      {
        SimpleBLEObserver_addDeviceInfo(pEvent->deviceInfo.addr,
                                        pEvent->deviceInfo.addrType, pEvent->deviceInfo.rssi, pEvent->deviceInfo.pEvtData, pEvent->deviceInfo.dataLen);
      }
      break;

then the pEvent->deviceInfo.dataLen does not hold the original value, which is 0x1E for 30 char expected in pEvtData.

here the function I am calling

static void SimpleBLEObserver_addDeviceInfo(uint8 *pAddr, uint8 addrType, int8 addrRssi, uint8 addrDataLen, uint8 * addrData ) // $$
{
  uint8 i;
 
  // If result count not at max
  if ( scanRes < DEFAULT_MAX_SCAN_RES )
  {
    // Check if device is already in scan results
    for ( i = 0; i < scanRes; i++ )
    {
      if (memcmp(pAddr, devList[i].addr, B_ADDR_LEN) == 0)
      {
        return;
      }
    }
    
    // Add addr to scan result list
    memcpy(devList[scanRes].addr, pAddr, B_ADDR_LEN );
    devList[scanRes].addrType = addrType;
    devList[scanRes].addrRssi = addrRssi;    // $$ add rssi value to list
    memcpy( devList[scanRes].addrData, addrData, (addrDataLen > ADDR_RAW_DATA_ARRAY_SIZE ? ADDR_RAW_DATA_ARRAY_SIZE : addrDataLen)); // $$ limit buffer len to array size
    // Increment scan result count
    scanRes++;
  }
}

if I swap the last two parameters addrDataLen holds 0x64 instead of 0x1E set at calling time.

Any thoughts ?

  • Hi,

    Have you tried disabling the optimizer for this function?
    Also, for the second call, did you change the function prototype to match the swapped params?

    Best wishes
  • Hi,

    thanks for following.

    Yes, of course I have disabled optimization in general for debug purposes and did proper function prototyping.

    Later I discovered that the stack went down to far and entered the static variable area, which was cured with alter the stack size.

    I have not checked after if the same problem keeps on.

    However, I observe some strange issues in my CCS 6,1 installation anyway, specialty with static module variables, I get the message that they are not referenced and I can not update them from any function. While the reference in a function is not shown as the error 'variable not defined'. When I define them as global, not static, then anything works as expected.

    I haven't checked if the used variable name is already used elsewhere, may must be, as the variables are not shown as undefined, but on the other hand, there is no error given for duplicate declaration, even if I declare them global.

    Debugging is also funny, the step cursor jumps back and forth, it doesn't look like any sense sometimes. I have some API in use with __STATIC_INLINE declared functions and this seems to put debugging upside down.

    May I have Version problems of various tools, may be ?

    So, strange everything, however, I can work using some work around, but would like to know the reasons some times later.

    regards