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

Mono bootloader for Netduino (and sample apps)


  • Please log in to reply
13 replies to this topic

#1 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 February 2011 - 10:26 PM

While we work out MonoDevelop IDE integration, we've created a Netduino C# bootloader which will allow you to manually compile your C# source on Mac/Linux...and then deploy your Netduino app via MicroSD card. I have attached the source to the Netduino Plus bootloader for Mono projects (inspired by community member Fabien's fantastic work in dynamic assembly loading). Be sure to uncomment the appropriate SD mounting command if you are not using a Netduino Plus. I have also attached two sample apps which can be compiled by Mono, processed through the MetaDataProcessor, copied to a MicroSD card, and then run on your Netduino/Netduino Plus/Netduino Mini. Please note that this bootloader loads your main app (single assembly). The bootloader can be easily modified to load dependencies if desired. Huge kudos to Miguel de Icaza, Geoff Norton, Marek Safar and the rest of the Novell Mono team for their hard work and cooperation getting .NET MF compiler support baked into Mono. Chris

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 February 2011 - 10:30 PM

If you'd like to deploy the bootloader on Mac/Linux (instead of compiling from source), grab Alpha 1 of our MFDeploy tool and flash this HEX file onto your Netduino/Netduino Plus/Netduino Mini.

If deploying the bootloader from Mac/Linux, you'll need to use a serial connection from your computer to your Netduino. If using a Netduino or Netduino Plus, use our custom MFDeploy build for Windows to switch your Netduino to serial deployment. Or compile the Netduino firmware from scratch after setting the debug port to COM1/COM2 in platform.h and deploy it to your Netduino using SAM-BA on Linux.

[Bootloader HEX for Netduino Plus is attached; bootloader HEX for Netduino and Netduino Mini coming later today which will require v4.1.1 alpha 6+ firmware]

Chris

Attached Files



#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 February 2011 - 11:19 PM

To manually build your Netduino app on Mac/Linux, you can use the same build procedure used behind the scenes by the .NET Micro Framework SDK on Windows.

The build process has two steps: (1) compile; (2) shrink ("minimize").

To compile your Netduino app, you'll use the mcs.exe compiler (from Visual Studio or from Mono 2.12). The .NET MF compiler support was too new to make it into the upcoming Mono 2.10 release, so for the moment you'll need to install Mono 2.10 and then build the Mono 2.12 compiler from source.

We'll build the MonoBlinky app using Mono in the following example.

Step 1: compile MonoBlinky using Mono's new C# compiler (Mono 2.10 installed to default directory, Mono source in c:\mono)
C:\Downloads\MonoBlinky\> SET NETMF_LIB="C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le"

C:\Downloads\MonoBlinky\> SET NETDUINO_LIB="C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.1\le"

C:\Downloads\MonoBlinky\> "c:\program files (x86)\mono-2.10\bin\mono.exe" 
"c:\mono\mcs\mcs\mcs.exe" /reference:%NETMF_LIB%\Microsoft.SPOT.TinyCore.dll 
/reference:%NETMF_LIB%\Microsoft.SPOT.Native.dll /reference:%NETMF_LIB%\mscorlib.dll 
/reference:%NETMF_LIB%\Microsoft.SPOT.Hardware.dll /reference:%NETDUINO_LIB%\SecretLabs.NETMF.Hardware.dll 
/reference:%NETDUINO_LIB%\SecretLabs.NETMF.Hardware.Netduino.dll /out:MonoNetduinoApp.exe 
/target:exe /nostdlib Program.cs Properties\AssemblyInfo.cs

To compile a DLL, use /target:library and /out:assemblyname.dll instead.

You can also copy all the assemblies to your project's source code folder to avoid the extra path variables.

This will output your app as MonoNetduinoApp.exe, a traditional .NET assembly. Now we'll strip out extraneous data and convert it to the .NET MF "PE" assembly format.

Step 2: compress ("minimize") our app (assembly)
C:\Downloads\MonoBlinky\> SET NETMF_BIN="C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Tools"

C:\Downloads\MonoBlinky\> "%NETMF_BIN%\MetaDataProcessor.exe" -loadHints mscorlib "%NETMF_LIB%\mscorlib.dll" 
-parse MonoNetduinoApp.exe -minimize -endian le -compile MonoNetduinoApp.pe

To run your Mono-compiled app, copy the resulting MonoNetduinoApp.pe file to a MicroSD card and insert it into your Netduino Plus (or use a shield on your Netduino or a MicroSD breakout board with your Netduino Mini). The MonoNetduinoBootloader app on your Netduino will then load the app automatically during powerup/restart.

Chris

#4 jeffd

jeffd

    New Member

  • Members
  • Pip
  • 1 posts

Posted 14 February 2011 - 12:24 AM

Chris-- Thanks for updating us on the continuing work to support the Netduino on Linux/Mac. I'm anxiously awaiting more beginner friendly environment, and appreciate you documenting these incremental baby-steps. jeff

#5 Earthed

Earthed

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationAustralia

Posted 24 August 2011 - 06:49 AM

This looks like a great way to incorporate Firmware Over the Air (FOA) when you add an M2M shield to load the hex file onto the Micro SD card - Thanks

#6 jefe

jefe

    New Member

  • Members
  • Pip
  • 6 posts

Posted 03 September 2011 - 06:50 PM

Chris, Could you expand on using SAM-BA to deploy the bootloader or point me to some other links that describe SAM-BA's usage with the Netduino? I have used SAM-BA before on a SAM9260 device, so I'm familiar with it. But, it requires a board configuration file and a serial port spec. I used Atmel's dev board config file and a USB device (the CDC driver that I linked to ttyUSB0) for the 9260 board. But when I connect the Netduino to USB, I don't see any new USB devices show up, either CDC or direct USB. Once I do find a connection to specify, I expect that I will write the bootloader hex file to address 0x100000.

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 September 2011 - 09:16 PM

Hi jefe, Here's a full set of instructions from the Wiki: http://wiki.netduino....ashx?HL=sam,ba Let me know if you need anything else! Chris

#8 jefe

jefe

    New Member

  • Members
  • Pip
  • 6 posts

Posted 05 September 2011 - 12:26 AM

Hi jefe,

Here's a full set of instructions from the Wiki:
http://wiki.netduino....ashx?HL=sam,ba

Let me know if you need anything else!

Chris


Wow. Thanks, Chris. Perfect! I should have looked harder for this myself. I'll let you know how it works out.

#9 Ryan T

Ryan T

    New Member

  • Members
  • Pip
  • 5 posts

Posted 04 January 2012 - 07:07 PM

Hi Chris, What are the limitations of this method? I can get your two examples running but when I try to load a larger assembly it fails to run (no error is reported, netduino plus is unresponsive, runs when loaded in the traditional manor). I have put all the references that are used in the assembly into the bootloader program (necessary?) with no luck. Perhaps I need to do something differently when using multiple classes (also threading) or the memory foot print is now too large? Any help with this would be appreciated. Thanks again. Ryan Firmware v4.1.1 BETA 1 Traditional Method Total: (11856 RAM - 100832 ROM - 53025 METADATA) .pe file on SDcard (11KB) The debugging target runtime is loading the application assemblies and starting execution. Total: (12120 RAM - 101992 ROM - 53394 METADATA)

#10 Ryan T

Ryan T

    New Member

  • Members
  • Pip
  • 5 posts

Posted 06 January 2012 - 02:52 AM

Update

I've found an unusual behavior when loading assemblies off the SDcard. When executing the following code (flashing LED running with two threads) from the provided MonoNetduinoBootloader it hangs at the line
assembly = Assembly.Load(assemblyData);
in MonoNetduinoBootloader. However, if at this stage the reset button is pressed the assembly is executed as expected.

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

namespace MonoNetduinoApp
{
    public class Program
    {
        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

        public static void Main()
        {
            // write your code here
            Thread flashLedThread = new Thread(flashLed);
            flashLedThread.Start();
            Thread.Sleep(Timeout.Infinite);
        }

        public static void flashLed()
        {
            while (true)
            {
                led.Write(!led.Read());
                Thread.Sleep(250);
            }
        }
    }
}

Also, when attempting to run the following code (using a button interrupt to turn on LED) it hangs the same as above. However, if at this stage the button is pressed the app continues to run but a System.NullReferenceException is thrown and the "Netduino app invalid. Please verify that class name is MonoNetduinoApp and startup method is Main." is printed.

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

namespace MonoNetduinoApp
{
    public class Program
    {
        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

        public static void Main()
        {
            // write your code here
            InterruptPort Button = new InterruptPort(Pins.ONBOARD_SW1,false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            Button.OnInterrupt += new NativeEventHandler(Button_OnInterrupt);
            Thread.Sleep(Timeout.Infinite);
        }

        static void  Button_OnInterrupt(uint data1, uint data2, DateTime time)
        {
                led.Write(data2 == 1);
        }
    }
}

I can get my main assembly running, mentioned in the above post, if I take out the button interrupt and press the reset button on the hang-up, however this is not a practical solution. Can anyone else re-create this problem and perhaps find a solution.

Thanks again

Ryan

P.S. I am not using Mono to compile (just straight Visual Studio, Windows) and I want to use SDcard assemblies for more flexibility in firmware updates

#11 cys

cys

    Advanced Member

  • Members
  • PipPipPip
  • 113 posts
  • LocationSoCal

Posted 14 February 2012 - 01:47 AM

I was able to manually compile and shrink MonoBlinky on my Mac. However, when working on my own app, compile is successful, but I get the following error when trying to shrink: "MonoNetduinoApp: error MMP0000: Cannot resolve type System.Runtime.CompilerServices.CompilerGeneratedAttribute from assembly MonoNetduinoAPP!" Any tips appreciated. I'm a newbie at this, so it could be something quite simple. Thanks.

#12 che

che

    New Member

  • Members
  • Pip
  • 1 posts

Posted 26 February 2012 - 03:10 PM

Can you explain what is happening when Assembly.load is executed? Does the code saved to SRAM or Flash/ROM ? Will the code be written to Flash on every .load launch? AT91SAM7X FLASH Memory has only ~10000 write cycles. Thanks.

#13 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 February 2012 - 04:02 PM

che: When Assembly.Load(...) is executed, the assembly is loaded into RAM. Ryan: if the assembly is too big to be loaded, you should get an OutOfMemoryException. In both cases, the dynamically-loaded assembly reduces the available RAM to your application, since it's using program RAM. Chris

#14 zei0

zei0

    New Member

  • Members
  • Pip
  • 4 posts

Posted 02 July 2014 - 03:17 PM

Hi Chris, What are the limitations of this method? I can get your two examples running but when I try to load a larger assembly it fails to run (no error is reported, netduino plus is unresponsive, runs when loaded in the traditional manor). I have put all the references that are used in the assembly into the bootloader program (necessary?) with no luck. Perhaps I need to do something differently when using multiple classes (also threading) or the memory foot print is now too large? Any help with this would be appreciated. Thanks again. Ryan Firmware v4.1.1 BETA 1 Traditional Method Total: (11856 RAM - 100832 ROM - 53025 METADATA) .pe file on SDcard (11KB) The debugging target runtime is loading the application assemblies and starting execution. Total: (12120 RAM - 101992 ROM - 53394 METADATA)






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.