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.
Photo

Hardware watchdog on Netduino Plus


  • Please log in to reply
35 replies to this topic

#1 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 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


  • Arron Chapman and strent like this

#2 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 25 November 2012 - 03:23 PM

The project I'm aiming for is a piece of home automation, the idea is to read a large number of 1-wire sensors, and send the sensor data to the network. So CW2, I'd appreciate having a copy of your 1-wire firmware sources, so that I could integrate both the 1-wire and watchdog into the same firmware...

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 25 November 2012 - 04:39 PM

So CW2, I'd appreciate having a copy of your 1-wire firmware sources, so that I could integrate both the 1-wire and watchdog into the same firmware...

The source code is included in Netduino_v4.1.1_beta1_CW.NETMF.OneWire-1.0.5.0.zip (attached to the first post of OneWire thread). Also, Secret Labs has announced the upcoming 4.2 firmware will include the native NETMF 1-Wire implementation, so you could integrate the watchdog there, when the official firmware source code is released.

Big thumbs up for the watchdog!

#4 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 26 November 2012 - 06:47 AM

CW2, I couldn't get the OneWire built on top of 4.1.0.6... Seems that you have built on top of 4.1.1, and my base is 4.1.0.6. The question is, where do I find the full 4.1.1 firmware source...

#5 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 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


  • CW2 and OZ8ET like this

#6 Gavin G.

Gavin G.

    Member

  • Members
  • PipPip
  • 11 posts

Posted 06 March 2013 - 08:51 PM

I'm not able to get the firmware deployed to my [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]NetduinoPlus[/color]. Whenever it is deploying the ER_Flash image I get an error. I had to re-flash the boot loader  and firmware from Chris and his team to get my board functioning again.

 

I will try this with one other board that still has 4.1.2 firmware and see how that goes.


Gavin G.

 

"The most important thing is to keep the most important thing the most important thing."

- From the book "Foundation design", by Coduto, Donald P.


#7 Gavin G.

Gavin G.

    Member

  • Members
  • PipPip
  • 11 posts

Posted 06 March 2013 - 08:55 PM

Yea just tried it on my second board and it gave me the same error. it gets about about 1/10 done, and then Error: unable to deploy to device pops up.

 

Anyone else have this happen?

 

I would really like to see how the watchdog functions in this custom firmware so please help


Gavin G.

 

"The most important thing is to keep the most important thing the most important thing."

- From the book "Foundation design", by Coduto, Donald P.


#8 Gavin G.

Gavin G.

    Member

  • Members
  • PipPip
  • 11 posts

Posted 06 March 2013 - 09:04 PM

Nvm I got firmware flashed by using SAM BA to flash the non custom bootloader from SL, and then using MFDeploy to flash the custom firmware ER_FLASH & ER_Config images.

 

 

However, as far as I can tell the example from the first post doesn't work when I build and deploy it. Am I missing something, it will get to 20 led flashes and then hang after that.

 

I would really like to know if this firmware managed to get the watchdog working.


Gavin G.

 

"The most important thing is to keep the most important thing the most important thing."

- From the book "Foundation design", by Coduto, Donald P.


#9 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 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

  • Gavin G. likes this

#10 strent

strent

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 07 March 2013 - 08:36 AM

Just flashed my Netduino Plus with your firmware + CW2's onewire - went without a hitch and the sample code works perfectly

 

Exactly what I was after, thanks!!!

 

Edit: I've found it seems to randomly trigger even when my application is running normally. (I've got a simple app that outputs uptime to an LCD deployed)

 

Edit: It happens around the 8 minute mark



#11 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 07 March 2013 - 01:28 PM

One thing I've been wondering is that the watchdog is fed by the CLR itself, and there could be cases where the managed code application is stuck, but the CLR is still alive and feeding the watchdog. Maybe I should implement a method through which the watchdog could be fed through the managed application, so that if it's really stuck, a reboot would happen.



#12 Gavin G.

Gavin G.

    Member

  • Members
  • PipPip
  • 11 posts

Posted 07 March 2013 - 07:09 PM

Thanks I got things setup on my device, I'm going to spend some time messing with the watchdog and I'll see how everything goes.

 

So far the sample code works, but looks like I still have some hangs when doing socket stuff, but that could be code errors and not hardware related. I'll check in if I find anything.

 

Also a method through which the watchdog could be fed through the managed application, would be nice.


Gavin G.

 

"The most important thing is to keep the most important thing the most important thing."

- From the book "Foundation design", by Coduto, Donald P.


#13 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 08 March 2013 - 09:15 AM

If the watchdog is fed through the managed application, I think it would need to work like this:

  • By default, the CLR would feed the watchdog
  • There would need be a way to set the Watchdog.Behaviour so that the CLR would no longer feed it
  • There would need be a way to feed the watchdog through a managed application, perhaps by adding a new property to the Watchdog class, or by 'misusing' one of the existing properties
  • So in this case, you'd have a timer which would call something which feeds the watchdog on your code


#14 strent

strent

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 10 March 2013 - 01:18 AM

Seems as though SDCard support doesn't work in your firmware build either

 

var fs = new FileStream(file, FileMode.Open)

 

Throws A first chance exception of type 'System.NotSupportedException' occurred in System.IO.dll



#15 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 10 March 2013 - 03:01 PM

Does this piece of code work on the stock 4.2.0.1 firmware?



#16 OZ8ET

OZ8ET

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts
  • LocationHundested, Denmark

Posted 11 March 2013 - 05:03 AM

Please explain!

 

I installed the firmware (thank you ToniA) and my first attempt on an fault (analog-port) NetduinoPlus 1 worked fine.

Next two other boards were upgraded, and they Work with some small sample programs.

Then I took the program that Works on NetduinoPlus 2 (changed reference and using to NetduinoPlus)but whenever I try to deploy, I get the error: "An error has occured: please check your hardware."

 

Is this a memory problem(Ram or Flash)?

How can I see how much memory is available for my application?

How can I see how much memory my application require to deploy?

 

Thanks in advance

Erik

 

Additional information:

When I upgraded the first (faulty) device, I did not installed the TinyBootLoader (by mistake). I did have som problems with upgrading the firmware, but managed to do it at last.

When I upgraded the other devices, I had the same problems, but realised I had to opgrade the TinyBootLoader. After doing that, the firmware upgrade was ok.

Now the first (faulty) device kan accept the application, but the others makes an error.

 

Device Info from the first (faulty) device:

DeviceInfo:

HAL build info: 4.2.0.0, Netduino Plus (v4.2.0.1) by Secret Labs LLC [CW2 mod]

OEM Product codes (vendor, model, SKU): 34, 177, 4097

Serial Numbers (module, system):

00000000000000000000000000000000

0000000000000000

Solution Build Info: 4.2.0.0, Netduino Plus (v4.2.0.1) by Secret Labs LLC [CW2 mod]

AppDomains:

default, id=1

Assemblies:

mscorlib,4.2.0.0

Microsoft.SPOT.Native,4.2.0.0

Microsoft.SPOT.Hardware,4.2.0.0

Microsoft.SPOT.Net,4.2.0.0

System,4.2.0.0

Microsoft.SPOT.Hardware.SerialPort,4.2.0.0

Microsoft.SPOT.IO,4.2.0.0

System.IO,4.2.0.0

Microsoft.SPOT.Hardware.PWM,4.2.0.1

Microsoft.SPOT.Hardware.OneWire,4.2.0.0

SecretLabs.NETMF.Diagnostics,4.2.0.0

SecretLabs.NETMF.Hardware.Netduino,4.2.1.0

Microsoft.SPOT.Graphics,4.2.0.0

SecretLabs.NETMF.IO,4.2.0.0

Easyweb,2.2013.310.1337

SecretLabs.NETMF.Hardware,4.2.0.0

 

Device Info from one of the other (not working) devices:

 

DeviceInfo:

HAL build info: 4.2.0.0, Netduino Plus (v4.2.0.1) by Secret Labs LLC [CW2 mod]

OEM Product codes (vendor, model, SKU): 34, 177, 4097

Serial Numbers (module, system):

00000000000000000000000000000000

0000000000000000

Solution Build Info: 4.2.0.0, Netduino Plus (v4.2.0.1) by Secret Labs LLC [CW2 mod]

AppDomains:

default, id=1

Assemblies:

mscorlib,4.2.0.0

Microsoft.SPOT.Native,4.2.0.0

Microsoft.SPOT.Hardware,4.2.0.0

Microsoft.SPOT.Net,4.2.0.0

System,4.2.0.0

Microsoft.SPOT.Hardware.SerialPort,4.2.0.0

Microsoft.SPOT.IO,4.2.0.0

System.IO,4.2.0.0

Microsoft.SPOT.Hardware.PWM,4.2.0.1

Microsoft.SPOT.Hardware.OneWire,4.2.0.0

SecretLabs.NETMF.Diagnostics,4.2.0.0

SecretLabs.NETMF.Hardware.Netduino,4.2.1.0



#17 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 11 March 2013 - 05:58 AM

Hmm. Seems like the watchdog might need some additional work. The likely explanation is that the watchdog is not fed while the application is deployed, and this causes a watchdog reset during the deployment.

 

Does anybody have any insight on the execution path during the deployment, i.e. if I for example want to disable the watchdog, where should I add that. The firmware deployment already has that code in the TinyBooter (see the function WaitForTinyBooterUpload in https://github.com/T...BooterEntry.cpp)



#18 OZ8ET

OZ8ET

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts
  • LocationHundested, Denmark

Posted 11 March 2013 - 06:24 AM

Thanks ToniA - there is a logic to that. Writing my post, I realised that the difference was the TinyBoot-thing that was not installed in my first attempt and the Watchdog therefore was not enabled. 

I am about to install the original TinyBoot-thing but right now have problem seeing the COM-port in SAM-BA.

This is however another problem that I hopefully will solve soon.

Thanks for quick reply

Erik



#19 OZ8ET

OZ8ET

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts
  • LocationHundested, Denmark

Posted 11 March 2013 - 08:48 AM

Having installed the original Secret Lab TinyBoot-thing for fw 4.2, I could upgrade the Firmware to ToniA's version, and I now have another 3 NetduinoPlus version 1 working with Onewire.

Life is good - thanks to ToniA, 

I look forward to a solution to the Watchdog problem, which will be en enhancement.

Regards

Erik



#20 ToniA

ToniA

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 11 March 2013 - 09:02 AM

The problem is that we'd need to have some way to

  • Signal the bootloader that we are deploying the firmware -> disable the watchdog
  • Signal the CLR that we are deploying an application -> disable the watchdog

... while we just have one button on the board. I was thinking that the bootloader could have 'short' and 'long' press detection, so that in the other case it would wait for the firmware deployment, and on the other case just disable the watchdog and continue the boot-up process.

 

And you probably already figured out that the watchdog is not activated if you use the stock bootloader :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.