PandaII SD-CARD Error

Hello,
I am a newbie and have a PANDAII. I can not get data from my SD card read. I get the error message:

Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1)
Microsoft.SPOT.IO.NativeIO::GetAttributes [IP: 0000]
System.IO.FileStream::.ctor [IP: 005c]
System.IO.FileStream::.ctor [IP: 0010]

And I have tested several programs from here:
[url]http://wiki.tinyclr.com/index.php?title=File_System[/url]

When debugging, I noticed that the cards are not formatted. But they are FAT16 and then 32 an FAT16…

VolumeInfo.GetVolumes()[0].IsFormatted

get me a false

I have tested it with just two 2GB SD cards:
[ulist]SanDisk Mobile microSD 2GB
Platinum micoSD 2GB[/ulist]

But it’s not work. What am I doing wrong? I have been an PANDAII only via USB and have no other devices connected.
I am using Visualstudio 2010 Ultimate .NET Micro fame work 4.1. if everything works.
Please help me.

Welcome to the forum Pierre.

Can you please post the code you use to mount the SD card (use code tags)? Have you been able to deploy other code to the Panda?

I use only the code from this website:
[url]http://wiki.tinyclr.com/index.php?title=File_System[/url]

but concrete:

        public static void Main()
        {
            // ... check if SD is inserted
            // SD Card is inserted
            // Create a new storage device
            PersistentStorage sdPS = new PersistentStorage("SD");

            // Mount the file system
            sdPS.MountFileSystem();

            // Assume one storage device is available, 
            // access it through NETMF
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            FileStream FileHandle = new FileStream(rootDirectory +
                                          @ "\hello.txt", FileMode.Create);
            byte[] data =
               Encoding.UTF8.GetBytes("This string will go in the file!");
            // write the data and close the file
            FileHandle.Write(data, 0, data.Length);
            FileHandle.Close();

            // if we need to unmount
            sdPS.UnmountFileSystem();

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

}

i’m trying to to run this sample:
[url]http://wiki.tinyclr.com/index.php?title=FEZ_Audio_OUT[/url]

Other programs run e.g. FEZ-TOUCH Display

Have you successfully run other code that does not use the SD card ? For example, can you successfully get the default LED blink program to work? Do you have the latest firmware installed?

The code you posted does not have a Read() call in it, so what code did you use that threw the error you posted? I’m not sure what you mean by “but concrete”.

The other progam run very good, LED blink programm or my display but only i can read or write date from the sd-card. i have installed the last firmware.

[quote]concrete[/quote] I mean, this is an example. if I can read or write, the program the “opinion” my card is not formatted and got out.

on this code i get the same error:

using System;
using System.IO;
using System.Threading;
 
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
 
using GHIElectronics.NETMF.IO;
 
namespace Test
{
    class Program
    {
        public static void Main()
        {
            // ...
            // SD Card is inserted
            // Create a new storage device
            PersistentStorage sdPS = new PersistentStorage("SD");
 
            // Mount the file system
            sdPS.MountFileSystem();
 
 
            // Assume one storage device is available, access it through 
            // Micro Framework and display available files and folders:
            Debug.Print("Getting files and folders:");
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                string rootDirectory = 
                    VolumeInfo.GetVolumes()[0].RootDirectory;
                string[] files = Directory.GetFiles(rootDirectory);
                string[] folders = Directory.GetDirectories(rootDirectory);
 
                Debug.Print("Files available on " + rootDirectory + ":");
                for (int i = 0; i < files.Length; i++)
                    Debug.Print(files[i]);
 
                Debug.Print("Folders available on " + rootDirectory + ":");
                for (int i = 0; i < folders.Length; i++)
                    Debug.Print(folders[i]);
            }
            else
            {
                Debug.Print("Storage is not formatted. Format on PC with 
                             FAT32/FAT16 first.");
            }
 
            // Unmount
            sdPS.UnmountFileSystem();
        }
    }
}

not an error because the program intercepts the error. but i get only the debug print: “Storage is not formatted. Format on PC with FAT32/FAT16 first.”

:frowning:

No idea what these statements mean.

As I understand so far, you don’t get an exception with this second code example, but the two cards you tried both give you the ‘card not formatted’ debug statement? Do the cards work in a PC?

Sorry for all the questions, but I don’t yet understand the exact nature of your problem.

if i use:

if (VolumeInfo.GetVolumes()[0].IsFormatted)
..
else(
...
)

i get no error or exeption, that i mean with “the program interups the error”.

the sd-cards i have formated on my pc and both works.

That’s right.

My brain power is waning fast as the night progresses. Let’s see if someone else can chime in with any ideas of what to try… you may not see a new response until tomorrow morning (EST). I do know that some brands of SD cards have caused problems in the past, maybe Kingston was one. What operating system are you using to format the cards?

@ GHI, @ Anybody have a suggestion?

What is your SDK version and what is the device’s version?

Don’t use windows built-in formatter. Try the one that is made by SD Association:

https://www.sdcard.org/downloads/formatter_3/

For what its worth…

Yesterday i formatted an SD card on a win 7 machine, dimped some mp3 files on it and plugged it into my Panda II. Used the music shield and the driver + the extension from code.tinyclr.com and had no problems. I remember Gus saying something about SD cards in an earlier post too.

Hi all,

my panda has the firmware: 4.1.7.0
under VisualStudio:
[ulist]GHI SDK: 4.1.7.0
Microsoft Framework: 4.1.2821.0
Run-time version: 4.0.30319[/ulist]

I have my cards with the “SD Formatter 3.1” Formatted (full format), but it changes nothing. The cards are supposedly not Formatted.

I’ve already read the other forum posts but found nothing that helps me.

:frowning:

Maybe let fez format your SD the way it likes.

A nice idea.

I have try this code:
[url]http://www.java2s.com/Open-Source/ASP.NET/Framework/netmf/Microsoft/SPOT/Platform/Tests/IOTestsHelper.cs.htm[/url]


using System;
using System.IO;
using System.Threading;
using System.Collections;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.IO;

namespace FEZ_Panda_II_ApplicationSD_CARD
{
    public class FormatParameters
    {
        public String VolumeName = "";
        public uint Parameter = 0;
        public String Comment = "";
    }

    public class Program
    {
        public static void Main()
        {
            PersistentStorage sd = new PersistentStorage("SD");
            sd.MountFileSystem();

            VolumeInfo _volumeInfo = null;
            FormatParameters[] _volumes = null;
            String[] _tests;
            int _currentVolume;

            ArrayList deviceVolumes = new ArrayList();
            
            // Get Volumes from device
            foreach (VolumeInfo volume in VolumeInfo.GetVolumes())
            {
                if (volume.Name == "WINFS")
                {
                    deviceVolumes.Add(new FormatParameters { VolumeName = "WINFS", Parameter = 0, Comment = "Emulator" });
                }
                else
                {                    
                    deviceVolumes.Add(new FormatParameters { VolumeName = volume.Name, Parameter = 1, Comment = "FAT16" });
                   // deviceVolumes.Add(new FormatParameters { VolumeName = volume.Name, Parameter = 2, Comment = "FAT32" });
                }
            }

            _volumes = (FormatParameters[])deviceVolumes.ToArray(typeof(FormatParameters));

            VolumeInfo myvolume = new VolumeInfo(_volumes[0].VolumeName);
           
            myvolume.Format(_volumes[0].Parameter, true); // FORMAT
            
            //Directory.SetCurrentDirectory(myvolume.RootDirectory);
            
        }
    }
}


but it dosn’t work. Have you a code for the Panda II ?

#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (5) ####
I have the same problem on the Panda II.
Firmware: 4.1.8.0

I tried to format the SD with the Panda II and with Windows 7 - i also used two different 2GB SD Cards.
[url]http://www.tinyclr.com/forum/23/5478/#/1/msg52093[/url]

My other applications without the SD support are fine.

Do you have an SDHC card you can try (>2GB)? Can you run any other functions or get return values from other properties on the cards? I haven’t used the SD card on my Panda II in awhile, and it has always worked fine. I may try it out with the new SDK to see if I can reproduce this (don’t hold your breath for the results, though :wink: ).

Pierre2,

The only time I got the error that you mention in your first post is if I try to run this code using the emulator.

#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####
#### Message: 
#### Test.Program::Main [IP: 0007] ####

A first chance exception of type ‘System.NotSupportedException’ occurred in MFConsoleApplication1.exe
An unhandled exception of type ‘System.NotSupportedException’ occurred in MFConsoleApplication1.exe

I ran your code in reply 4 exactly as you have it there and I did not get any errors. It read the filesystem and listed the files in the main directory.

For this example you posted, make sure you have the following assemblies:
GHIElectronics.NETMF.IO
GHIElectronics.NETMF.System
Microsoft.SPOT.IO
Microsoft.SPOT.Native
mscorlib
System.IO

I ran the code that you linked to in your first post using a Panda II template and modified the code as follows:

using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.IO;

namespace FEZ_Panda_II_SD_Test
{
    public class Program
    {
        public static void Main()
        {
            // ...
            // SD Card is inserted
            // Create a new storage device
            PersistentStorage sdPS = new PersistentStorage("SD");
 
            // Mount the file system
            sdPS.MountFileSystem();
 
 
            // Assume one storage device is available, access it through 
            // Micro Framework and display available files and folders:
            Debug.Print("Getting files and folders:");
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                string rootDirectory = 
                    VolumeInfo.GetVolumes()[0].RootDirectory;
                string[] files = Directory.GetFiles(rootDirectory);
                string[] folders = Directory.GetDirectories(rootDirectory);
 
                Debug.Print("Files available on " + rootDirectory + ":");
                for (int i = 0; i < files.Length; i++)
                    Debug.Print(files[i]);
 
                Debug.Print("Folders available on " + rootDirectory + ":");
                for (int i = 0; i < folders.Length; i++)
                    Debug.Print(folders[i]);
            }
            else
            {
                Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
            }
 
            // Unmount
            sdPS.UnmountFileSystem();
            Thread.Sleep(Timeout.Infinite);
        }
        //public static void Main()
        //{
        //    // Blink board LED

        //    bool ledState = false;

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

        //    while (true)
        //    {
        //        // Sleep for 500 milliseconds
        //        Thread.Sleep(500);

        //        // toggle LED state
        //        ledState = !ledState;
        //        led.Write(ledState);
        //    }
        //}

    }
}

Make sure these assemblies are pressent:
FEZPanda_II_GHIElectronics.NETMF.FEZ
GHIElectronics.NETMF.IO
GHIElectronics.NETMF.System
Microsoft.SPOT.Hardware
Microsoft.SPOT.IO
Microsoft.SPOT.Native
mscorlib
System.IO

Again I did not get any errors and the filesystem was read as it was read in the reply 4 test program.

I tested these programs on two different cards:
Kingston 2GB MicroSD
Dane-Elec 4GB MicroSD HC

This is the capabilities of my current version of Panda II:

ClrInfo.clrVersion: 4.1.2821.0
ClrInfo.clrVendorInfo: Microsoft Copyright (C) Microsoft Corporation. All rig
ClrInfo.targetFrameworkVersion: 4.1.2821.0
SolutionReleaseInfo.solutionVersion: 4.1.6.0
SolutionReleaseInfo.solutionVendorInfo: GHI Electronics, LLC
SoftwareVersion.BuildDate: Jun 24 2011
SoftwareVersion.CompilerVersion: 410561

I ran the code as posted in Reply 13 and added the appropriate assemblies and the SD Card did indeed format. I placed the card on my laptop and it was blank. I then put some files on the card and reran one of the other SD Card reading test programs from post 1 and reply 4 and was able to read the file system.

Try some of these solutions and see if they work as I have described them.

@ Thomas8

[quote]#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (5) ####
I have the same problem on the Panda II.
Firmware: 4.1.8.0

I tried to format the SD with the Panda II and with Windows 7 - i also used two different 2GB SD Cards.[/quote]

Make sure that you are not running in emulation mode by going to the Solution Manager and double click on properties. On the properties page select the .Net Micro Framework tab and select Transport: USB… USBizi_USBizi should automatically be there.

Hi Aron, thank you for your help.
I still have the problem. I tried your code and used the assemblies you mentioned.
I am not running on the emulator.

I can not format the SD,
even when i have formated it it with Windows it will say that the card is not formatted on the Panda II.

Just a suggestion and not sure if it has anything to do with the problem, but maybe (hidden/unactivated) partitions on the SD card causes the problems.

Your exception was “not implemented” and this is what threw us all off and made this thread do long :slight_smile:
Were you loading to emulator before?

Now, the new error you have is IO exception which is related to faliure on SD card. Maybe you do not have a good power source, maybe try different card.