System.Update Need Your Help On Fez Panda

Hi All,
Is it Possible to update user application On Fez_Panda II From SD Storage?

i wrote code using this article:
http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/html/53c9fe92-8150-bd36-e2de-bf4fc6f13f8f.htm
But After AccessBootloader Cant connect to Device

what im doing:

  1. I write some led blink project and deployed it on panda, after this Generated file using G Command, also i converted into hex
  2. wrote code if SystemMode is NonFormatted EnableBootloader to seperate two applications and on button click accessingBootloader
  3. button clicked accessBootloader and this PC Saying USB Not Recognized
    so i cant deploy app into bootloader mode this is problem

I am having some difficulty following your process, but to answer your first question, yes you can update the user application on a Panda II from SD storage.

After your main application formats and then calls access boot loader, you should be able to deploy your bootloader app to that region. The bootloader code should be a different app from your main program and be 48KB or less in size.

The boot loader app should then read the hex file (which needs to be in a specially formatted, you cannot use the HEX you pulled using “G” command, the 96KB region needs to be extracted using another utility. Alternatively, you could write the extraction routine into your boot loader).

1 Like
  1. OK thank you .

Yes i know received binary data from g command converted to srec format using this application (http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/USBizi_ExtractApplication.exe) from command prompt and im trying to update using this file

thanks

In your first post you said “button clicked”

Which button are you clicking?

Here is my code

 public static void Main()
        {
            var mode = SystemUpdate.GetMode();
            if (mode == SystemUpdate.SystemUpdateMode.NonFormatted)
            {
                SystemUpdate.EnableBootloader();
            }
            if (mode != SystemUpdate.SystemUpdateMode.Application)
            {
                throw new InvalidOperationException("We are not in application mode!");
            }


            InterruptPort rightButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.LDR, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            rightButton.OnInterrupt += new NativeEventHandler(rightButton_OnInterrupt);

            Thread.Sleep(Timeout.Infinite);
        }

        static void rightButton_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            Debug.Print("ACCESSING Bootloader");
            Thread.Sleep(2000);
            SystemUpdate.AccessBootloader();
        }

Alright, after a little testing, we ran into the same problem you had. I’ll explain step by step what we did, and how to get past the issue. Since this process requires 3 major steps, with 3 separate programs to deploy, I will be breaking this up into 3 posts, 1 for each step.

Step 1:

Deploy the following program. No other actions are needed for this step.

using System;
using Microsoft.SPOT;

using GHIElectronics.NETMF.System;
using Microsoft.SPOT.Hardware;
using System.Threading;
using GHIElectronics.NETMF.FEZ;

namespace Step_1
{
    public class Program
    {
        public static void Main()
        {
            var mode = SystemUpdate.GetMode();
            if (mode == SystemUpdate.SystemUpdateMode.NonFormatted)
            {
                SystemUpdate.EnableBootloader();
            }

            Thread.Sleep(Timeout.Infinite);
        }
    }
}

Step 2:

Deploy the following application. This application will be substituted with your actual application. DO NOT PRESS THE LDR BUTTON YET.

Note: This is where the issue is corrected. Your application must be under 48kb. We had the same issue as this post describes, so we removed unneeded references until we were at the appropriate size. If you do not, you may get a “Error with device, please check your hardware” message in this or the next step.

using System;
using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

using GHIElectronics.NETMF.System;
using System.Threading;

namespace Step_2
{
    public class Program
    {
        public static void Main()
        {
            var mode = SystemUpdate.GetMode();
            if (mode != SystemUpdate.SystemUpdateMode.Application)
                throw new InvalidOperationException("We are not in application mode!");

            InterruptPort rightButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.LDR, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            rightButton.OnInterrupt += new NativeEventHandler(rightButton_OnInterrupt);

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);

            Debug.Print("This is the normal application working...");
            //...
            //...

            for (; ; )
            {
                led.Write(!led.Read());
                Thread.Sleep(100);
            }
        }

        static void rightButton_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            Debug.Print("ACCESSING Bootloader");
            Thread.Sleep(2000);
            SystemUpdate.AccessBootloader();
        }
    }
}

Once this application is deployed, press and hold the RESET button, being careful not to hit LDR. Once RESET has been pressed, you can now press and hold LDR. Release RESET to enter loader mode.

From Teraterm, connect to the COM port that is created when the board enters loader mode, and type only a ‘G’. This letter must be capital. Now go to File->Transfer->XMODEM-> Receive… At the bottom, there are 3 options, Checksum, CRC, and 1K. Select 1k. Now browse to where you would like to save the file and select Open.

Once that is done, use the USBizi_ExtractApplication.exe that you used earlier, and copy that output file to an SD card and rename it app.hex.

Insert the card into the board and proceed to the next step.

Reset the board.

Step 3:

You may now press the LDR button, and deploy the following program. Press the LDR button when it is listed in the Output Window. Your board will be updated and resume normal operation.

using System;
using System.IO;
using Microsoft.SPOT;

using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.IO;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace Step_3
{
    public class Program
    {
        public static void Main()
        {
            if (SystemUpdate.GetMode() != SystemUpdate.SystemUpdateMode.Bootloader)
                throw new InvalidOperationException("We must be in bootloader mode!");

            // set up the right button to do the system update
            InterruptPort rightButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Digital.LDR, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            Debug.Print("Press LDR to proceed with update");

            // wait for it to be pressed
            while (rightButton.Read())
                ;

            PersistentStorage sd = new PersistentStorage("SD");
            sd.MountFileSystem();

            string fileName = "\\SD\\app.hex";

            FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            // start update
            SystemUpdate.ApplicationUpdate.Start();

            // read the file in chucks
            byte[] buffer = new byte[10 * 1024];
            int length;

            do
            {
                length = file.Read(buffer, 0, buffer.Length);
                SystemUpdate.ApplicationUpdate.Write(buffer, 0, length);

            } while (length == buffer.Length);

            file.Close();

            // End update
            SystemUpdate.ApplicationUpdate.End();

            // Access the application
            SystemUpdate.AccessApplication();
        }

    }
}

@ Steven -

How can you get the “app.hex” file?

How can you get the “app.hex” file? what is the “LDR Button”?

I have built a board on the basis of “FEZ Cobra Mainboard” by myself, I want to updata the .hex file of my project from USB stick to Flash of EMX.

@ workhard, this post is all about Panda, not an EMX based board. Create a new thread !