Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Reputation Activity

  1. Like
    TrevorH got a reaction from hungtran in Watchdog reset Hangs on WiFiInit()   
    Hi All,
    I have a problem with the watchdog timer reset.
    I am using Energia with a CC3200 on a custom board but the same issue occurs with a Launchpad.
    I have cut down the code to demonstrate the problem it is part of a much larger project which has a process control element and needs a watchdog timer.
    I have cobbled the demo together from all over the place so there are many different coding styles (smells) used - sorry
    It is spread over 2 tabs The full project has 30.
    From my reading, the reset functions are unreliable so TI suggests, test if the system has recovered from a watchdog reset then hibernate the CC3200. Then wake it up shortly after to ensure a clean reset. This seems to work until you connect to a network. I have tried to exit the network connection gracefully but I might have missed a step, my knowledge of the underlying network stuff is not so good.
    The demo code started from the scan network demo that installs with Energia. The watchdog stuff comes from the TI SDK.
    When recovering from the reset the program or processor hangs when you try to run WiFiInit() but not all the time. I have tried different delays in different places to let the Network processor catch up but no success
    This program is set up to continually time out the watchdog so there is no need to tell me that I am not servicing the watchdog.
    It would be great if someone can offer some insight into how to solve this
    Tab named WatchdogTest
    #include <WiFi.h> #include <WiFiClient.h> #include <WiFiServer.h> #include <WiFiUdp.h> #include "driverlib\prcm.h" #define debug 1 #define Buzzer RED_LED // GPIO24 pin 17 #define BEEP 100 unsigned long ulResetCause; // moved to wdt.ino int WiFiDisconnectErr; uint8_t watchdogResetFlag; uint8_t watchdogIntClearFlag; uint32_t g_ulWatchdogCycles=0; uint32_t g_bFeedWatchdog=1; // your network name also called SSID char ssid[33] = "YourSSID"; // your network password char password[65] = "YourPassword"; void setup() { pinMode(Buzzer,OUTPUT); // for the purpposes of this demo the buzzer is redirected to the red LED on the launchpad board digitalWrite(Buzzer, LOW); //sound a chirp on the buzzer digitalWrite(Buzzer, HIGH); delay (BEEP); digitalWrite(Buzzer, LOW); Serial.begin(115200); Serial.println("Ok..."); recoverFromWatchdog(); wdt(); WiFi.init(); Serial.println(WiFi.firmwareVersion()); // Print WiFi MAC address: printMacAddress(); // scan for existing networks: Serial.println("Scanning available networks..."); listNetworks(); // attempt to connect to Wifi network: if (debug)Serial.print("Attempting to connect to Network named: "); // print the network name (SSID); if (debug)Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: WiFi.begin(ssid, password); while ( WiFi.status() != WL_CONNECTED) { // print dots while we wait to connect if (debug)Serial.print("."); delay(300); } if (debug)Serial.println("\nYou're connected to the network"); if (debug)Serial.println("Waiting for an ip address"); while (WiFi.localIP() == INADDR_NONE) { // print dots while we wait for an ip addresss if (debug)Serial.print("."); delay(300); } // you're connected now, so print out the status printWifiStatus(); } void loop() { uint32_t slowClockVal; if (watchdogResetFlag) { watchdogResetFlag =0; if (WiFi._connecting) { WiFiDisconnectErr = WiFi.disconnect(); Serial.println(WiFiDisconnectErr); delay(50); WiFiDisconnectErr = WiFi.disconnect(); Serial.println(WiFiDisconnectErr); delay(50); } } if (watchdogIntClearFlag) { watchdogIntClearFlag =0; Serial.print("Clear WD int "); Serial.println(g_ulWatchdogCycles); Serial.print("Slow Clock Value ....... "); slowClockVal = (uint32_t)PRCMSlowClkCtrGet(); Serial.println(slowClockVal); digitalWrite(Buzzer, HIGH); delay (BEEP); digitalWrite(Buzzer, LOW); } } void printMacAddress() { // the MAC address of your Wifi byte mac[6]; // print your MAC address: WiFi.macAddress(mac); Serial.print("MAC: "); Serial.print(mac[5], HEX); Serial.print(":"); Serial.print(mac[4], HEX); Serial.print(":"); Serial.print(mac[3], HEX); Serial.print(":"); Serial.print(mac[2], HEX); Serial.print(":"); Serial.print(mac[1], HEX); Serial.print(":"); Serial.println(mac[0], HEX); } void listNetworks() { // scan for nearby networks: Serial.println("** Scan Networks **"); int numSsid = WiFi.scanNetworks(); if (numSsid == -1) { Serial.println("Couldn't get a wifi connection"); while (true); } // print the list of networks seen: Serial.print("number of available networks:"); Serial.println(numSsid); // print the network number and name for each network found: for (int thisNet = 0; thisNet < numSsid; thisNet++) { Serial.print(thisNet); Serial.print(") "); Serial.print(WiFi.SSID(thisNet)); Serial.print("\tSignal: "); Serial.print(WiFi.RSSI(thisNet)); Serial.print(" dBm"); Serial.print("\tEncryption: "); printEncryptionType(WiFi.encryptionType(thisNet)); } } void printEncryptionType(int thisType) { // read the encryption type and print out the name: switch (thisType) { case ENC_TYPE_WEP: Serial.println("WEP"); break; case ENC_TYPE_TKIP: Serial.println("WPA"); break; case ENC_TYPE_CCMP: Serial.println("WPA2"); break; case ENC_TYPE_NONE: Serial.println("None"); break; case ENC_TYPE_AUTO: Serial.println("Auto"); break; } } void printWifiStatus(void) { // print the SSID of the network you're attached to: if (debug)Serial.print("Network Name: "); if (debug)Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); if (debug)Serial.print("IP Address: "); if (debug)Serial.println(ip); } Tab named wdt
    #include "driverlib\wdt.h" #include "driverlib\utils.h" #include "driverlib\prcm.h" //unsigned long ulResetCause; void recoverFromWatchdog(void) { // This is here to clean up after a watchdog reset // Get the reset cause // ulResetCause = PRCMSysResetCauseGet(); // // If watchdog triggered reset request hibernate // to clean boot the system // if( ulResetCause == PRCM_WDT_RESET ) { HIBEntrePreamble(); MAP_PRCMOCRRegisterWrite(0,1); MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR); MAP_PRCMHibernateIntervalSet(330); MAP_PRCMHibernateEnter(); } } void wdt(void) // this is the system watchdog { MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); MAP_WatchdogUnlock(WDT_BASE); MAP_WatchdogIntRegister(WDT_BASE,WatchdogIntHandler); MAP_WatchdogReloadSet(WDT_BASE,40000000*5); //35 seconds 40000000 is half the clock frequency 80 MHz /2 MAP_WatchdogEnable(WDT_BASE); } void wdtReset(void) // this is the software reset { MAP_WatchdogUnlock(WDT_BASE); MAP_WatchdogReloadSet(WDT_BASE,40000000 * 2); // 2 seconds give the system time to close network connections } //***************************************************************************** // //! Mandatory Configuration to put the PM into safe state before entering hibernate //! //! \param None //! //! \return None // //***************************************************************************** static inline void HIBEntrePreamble() { HWREG(0x400F70B8) = 1; UtilsDelay(800000/5);//delay(2); HWREG(0x400F70B0) = 1; UtilsDelay(800000/5);//delay(2); HWREG(0x4402E16C) |= 0x2; UtilsDelay(800);//delay(1); HWREG(0x4402F024) &= 0xF7FFFFFF; } //***************************************************************************** // //! The interrupt handler for the watchdog timer //! //! \param None //! //! \return None // //***************************************************************************** void WatchdogIntHandler(void) { // // If we have been told to stop feeding the watchdog, return immediately // without clearing the interrupt. This will cause the system to reset // next time the watchdog interrupt fires. // if(!g_bFeedWatchdog) { return; } // // After 10 interrupts, switch On LED6 to indicate system reset // and don't clear watchdog interrupt which causes system reset // if(g_ulWatchdogCycles >= 3) { // if (client)client.stop(); watchdogResetFlag++; MAP_UtilsDelay(800000); return; } // // Clear the watchdog interrupt. // MAP_WatchdogIntClear(WDT_BASE); watchdogIntClearFlag++; // // Increment our interrupt counter. // g_ulWatchdogCycles++; }
  • Create New...