Hi,
I’m trying to access the SD card but I can not. By monitoring with debug always gives error within PersistentStorage (“SD”);
I read several other threads on the reasons that can cause this error, some spoke in the power supply, comment on other versions of gadgeteer and also talk about the type of formatting required for the SD card. I took every care seen in previous threads but did not succeed.
I formatted the card with FAT32, also used the formatting of VolumeInfo:
Volume.Format (“FAT32”, 0, true);
Volume.Format (“FAT”, 0);
Volume.Format (0, true);
I left only the gadgeteers required for my test to reduce the use of power.
Follows the settings of my environment:
Hardware:
Fez Spider Mainboard 1.0
SDCard 1.4
USBClient DP 1.3
SanDisk MicroSDHC 4Gb class 2
SanDisk MicorSDHC Adapter
Fez Config:
Loader (TinyBooter) version information:
4.2.11.1 on this computer.
4.2.11.1 on this device
Firmware (TinyCLR) version information:
4.2.11.1 on this computer.
4.2.11.1 on this device.
Software
VS2012
MicroFrameworkSDK NETMF SDK 4.3 (RTM) for VS2012
MicroFrameworkSDK NETMF SDK 4.2 (RTM QFE2) for VS2010
GHI NETMF v4.2 and Gadgeteer Package 2013 R3
Error, inside RemovableMedia_Insert
using System;
using System.Text;
using System.Collections;
using System.Threading;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Premium.IO;
namespace GadgeteerApp2
{
public partial class Program
{
protected PersistentStorage _pStorage;
void ProgramStarted()
{
RemovableMedia.Insert += RemovableMedia_Insert;
RemovableMedia.Eject += RemovableMedia_Eject;
Debug.Print("Program Started");
}
private void RemovableMedia_Insert(object sender, MediaEventArgs e)
{
if (this.IsStorageAvailable("SD"))
{
Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is inserted.");
if (e.Volume.IsFormatted)
{
try
{
_pStorage = new PersistentStorage("SD"); // Create a new storage device
if (_pStorage != null)
{
_pStorage.MountFileSystem(); // Mount the file system
_pStorage.UnmountFileSystem();
_pStorage.Dispose();
_pStorage = null;
}
}
catch (Exception ex)
{
/*
Storage "\SD" is inserted.
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (5) ####
#### Message:
#### GHI.Premium.IO.PersistentStorage::.ctor [IP: 0000] ####
#### GadgeteerApp2.Program::RemovableMedia_Insert [IP: 003c] ####
#### Microsoft.SPOT.IO.InsertEventHandler::Invoke [IP: 80171067] ####
#### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 0041] ####
A first chance exception of type 'System.InvalidOperationException' occurred in GHI.Premium.IO.dll
*/
}
}
else
{
Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RemovableMedia_Eject(object sender, MediaEventArgs e)
{
Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private bool IsStorageAvailable(string baseDir)
{
bool flag = false;
try // If SD card was removed while mounting, it may throw exceptions
{
switch (baseDir)
{
case "SD":
bool sdExists = PersistentStorage.DetectSDCard();
if (sdExists) // make sure it is fully inserted and stable
{
Thread.Sleep(50);
sdExists = PersistentStorage.DetectSDCard();
}
if (sdExists)
{
flag = true;
}
else
{
flag = false;
}
break;
}
}
catch
{
flag = false;
}
return flag;
}
}
}
I have no idea what might be causing this error.
Thanks for the help,
Andrew Paes