Exception System.Exception - 0xffffffff (1)

Cobra 2 eco 4.2 latest sdk using serial debug.

This code worked yesterday. Today it’s giving me an exception.

        private USBC_MassStorage ms;
        private PersistentStorage sd;
        private Boolean started;
        private Stream stream;

        // This method is run when the mainboard is powered up or reset.   
        private void ProgramStarted()
        {
            Debug.Print("Program Started");

            ms = USBClientController.StandardDevices.StartMassStorage();
            sd = new PersistentStorage("SD");
            //sd.MountFileSystem();                     
            ////sd.UnmountFileSystem();
            //VolumeInfo.GetVolumes()[0].Format("FAT", 0);
            try
            {
               // sd.UnmountFileSystem();
                ms.AttachLun(0, sd, " ", " ");          //     [b]< crashing here[/b]

                ms.EnableLun(0);
            }
            catch (Exception)
            {
            }
}

Exception System.Exception - 0xffffffff (1)

#### Message: 
#### GHI.Premium.USBClient.USBC_MassStorage::AttachLun_Helper [IP: 0000] ####
#### GHI.Premium.USBClient.USBC_MassStorage::AttachLun [IP: 000b] ####
#### ImpulseTester.Program::ProgramStarted [IP: 0049] ####

A first chance exception of type ‘System.Exception’ occurred in GHI.Premium.USBClient.dll

any Idea?

i’ve tried 3 different ones.
They all mount and format ok
it is this line that gives the exception

 ms.AttachLun(0, sd, " ", " ");

it worked fine yesterday.
i am going to try and reflash the firmware>

Re-flashing the firmware solved the problem!!
i’m concerned about this though.
why would this happen?
I am evaluating this platform and if i recommend it and we have a rash of failures in the field it won’t be good for me.

There is an issue in NETMF where writing configuration multiple times will corrupt the firmware. Not sure when NETMF is going to fix it.

Sounds like you got bit by that.

@ andre.m
do you mean “NETMF and Gadgeteer Package 2013 R2” because i am using that one?
or is there an insider one being tested?
or do you mean 4.3?

obviously it is not solved as i just had that issue with it.

Well, if the only way to fix the issue is to re-flash the firmware then it means it got corrupted somehow. So the firmware corruption issue is still might be there.

What would help if you can find out a repeatable way of reproducing the issue. That way it would be easier to identify and fix the problem.

happened again.
this time i reflashed the g120 firmware and it didnt fix the problem.
next i reflashed tinybooter and g120 fixed the problem

It happen the last time after the second time i started debugging again
here is the complete program

using System;
using System.IO;
using GHI.Hardware.G120;
using GHI.Premium.IO;
using GHI.Premium.USBClient;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace ImpulseTester
{
    public partial class Program
    {
        private const string FileName = @ "\SD\Test.TXT";
        private readonly GT.Timer CkBTN = new GT.Timer(1000);
        private readonly GT.Timer PressureReadtmr = new GT.Timer(100);
        private readonly InputPort btn = new InputPort(Pin.P0_13, true, Port.ResistorMode.PullUp);
        private readonly OutputPort led = new OutputPort(Pin.P3_26, false);
        private readonly GT.Timer noSDtmr = new GT.Timer(500);
        private readonly AnalogInput psi = new AnalogInput(Cpu.AnalogChannel.ANALOG_6);

        private Boolean btnpos;
        private DateTime dt;
        private USBC_MassStorage ms;
        private PersistentStorage sd;
        private Boolean started;
        private Stream stream;

        // This method is run when the mainboard is powered up or reset.   
        private void ProgramStarted()
        {
            Debug.Print("Program Started");

            ms = USBClientController.StandardDevices.StartMassStorage();
            sd = new PersistentStorage("SD");
            //sd.MountFileSystem();
            ////sd.UnmountFileSystem();
            //VolumeInfo.GetVolumes()[0].Format("FAT", 0);
            try
            {
                // sd.UnmountFileSystem();
                ms.AttachLun(0, sd, " ", " ");

                ms.EnableLun(0);
            }
            catch (Exception)
            {
            }

            CkBTN.Tick += CkBTN_Tick;

            PressureReadtmr.Tick += PressureReadtmr_Tick;
            noSDtmr.Tick += noSDtmr_Tick;
            CkBTN.Start();
        }

        private void noSDtmr_Tick(GT.Timer timer)
        {
            if (led.Read())
            {
                led.Write(false);
            }
            else
            {
                led.Write(true);
            }
        }

        private void PressureReadtmr_Tick(GT.Timer timer)
        {
            try
            {
                using (Stream fs = File.Open(FileName, FileMode.Append))
                using (var writer = new StreamWriter(fs))
                {
                    //= 509.52x - 3.5777
                    writer.WriteLine(((DateTime.Now.Ticks - dt.Ticks) / 600000000.0).ToString("N3") + "," +
                            ((509.52 * double.Parse(psi.Read().ToString("N3"))) - 8).ToString("N0"));
                    writer.Flush();
                }


                //stream.Flush();
                //Debug.Print(((DateTime.Now.Ticks - dt.Ticks)/600000000.0).ToString("N3") + "," +
                //            ((509.52*double.Parse(psi.Read().ToString("N3"))) - 8).ToString("N0"));
                ////                   ((psi.Read() - 0.0155)*2406).ToString("N0"));
            }
            catch (Exception)
            {
                PressureReadtmr.Stop();
                stream.Flush();
                stream.Dispose();
                led.Write(false);
                //  Mainboard.UnmountStorageDevice("SD");
                ms = USBClientController.StandardDevices.StartMassStorage();
                sd.UnmountFileSystem();
                ms.AttachLun(0, sd, " ", " ");

                ms.EnableLun(0);


                started = false;
                noSDtmr.Start();
            }
        }


        private void CkBTN_Tick(GT.Timer timer)
        {
            btnpos = btn.Read();
            if (started && btnpos)
            {
                //  Mainboard.UnmountStorageDevice("SD");

                sd.UnmountFileSystem();
                ms.AttachLun(0, sd, " ", " ");

                ms.EnableLun(0);

                PressureReadtmr.Stop();

                led.Write(false);
                started = false;

                noSDtmr.Stop();
            }
            else if (!started && !btnpos && !noSDtmr.IsRunning)
            {
                try
                {
                     ms.DisableLun(0);
                    sd.MountFileSystem();
                    //   Mainboard.MountStorageDevice("SD");
                    dt = DateTime.Now;

                    started = true;
                    led.Write(true);

                    stream = File.Create(FileName);
                    stream.Dispose();
                    //  writer = new StreamWriter(stream);
                    PressureReadtmr.Start();
                }
                catch (Exception)
                {
                    //   Mainboard.UnmountStorageDevice("SD");
                    started = false;
                    noSDtmr.Start();
                    //    Mainboard.UnmountStorageDevice("SD");

                    sd.UnmountFileSystem();
                    ms.AttachLun(0, sd, " ", " ");

                    ms.EnableLun(0);
                }
            }
            else if (btnpos && noSDtmr.IsRunning)
            {
                // Mainboard.UnmountStorageDevice("SD");
                ms = USBClientController.StandardDevices.StartMassStorage();
                sd.UnmountFileSystem();
                ms.AttachLun(0, sd, " ", " ");

                ms.EnableLun(0);

                noSDtmr.Stop();
                led.Write(false);
            }
        }
    }
}

@ GHI is anyone looking into this?

i actually sent this device out to a colleague to use in a different location and am crossing my fingers that it wont happen there and is only happening during the debug.

ok, so I had this today.

Been testing the board all day and suddenly start getting an exception on:

sd = new PersistentStorage(“SD”);

Re-flashed my code several times from VS and had no change.

So re-wrote the main firmware files using G120Updater, wrote my code again and all working again.

Something somewhere is getting corrupt in the G120 outside of app code…

@ MikeCormier Can you try to recreate the problem in a regular Micro Framework project? Not Gadgeteer.

We’re not using Gadgeteer - G120 module with Premium libraries.

Firmware corruption has been happening frequently the last couple of days:

Problem starts by showing 0xFFFFFFFF exceptions on sd creation followed shortly by non-boot-ability requiring a reflash from GHI120Updater.

Quite a complex app so no simple test case.

SD card is also periodically getting corrupted on file copy to it.

On a deadline but if any pattern becomes apparent will fill in more details.

Are you trying to attach the SD card to mass storage with AttachLun()? The original post in this thread crashes when trying to call AttachLun, not creating persistent storage. Your issue seems like a new one, dplicher.

The essence of firmware corruption and exceptions around use of the SD appears the same. I’ll open a new thread if this becomes a showstopper. Need to see if it happens outside debug flashing world…

@ Mike If you have a board with no application on it and you deploy+debug, does it work that first time and then fail every time after? If It does, try calling ms.DisableLun() and sd.Dispose() before the program ends and see if it can work on subsequent tries. I was able to reproduce the problem, but only on a second run of the application without a power cycle or call to DisableLun and Dispose.

@ John
I’ll try this out tomorrow and update you o how it goes