When I insert an SD card it seems to reset the FEZ module. Is this normal? It seems to reset when I push it about half way in. Sometimes it also resets when I remove it but not all the time.
I used the sample code that uses the thread for software insertion detection so I assumed this was possible without insertion causing a device reset.
Shawn
That is not normal on any of the non-gadgeteer boards for sure. Can you please provide the device you’re using and perhaps some sample code of what you’re doing on insert?
I Just used the sample code on the site
When I insert the SD card my computer makes the “USB Disconnected” sound and then the “USB Connected” sound. And after this the debugger no longer works but the program runs as the example text was written to the card. But I guess that probably occurs after the restart.
This happens on both my Fez Panda II’s with 4.1.8.0 firmware.
using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
namespace AutoMount
{
public class Program
{
public static void Main()
{
RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
RemovableMedia.Eject += new EjectEventHandler(RemovableMedia_Eject);
// Start auto mounting thread
new Thread(SDMountThread).Start();
// Your program goes here
// ...
Thread.Sleep(Timeout.Infinite);
}
static void RemovableMedia_Eject(object sender, MediaEventArgs e)
{
Debug.Print("SD card ejected");
}
static void RemovableMedia_Insert(object sender, MediaEventArgs e)
{
Debug.Print("SD card inserted");
if (e.Volume.IsFormatted)
{
Debug.Print("Available folders:");
string[] strs = Directory.GetDirectories(e.Volume.RootDirectory);
for (int i = 0; i < strs.Length; i++)
Debug.Print(strs[i]);
Debug.Print("Available files:");
strs = Directory.GetFiles(e.Volume.RootDirectory);
for (int i = 0; i < strs.Length; i++)
Debug.Print(strs[i]);
}
else
{
Debug.Print("SD card is not formatted");
}
}
public static void SDMountThread()
{
PersistentStorage sdPS = null;
const int POLL_TIME = 500; // check every 500 millisecond
bool sdExists;
while (true)
{
try // If SD card was removed while mounting, it may throw exceptions
{
sdExists = PersistentStorage.DetectSDCard();
// make sure it is fully inserted and stable
if (sdExists)
{
Thread.Sleep(50);
sdExists = PersistentStorage.DetectSDCard();
}
if (sdExists && sdPS == null)
{
sdPS = new PersistentStorage("SD");
sdPS.MountFileSystem();
}
else if (!sdExists && sdPS != null)
{
sdPS.UnmountFileSystem();
sdPS.Dispose();
sdPS = null;
}
}
catch
{
if (sdPS != null)
{
sdPS.Dispose();
sdPS = null;
}
}
Thread.Sleep(POLL_TIME);
}
}
}
}
I have noticed the restart upon insert as well.
Are you running on a powered USB hub or wall wart adapter?
It happens on my Panda II as well, and others have mentioned that it happens for them too.
The general consensus is that the USBizi on the Panda II is insufficiently decoupled. You can solve the problem if you add the correct capacitors in the right places: http://www.tinyclr.com/forum/topic?id=3277&page=1#msg31431