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.

CC3100: Getting exceptions in changing the ip address from static to dynamic

Part Number: CC3100
Other Parts Discussed in Thread: , CC3200

Hi All,

I am trying to change the IP address from static to dynamic and vice versa in runtime. All the drivers and wifi has been initialized previously and is working fine. Later at some time, I need to switch from dynamic IP to static IP and again from static to dynamic. This is my function which is performing this-


sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (unsigned char *) &ipV4);
///////////////// getting reset here
I am getting reset here. WHy is it so?

Thanks


bool reconnectWifi(char* ipAddr, char* ipMask) // 
{
    if (strlen(ipAddr) < 7 || strlen(ipMask) < 7)
    {
        return false;
    }

    g_lastWiFiSwitchSecs = Seconds_get();
    sl_WlanDisconnect();
    sl_Stop(800);
    g_lastWiFiSwitchSecs = 0;

    SlNetCfgIpV4Args_t ipV4;
    uint8_t len = sizeof(ipV4);
    uint8_t dhcpIsOn;
    int result, mode, param, response;

      result = sl_Start(NULL, NULL, NULL);

    if (strcmp(ipAddr, "dynamic") == 0)  // already in station mode amde previosuly in normal wifi usage
    {
        /* Set auto connect policy */
        response = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                                    SL_CONNECTION_POLICY(1, 0, 0, 0, 0), NULL,
                                    0);
        if (response < 0)
        {
            System_abort("Failed to set connection policy to auto");
        }

        /* Enable DHCP client */
        param = 1;
        response = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE, 1, 1, &param);
        if (response < 0)
        {
            System_abort("Could not enable DHCP client");
        }

        sl_Stop(1000);  //BIOS_WAIT_FOREVER);
 //       sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (unsigned char *) &ipV4);
    }
    else
    {
        //Set static ip adress
        char lAddr[50] = { 0 };
        strcpy(lAddr, ipAddr);
        char* indxSt = lAddr;
        char* indx = strchr(indxSt, '.');
        indx[0] = 0;
        int ip1 = strtol(indxSt, (char **) NULL, 10);
        indxSt = indx + 1;
        indx = strchr(indxSt, '.');
        indx[0] = 0;
        int ip2 = strtol(indxSt, (char **) NULL, 10);
        indxSt = indx + 1;
        indx = strchr(indxSt, '.');
        indx[0] = 0;
        int ip3 = strtol(indxSt, (char **) NULL, 10);
        indxSt = indx + 1;
        int ip4 = strtol(indxSt, (char **) NULL, 10);
        //Mask
        strcpy(lAddr, ipMask);
        indxSt = lAddr;
        indx = strchr(indxSt, '.');
        indx[0] = 0;
        int im1 = strtol(indxSt, (char **) NULL, 10);
        indxSt = indx + 1;
        indx = strchr(indxSt, '.');
        indx[0] = 0;
        int im2 = strtol(indxSt, (char **) NULL, 10);
        indxSt = indx + 1;
        indx = strchr(indxSt, '.');
        indx[0] = 0;
        int im3 = strtol(indxSt, (char **) NULL, 10);
        indxSt = indx + 1;
        int im4 = strtol(indxSt, (char **) NULL, 10);
        ipV4.ipV4 = (_u32) SL_IPV4_VAL(ip1, ip2, ip3, ip4);   // _u32 IP address
        ipV4.ipV4Mask = (_u32) SL_IPV4_VAL(im1, im2, im3, im4); // _u32 Subnet mask for this STA/P2P
        //ipV4.ipV4Gateway   = (_u32)SL_IPV4_VAL(192,168,2,1);             // _u32 Default gateway address
        //ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(192,168,2,1);             // _u32 DNS server address

        //sl_NetCfgGet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE, &dhcpIsOn, &len, (unsigned char *)&ipV4);
        long lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,
                                    IPCONFIG_MODE_ENABLE_IPV4,
                                    sizeof(SlNetCfgIpV4Args_t), (_u8 *) &ipV4);
        sl_Stop(200);
        sl_Start(NULL, NULL, NULL);
    }
    unsigned int TimeOutTime =
            Clock_getTicks() + WIFI_SCAN_TIMEOUT * ClockTicks_per_ms;
    /*
     * Wait for SimpleLink to connect to an AP. If connecting to the AP for
     * the first time, press Board_BUTTON0 to start SmartConfig.
     */
    int count = 0;
    while (((g_deviceConnected != true) || (g_ipAcquired != true))
            && g_wifiMaxScan)
    {
        /*
         *  This could be done with GPIO interrupts, but for simplicity polling
         *  is used to check the button.
         */
        if (++count % 5000000 == 0)
        {
            logIntInt("Count(%d):deviceConnected %d", __FUNCTION__, count,
                      g_deviceConnected);
        }

        if (Clock_getTicks() > TimeOutTime)
        {
            break;
        }
    }

    if (g_ipAcquired != true)
    {
        logg("***ERROR*** - unable to acquire wifi IP - timeout", __FUNCTION__);
        buzzerSet(true, 2000, 0xf0f0, false);
        return false;
    }
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (unsigned char *) &ipV4); ///////////////// getting reset here

    /* Print IP address */
    char ipAddrStr[20] = { 0 };
    sprintf(ipAddrStr, "%d.%d.%d.%d", SL_IPV4_BYTE(ipV4.ipV4, 3),
            SL_IPV4_BYTE(ipV4.ipV4, 2), SL_IPV4_BYTE(ipV4.ipV4, 1),
            SL_IPV4_BYTE(ipV4.ipV4, 0));
    logStr("reconnect successful - IP address %s", "", ipAddrStr);
    return true;
}


  • Hi Akhilesh,

    What exactly is getting reset? The CC3100?

    What do you see that is indicating a reset is happening?

    Thanks,
    Ben M

  • Hi Ben,

    I see this 

    Error:E_hardFault: FORCED

    After this, the device resets. It happens only when I am switching to dynamic IP. For static, it works well. Am I doing right? Bcz at some point, I got the same error sometimes in sl_stop(800).

  • Hi Akhilesh,

    That appears to be a hard fault on the host side and not an error from our driver. I assume it is an issue with an illegal memory access or potentially a stack overflow.

    Can you confirm that calling the netcfgget API in a simplified (or test) application works as expected? 

    Thanks,

    Ben M

  • Hi Ben M,

    Something happening inside c3100. This code was working after I did something. But, in the production, I am getting the reset at sl_stop() that too once in a day ( that will be around 1 in 100 times). The code does not go into abort(). It resets the whole microcontroller. 

    I am not able to recreate the error as it is happening in one of our sites that too at very less frequency. But if it comes to do something, I am able to make this reset by calling sl_stop() 2 times in a row. When I am calling sl_stop 2 times, at the second call, it fails and resets. When I did step-in, I found that it is resting at this API call inside sl_stop() -   ret_status = Semaphore_pend((Semaphore_Handle) *pLockObj, Timeout); inside osi_tirtos.c

    Do you have an idea why is this happening?

    Thanks

  • Hi Akhilesh,

    The CC3100 can't reset the MCU. By "reset", do you mean the MCU is triggering a watchdog reset? 
    If so, does that mean that the system is just stuck waiting inside the SimpleLink Host driver in the sl_Stop() command and because it is blocked there, the MCU is resetting?

    Also, why do you call sl_Stop() two times in a row? This shouldn't do anything more than a single call to sl_Stop().

    Best,

    Ben M

  • Hi Ben,

    I am trying to recreate the issue which is happening at one of our site. While switching the IP address from static to IP, sl_stop() dies. It means no reset and it stays there in some hard loop. We can't debug that as it is happening in 1 or 2 times in 2 days. 

    To try that, I put 2 sl_stops but it resets, it means it is not the same issue that is happening at the site. 

    Can you explain to me when sl_stop sticks and where it may stick? Further, there is no coming out from that stuck state. We have to restart the power supply of the device. 

    Thanks

  • Hi Akhilesh,

    What host driver version are you using? It should appear as a define (SL_DRIVER_VERSION) in the simplelink.h header file.

    When you call sl_Stop() in your application and in your test case to try to simulate the issue, are you always using a timeout?

    The sl_Stop() call should only "wait" at certain points if a timeout is being used. That's because without a timeout, it simply deasserts the enable line (nHIB or nReset). With a timeout, it actually sends a command to the NWP to tell the device to safely shut down to allow time for ongoing processes to complete.

    I don't think sl_Stop() should ever get stuck though IF the sl_GetTimestamp function has been implemented (enabling timeouts in case of error during the execution of the protocol to the CC3100) and the OS adaptation is done correctly (enabling timeouts on RTOS objects).

    Best Regards,

    Ben M

  • Hi Ben,

    The SL_DRIVER_VERSION   is "1.0.0.10". 

    Benjamin Moore said:

    When you call sl_Stop() in your application and in your test case to try to simulate the issue, are you always using a timeout?

    Yes. I always try to put different timeouts. At sites (productions), we have used timeout too, more than 300ms. 

    Benjamin Moore said:

    I don't think sl_Stop() should ever get stuck though IF the sl_GetTimestamp function has been implemented (enabling timeouts in case of error during the execution of the protocol to the CC3100) and the OS adaptation is done correctly (enabling timeouts on RTOS objects).

    Can you explain sl_GetTimestamp()? 
    This is the code where it stuck sometimes-

      sl_WlanDisconnect();
      logg("Before sl_stop",__FUNCTION__);
    
      if (sl_Stop(BIOS_WAIT_FOREVER)) { 
          logg("sl_stop() failed, rebootoing","");
          WiFi_close((WiFi_Handle)g_wifiHandle);
          JumpToBootLoader();
       }

    Sometimes, it never passes the line  

    if (sl_Stop(BIOS_WAIT_FOREVER)) 

    It happens once in a 1-2 days.


    Akhilesh

  • Hi Akhilesh,

    Your host driver version is very old and should be updated.

    What do you have BIOS_WAIT_FOREVER defined as? I don't think it makes sense to use this define as a parameter for sl_Stop(). That isn't its intended use. Please refer to the specification of the possible timeout values in the device.h header file. I recommend creating a new define for the value you use to avoid confusion.

    In terms of the sync object timeout, it should be set to wait for up to 65 seconds (driver long timeout) and eventually break if it is stuck in the SL_DRV_SYNC_OBJ_WAIT_TIMEOUT call in sl_Stop (which leads to Semaphore_pend call you were referring to before). This is where the code will wait if it has successfully sent the "stop with timeout" command to the CC3100 device and needs to wait for the asynchronous response (signaled by interrupt) from the device confirming that the stop completed.

    The other location where the code will wait (and where you might also have issues in your production code) is earlier in sl_Stop inside of the _SlDrvCmdOp call. It is responsible for actually sending that "stop with timeout" command to the CC3100. During the command exchange, the host expects to receive a confirmation that the command was received successfully sent back from the device.

    In your host driver version, there are multiple spots in the code responsible for interpreting that response where the device uses a while loop without a timeout...meaning it could wait forever if the data on the host interface is corrupted and the expected data is never seen. In the latest host driver versions, the host driver adds a timestamp function to the porting layer to enable the host to timeout and recover more gracefully if that scenario ever happens.

    I recommend you take a look at the latest host driver version and try updating your code. See CC3100 SDK download here:

    http://www.ti.com/tool/CC3100SDK

    Best Regards,

    Ben M

     

  • Thanks for all these Ben. I'll look into it thoroughly and will come back at you. I need to understand what all has been said by you. Meanwhile, can you tell me if I am updating the sdk to latest one, will I have to change the API calls too? I mean - are the APIs the same as it were before or there are some changes? 

    BIOS_WAIT_FOREVER is defined as 0xFFFF. It means that it will wait until the operation is over.

    Thanks for Help. 

    Regards

    Akhilesh

  • Hi Ben,

    This driver comes along with TI RTOS and I am not able to update it to the latest one. 

    I discussed it one of the persons. https://e2e.ti.com/support/microcontrollers/other/f/908/p/898804/3323101#3323101

    Please have a look and suggest me something.

    Thanks

  • Hi Akhilesh,

    We work to maintain backwards compatibility with the application layer when updating the host driver so I don't believe there are API changes you will have to worry about. 

    Even though this isn't a host driver that we officially support in the Tiva C TI-RTOS distribution, I still recommend you update the host driver in your application based on our CC3100 SDK releases. This will have to be handled on your side by changing the source files with the new versions located at CC3100SDK_x.x.0\cc3100-sdk\simplelink in our latest SDK version.

    This is the recommended approach because the host driver module itself is tested as a whole during the CC3100/CC3200 SDK releases and we can't guarantee things will work if you try to only pull some of the changes into your older driver version.

    Best Regards,

    Ben M

  • Hi Ben,

    I tried to update the host driver from the TI RTOS. 

    Steps-

    I went into this directory

    C:\ti\tirtos_tivac_2_16_01_14\products\tidrivers_tivac_2_16_01_13\packages\ti\mw\wifi\cc3x00\simplelink

    I replaced the include and source folders from the latest cc3100 1.3 sdk. 

    Then I tried to rebuild the ti rtos but getting the following error so many times for each .c files.

    gmake[1]: *** [package/lib/lib/cc3x00_host_driver/./simplelink/source/flowcont.oem4f] Error 1
    detected in the compilation of "simplelink/source/wlan.c".
    Compilation terminated.

    I am attaching my ti rtos build logs also. 

    ThankslogsTIRTOS.txt

  • Hi Akhi,

    I'll take a look and see if I can provide some suggestion for resolving the build error. I'll plan to get back to you by Friday on this.

    Thanks,
    Ben M

  • Thanks Ben. I'll be trying if I can solve it by myself too. 

  • Hi Ben,

    I am able to compile it properly. But now I am getting the errors while running the device. I am not even able to set my device into station mode. I am assuming there is no API change and that's why I have not even made a single change in my source code. 

    I am using cc3100 sdk1.3 now. 

    When I call  mode = sl_Start(0, 0, 0);

    I am getting mode =1, which is ROLE_UNKNOWN   =   1. 

    Why I am getting this error?

    Thanks

    AKhilesh

  • Hi Akhilesh,

    I wonder if you are seeing some issue due to the updates in the timeout detection mechanisms. Please refer to the SDK release notes in the CC3100 SDK v1.3 and note the migration information at the bottom. Please also refer to the release notes dedicated to the host driver.

    http://software-dl.ti.com/ecs/CC3100SDK/1_3_0/exports/cc3100-sdk_1_3_0_release_notes.html

    Best Regards,

    Ben M

  • Hi Ben,

    I am stuck at some other stuff. I'll try that and will get back.

    Thanks