Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

ToniA

Member Since 05 Apr 2012
Offline Last Active Dec 23 2015 03:06 PM
-----

#47334 Hardware watchdog on Netduino Plus

Posted by ToniA on 18 March 2013 - 04:48 PM

OK, here's my new 1-wire + watchdog firmware for Netduino Plus, based on official 4.2.0.1, with CW2's 1-wire, compiled with RVDS 4.1.

 

Flashing instructions:


    [*]Reset the NetduinoPlus by connecting 3.3V to the golden square
    [*]Disconnect and reconnect the USB
    [*]Install the TinyBooterDecompressor.bin with SAM-BA
    [*]Disconnect the USB cable and reconnect it while PRESSING AND HOLDING THE ONBOARD BUTTON until the onboard LED blinks quickly
    [*]Deploy the firmware using MFDeploy
    [*]Disconnect and reconnect the USB AGAIN while PRESSING AND HOLDING THE ONBOARD BUTTON until the onboard LED blinks quickly
    [*]Set the network configuration with MFDeploy
    [*]Disconnect and reconnect the USB (don't press the button), and you're done
    [/list]

    The Tinybooter has three modes:

    • Onboard button is not touched -> boot up with watchdog enabled
    • Press the onboard button while connecting the USB -> release the button after the LED turns off but before it starts blinking -> boot up with watchdog disabled -> can use MFDeploy to deploy large applications
    • Press and hold the onboard button while connecting the USB until the onboard LED first turns off and then blinks -> boots to TinyBooter for firmware upload and for setting the network configuration

    The watchdog also has three modes on the application

    • 'Watchdog.enabled' is not set in the program -> watchdog is active and is automatically fed by the CLR
    • 'Watchdog.enabled = false' -> watchdog is explicitly disabled -> same functionality as in the stock firmware
    • 'Watchdog.enabled = true' -> watchdog is explicitly enabled and cannot be disabled -> the watchdog must be fed by the application by calling 'Watchdog.enabled = true' periodically. If this is not done, or if the application crashes, a watchdog reset will happen

    A sample application

    • Please note that the watchdog is not active when connected to the debugger -> stop debugging and reconnect the USB
    • To verify the functionality, comment out the 'Watchdog.enabled' row in FeedWatchdog and see the board doing a reset after a short while
    using System;using System.Net;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace WatchdogDemo{    public class Program    {        static void FeedWatchdog(object o)        {            // Each time the watchdog is enabled, it's also fed            // This is a bit of a workaround, but at least it didn't            // require any interface changes            Watchdog.Enabled = true;        }        public static void Main()        {            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);            // When the watchdog is enabled, it also must be fed from the managed app            Watchdog.Enabled = true;            Timer WatchdogTimer = new Timer(new TimerCallback(FeedWatchdog), null, 1000, 1000);            while (true)            {                Thread.Sleep(50);                led.Write(!led.Read());            }        }    }}

    The firmware source code is here: https://github.com/T...tduino-watchdog

    Attached Files




#46807 Hardware watchdog on Netduino Plus

Posted by ToniA on 07 March 2013 - 06:15 AM

Gavin, the problem you are seeing is about the boot loader, and yes, only the TinyBooterDecompressor.bin from this build will work with the watchdog. You absolutely have to keep the onboard button held down when you connect the USB cable. You will see that the onboard led will light up for about a second, and then turns off. Now you can deploy the firmware with MFDeploy.

 

The reason for all this is that the watchdog control register on the AT91SAM7X512 microcontroller is a write-once register, i.e. the watchdog behaviour can only be set once. By default the watchdog is ON, and on your application you can turn it off if you like ('Watchdog.Enabled = false;') or prevent the watchdog from being turned off ('Watchdog.Enabled = true;').

 

The stock bootloader will turn the watchdog off, and therefore it cannot be turned on again (the write-once thing). So I needed to modify the bootloader to not touch the watchdog control register. The next problem is on the firmware deployment, as that will not work if the watchdog is on. This is the reason why you need to press the onboard switch, as that signals the boot loader to turn off the watchdog and wait for firmware deployment.

 

So, once more:

  • Reset the board by connecting 3.3V to the golden square
  • Unplug and reconnect the USB cable
  • Flash the TinyBooterDecompressor.bin with SAM-BA
  • Unplug the USB
  • Reconnect the USB while pressing the onboard switch until the onboard LED turns off
  • Deploy the firmware with MFDeploy

All the firmware changes are in this commit:

https://github.com/T...de7da226e47c83a

 

Let me know if there's anything you'd like to change, Github pull requests are also welcome. So far my changes only support the Netduino Plus 1, as I don't own a Netduino 1. I compiled the firmware with RVDS 3.1, using these commands:

call setenv_rvds.cmd 3.1msbuild solutionsnetduinoplusdotnetmf.proj /p:flavor=release;tcp_ip_stack=lwip /m:2



#46768 Hardware watchdog on Netduino Plus

Posted by ToniA on 06 March 2013 - 04:29 PM

A bit more progress, I got CW2's 1-wire-enabled 4.2.0.1 firmware for NetduinoPlus compiled with the watchdog support, using RVDS 3.1.

 

Flashing procedure:

* Flash the tinybootdecompressor first using SAM-BA

* Reconnect the USB while pressing the onboard switch at the same time -> the onboard led should turn off

* Deploy the firmware using MFDeploy

 

The source code is in here: https://github.com/ToniA/netduino




#40166 Hardware watchdog on Netduino Plus

Posted by ToniA on 25 November 2012 - 03:20 PM

A few weeks ago I asked about source access and firmware compilation. My aim was to enable Netduino's hardware watchdog.

Today I finally got it working, using Netduino Plus firmware 4.1.0.6 with the Microsoft porting kit 4.1, compiling with RVDS 3.1.

I have attached the binaries and the source changes on top of the 4.1.0.6 source.

Instructions:
  • Install the TinyBooterDecompressor.bin with SAM-BA
  • Disconnect ND+ and reconnect while PRESSING THE ONBOARD BUTTON at the same time -> the onboard led should turn off (to signal that the watchdog has been turned off for this bootup)
  • Deploy the firmware images using MFDeploy
Note that the AT91 watchdog behavior can be set only once. This is why the TinyBooter cannot disable it at startup, as it couldn't be re-enabled later in your application. Also in your application the watchdog can be either enabled or disabled, the behavior cannot be changed afterwards. The watchdog timeout has been set to the maximum value, i.e. approximately 16 seconds.

To prove the watchdog works, I added a way to cause the soffware to get stuck. That happens now if you query the value of Watchdog.Timeout. Here's a sample program to prove this works. Note that the watchdog reset only works when the debugger is not connected, i.e. you need to stop debugging in Visual Studio to see the watchdog reset restarting the program:


using System;
using System.Net;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace NetduinoPlusApplication1
{
	public class Program
	{
    	public static void Main()
    	{
        	int i = 0;
        	int delay = 250;
        	OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

        	Watchdog.Enabled = true;
//      	Watchdog.Enabled = false;   // If the watchdog is disabled, the software will just get stuck

        	while (true)
        	{
            	Debug.Print("Round " + i++);
            	Debug.Print("Watchdog enabled: " + Watchdog.Enabled.ToString());
          	
            	led.Write(true);

            	Thread.Sleep(delay);
            	led.Write(false);
            	Thread.Sleep(delay);

            	// This simulates the case when the software gets stuck
            	if (i > 20)
            	{
                	TimeSpan foo =  Watchdog.Timeout;
            	}
        	}
    	}
	}
}

Attached Files




home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.