Watchdog fails to reset EthernetNetif

03 Jun 2012

i have written a code that uses Watchdog to reset Mbed every 30seconds. After 30-60mins, the ethernet interface fails to setup() after WD reset.

If i press reset button, ethernet setup() works. How can that be?

#include "mbed.h"
#include "EthernetNetIf.h"
EthernetNetIf eth;

void dogKick() {
    LPC_WDT->WDFEED = 0xAA;
    LPC_WDT->WDFEED = 0x55;
    printf("dogkick\n");
}
void setDog(float s =30) {
    LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
    uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
    LPC_WDT->WDTC = s * (float)clk;
    LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
    dogKick();
}

int main() {
    printf("\n\nStartup...\n");
    setDog(30);
    wait(1);
    printf("Setting up...\n");
    EthernetErr ethErr = eth.setup(30000);// lets use 30seconds, problem is with default value also
    if (ethErr) {
        printf("Error %d in setup.\n", ethErr);
        return -1;
    }
    printf("Setup OK\n");
    return 0;

}

/media/uploads/eqon/screen_shot_2012-06-03_at_19.12.48.png

Hm, and i have also used a reset on PHY chip on mbed like that

DigitalOut ethrst(P1_28);
int main{
    ethrst=0;//reset active low
    wait(1);
    ethrst=1;
    wait(1);

  //code continues....
}

Seems to work a bit longer.

Ideas?

03 Jun 2012

could it be an ARP or DHCP issue in the LAN?

04 Jun 2012

Like Steve said, your DHCP server has gotten annoyed at being bothered so much by the same client. It's to prevent a "denial of service" situation at the DHCP server.

I'm sure if you just wait 10 minutes it will be fine. You can possibly change a setting on your DHCP server to remove this behavior, or just use a static IP on your mbed.

If the DHCP server is on a PC you have access to, you can confirm this by installing Wireshark on it and watching the exchange of DHCP packets.

06 Jun 2012

Thanks guys, but NO, that's not the case. If i had DHCP or whatever server problem, then how to explain:

  1. If i manually reset Mbed, then everything runs properly again. How could it be, if i am "denied of service"? Watchdog FAILS to reset Mbed, but manual reset works.
  2. Remove ethernet cable, and as following picture shows, EthernetNetIf fails without ethernet cable when Watchdog creates reset every 30sec

Can somebody test the code (top of page) for 60minutes ? With or without ethernet cable.

/media/uploads/eqon/wolan.png

07 Jun 2012

Egon, can you publish your code so that I can make sure that I use the exact same libraries as you? I want to try and reproduce on my mbed.

07 Jun 2012

Egon,

I think the "return" statements in main() may be adding to the confusion. I seem to recall that for the mbed, returning from main can act like an abort() (which cancels all pending usb transfers of buffered text from the printf()'s). Try replacing the "return"s with "while (1) ;"s and see if your terminal messages look more like what you are expecting. This might also be important if (after a while) your DHCP server was trained to respond very quickly. Then the messages you were (previously) seeing could start being aborted before they can be transfered via usb.

There is also some conflict that I see between your watchdog setting of 30 seconds vs the the ethernet timeout of 30 seconds AFTER a 1 second delay. Here again, the watchdog-timeout could prevent any ethernet-timeout message from being sent.

07 Jun 2012

Egon, I have imported your ethnetWatchDog program and am running it now to see if I can repro.

07 Jun 2012

Adam, Thanks,

Fred, while() didn't change things, 2nd thing, as you said, might be terminal-interface problem. i try,

i now suspect mbed-interface chip or serial-usb connection etc. I'll get back to you,

07 Jun 2012

I think it might be the interface chip as well. Changing the program to infinite loop at the end and providing your own mbed_mac_address() function would stop semi-hosting calls being made to the interface chip while you are running this program. I don't think the CPU will handle a watchdog timeout well when the CPU is halted for a semi-host call.

http://mbed.org/forum/electronics/topic/3291/?page=2#comment-16892

extern "C" void mbed_mac_address(char *s) {
    char mac[6];
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xf7;
    mac[3] = 0xf0;
    mac[4] = 0x45;
    mac[5] = 0xbe;
    // Write your own mac address here
    memcpy(s, mac, 6);
}
07 Jun 2012

I left my mbed 1768 running for over 6 hours without the Ethernet plugged in and it never hung.

I will try with the cable plugged in later today when I can relocate the setup to a location which has Ethernet access.

-Adam

07 Jun 2012

Lets all thank Adam for giving us a solution. i have it running for 3hours with terminal ON and without ethernet cable, ill try with ethernet cable also.

Solution

code that uses Watchdog to reset Mbed every 30seconds and brings up Ethernet again and again..

#include "mbed.h"
#include "EthernetNetIf.h"
EthernetNetIf eth;

void dogKick() {
    LPC_WDT->WDFEED = 0xAA;
    LPC_WDT->WDFEED = 0x55;
    printf("dogkick\n");
}
void setDog(float s =30) {
    LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
    uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
    LPC_WDT->WDTC = s * (float)clk;
    LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
    dogKick();
    
}
// extend mbed_mac_address() here 
// so mbed-interface chip connections can be avoided
// eg. this function would stop semi-hosting calls being made to the interface chip while you are running this program
extern "C" void mbed_mac_address(char *s) {
    char mac[6];
    // Write your own mac address here
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xf7;
    mac[3] = 0xf0;
    mac[4] = 0x45;
    mac[5] = 0xbe;
    memcpy(s, mac, 6);
}


DigitalOut led(LED3); //if alive

int main() {

    
    printf("\n\nStartup...\n");
    setDog(30); 
    printf("Setting up...\n");
    EthernetErr ethErr = eth.setup();
    
    // if interface is up, not frozen, continue...
    if (ethErr) {
        printf("Error %d in setup.\n", ethErr);
           led=1;
       while(1){}// not return 0
    }
    printf("Setup OK\n");
    led=1;
    while(1){}// not return 0

}

Hm, but, other solutions? How to get mac address out from mbed-interface-chip and then shut it off ?