ChipworkX Development System - SD Card Question

I am laying out my own board at present and looking at the development schematic I can’t find where SD_CD (card detect) and SD_WP (write protect) connect to the processor module. It would appear that these are actually not used by the current design. Would I be correct in this assumption?

I am actually going to use a MicroSD card socket as I have no room for an SD card itself so I won’t have SD_WP available anyway.

Dave…

Thanks Andre.

I kind of figured out that it uses GPIO but not having any development board in my hands (it’s on its way) I didn’t know if the OS itself was checking a certain GPIO pin. I can’t see them anywhere on the dev board schematic so that is why I was asking if used or not.

Hi Andre,

It’s the other way around. MicroSD has no write protect. It does have card detect. At least the ones I am using do. I use it all the time on other designs.

Dave…

I have just received my ChipworkX dev system and attempting to port my old code to it. Not much needed changing to get it to compile. Just the code to handle the GPIO pins.

BUT… I can’t get it to detect the SD card that I have inserted. I have a 2GB card and I get error debug output when I call:


PersistenStorage sdPS = new PersistentStorage("SD");


 #### Exception System.Exception - 0xffffffff (1) ####
    #### Message: 
    #### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000] ####
    #### TankLevelGlide.Program::InitSystem [IP: 0008] ####
    #### TankLevelGlide.Program::Main [IP: 0047] ####
A first chance exception of type 'System.Exception' occurred in GHIElectronics.NETMF.IO.dll

Any clues to what I am missing?

Hi Andre,

Calling that function gives me this error:


 #### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####
    #### Message: 
    #### GHIElectronics.NETMF.IO.PersistentStorage::DetectSDCard [IP: 0000] ####
    #### TankLevelGlide.Program::InitSystem [IP: 0005] ####
    #### TankLevelGlide.Program::Main [IP: 0047] ####

Not tried that. In my actual end design the SD card is permanently installed so always there at power up. It is never removed or inserted.

I popped the card out. Ran the software, plugged the card in and nothing happens. The handler never gets called.

The problem is that I can’t see on the schematic where the SD card detect connects to the ChipworkX processor module. It goes to a header, SV2 but nowhere else that I can see on the drawing.

IIRC there is a pin to check for card but it does not raise events.

I am using the ChipworkX development board. Until I have my code working on that first, I am not committing my own PCB to fabrication. I am still waiting for an answer to the SD detect issue !

I just decided to run a really basic programme. See below. It fails with an exception, System.NotSupportedException - CLR_E_NOT_SUPPORTED

I have all the downloads recommended from the website. I chose 4.1 and included all the references. Still nothing working.


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

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

namespace ChipworkXTest
{
    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();        
        }
    }
}

Hi Gus,

If there is a detection in the software I would be interested to hear which IO pin the Firmware guys are expecting to find this on as I have now checked both V1.2 and V1.5 of the schematic and SD_CD (detect) only connects to the SD socket and SV2. Same with SD_WP (write protect)

I am not sure this is the reason for the failure but I would have assumed that having an SD socket on the board means that SD cards are supported. My card is only 2GB and not SDHC so only uses the SPI interface. Your board is not wired for SDHC access so it should work.

Am I maybe missing a reference? Which ones do I need for file access? I got an error about this when I first built the code and included the one it asked for. Short of adding them all, I am stumped to why it won’t work.

I was answering from my phone so I couldn’t view schematics easily. But I just checked and SD detect pin is left free for you to connect to any pin you want. If you look here http://www.ghielectronics.com/images/catalog/125-0_large.jpg you will see how we have a jumper between it and the GPIO next to it. That is how you detect SD card.

Now, my understanding is you are unable to use SD, so lets skip detection for now and concentrate on the file access. I am not sure why you are seeing an exception but someone else at GHI will look into that.

By the way, chipworkX uses SPI to access SD cards but it does not have 2GB limits. It supports SDHC cards.

@ Dave McLaughlin -

I tried your code, and no exception found on my side. Did you try difference card?
Here is code, there is a bit change so I can test many cards.


using System;
using System.Threading;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

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

namespace ChipworkXTest
{
    public class Program
    {
        public static void Main()
        {
            InputPort button = new InputPort((Cpu.Pin)ChipworkX.Pin.PA23, false, Port.ResistorMode.PullUp);
            while (true)
            {
                while (button.Read())
                {
                    Thread.Sleep(100);
                }
                // ...
                // 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.");
                }
                Thread.Sleep(1000);
                // Unmount
                sdPS.UnmountFileSystem();
                sdPS.Dispose();
                sdPS = null;
            }
            Thread.Sleep(-1);
        }
    }
}

I added the link to the board and ran the test programme I posted earlier. Same error.

I then powered down the dev board and re-ran the test programme. Now it works. Also pressing reset causes it to work after I have tried to use my main application.

There seems to be something in my main application causing this to fail but I can’t see what it can be? I am not doing anything with IO at the point the function is called. The only IO that is changed is the 2 LED outputs (I chose the same IO for this)

No threads are started at this point. The only initialisation is to some variables.

This is all the using I have:


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation.Media;
using System.IO.Ports;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Net;
using System.Xml;
using System.IO;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.IO;
using Microsoft.SPOT.IO;

using GlideButton = GHIElectronics.NETMF.Glide.UI.Button;
using GlideColors = GHIElectronics.NETMF.Glide.Colors;

What about power?

Ah ha, power it was.

I was assuming that the USB was enough to supply the system but that doesn’t appear to the case!!! It does run the LCD but it did fail when trying the SD so it must be close to the power limits.

DOH! My fail but well spotted Gus.

Right, now to get this design on the go.

Dave…