Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

SD Card in Netduino Go


  • Please log in to reply
8 replies to this topic

#1 dieguich

dieguich

    New Member

  • Members
  • Pip
  • 4 posts

Posted 09 May 2012 - 04:43 PM

Hello all!

this is my first post in the Forum.

Two days ago I've purchased a Netduino Go thinking to wrap some data from a microSD card (I've the one that comes with sparkfun mp3 decoder shield: http://www.sparkfun.com/products/10628) in order to read it, or even reproduce it in the mp3 decoder shield.

To such aim, I've also bought a Shield Base where I've pin the mp3 shield (Arduino-way). When I try to mount it using the next piece of code:

            NetduinoGo.ShieldBase sb = new NetduinoGo.ShieldBase(GoSockets.Socket1);

            try
            {
                StorageDevice.MountSD("SD1", SPI_Devices.SPI1, sb.Pins.GPIO_PIN_D10);
                
            }
            catch (Exception e)
            {
                Debug.Print("That's the error: " + e.Message);
                Debug.Print("\n");
            }

But I get always the System.IO.IOException

SecretLabs.NETMF.IO.StorageDevice::SDSPI_Mount
SecretLabs.NETMF.IO.StorageDevice::MountSD
SecretLabs.NETMF.IO.StorageDevice::MountSD
NetduinoGoApplication1.Program::Main

Any ideas? Thanks in advance.. I've try to shift to other CPU.Chip_Select (9, 8...but nothing happend). I'm using a 2Gb microSD.

Diego.

#2 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 17 May 2012 - 05:30 AM

Hi Diego, SD card support is quite broken in .Net MF 4.2 RCx at the moment, especially SDHC support. There's no telling if a card will work or not, regardless of its capacity. -Fabien.

#3 dieguich

dieguich

    New Member

  • Members
  • Pip
  • 4 posts

Posted 17 May 2012 - 09:11 AM

Hi Diego,

SD card support is quite broken in .Net MF 4.2 RCx at the moment, especially SDHC support. There's no telling if a card will work or not, regardless of its capacity.

-Fabien.



Hello Fabien, first thanks for your reply!

For our project we have gotten inspired for your web page post:

http://fabienroyer.w...ng-out-sockets/

Our idea was somehow similar, but we were thinking to use the shield base instead. Thus, plug a shield with a SD reader on the board to read the stored data.

As you can see for our post, we always get the IOException error. Digging into the code (reverse engineering) we have realised that the Exception is caused because we are not able neither to create a directory (Directory.CreateDirectory) within the netduinoGo (This what the StorageDevice.MountSD internally does, doesn't it?).

We have grabbed your code from your repository, and obviously you have been able to achieve the SD connection:

public void Initialize(GoSocket socket, string mountPoint = "SD") {
            _mountPoint = mountPoint;
            SPI.SPI_module sdCardSpi;
            Cpu.Pin sdCardChipSelect;
            Cpu.Pin sdCardGPIO;
            socket.GetPhysicalResources(out sdCardGPIO, out sdCardSpi, out sdCardChipSelect);
            if (!BindSocket(socket)) throw new ApplicationException("socket already bound");
            SetSocketPowerState(true);
            StorageDevice.MountSD(_mountPoint, sdCardSpi, sdCardChipSelect);
        }


What do you think it could be our problem? Have you had similar issues regarding the MountSD? Any help will be appreciated ;)

Finally, we would like to know if you have had any contact with the base-shield...We're trying to understand how can the SPI virtualization works...


Thanks in advance,

regards from Jon and Diego.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 May 2012 - 01:24 PM

Hi dieguich,

Two quick explanations for why this isn't working for you:

  • SPI is not a supported feature in the beta Shield Base firmware quite yet. InputPort, OutputPort, TristatePort, AnalogInput, and PWM are all supported...but SerialPort and SPI are not yet implemented.
  • Your code is trying to mount the SD as "SPI_Devices.SPI1". Once SPI is supported on the shield base, it'll be exposed as a SPI module within the shield base class (i.e. 'sb.SPI_...'). SPI_Devices.SPI1 is referring to the SPI1 channel on the mainboard instead...the same one that's used by sockets 1-4 and not the SPI channel on the shield base itself.
Once we support SPI on the shield base (soon), it'll be limited to managed code drivers in its first release. This is because go!bus is a managed code virtual i/o layer. Eventually we can push this down the stack to support native code drivers too...at which time it would be possible to use SD on a shield.

The SD card go!modules should be going out for production soon. The chips for them just arrived. I would recommend waiting a few weeks and plugging an SD go!module directly into the mainboard. Or connecting an SD card via breakout board as noted in [1] below.

That said, you do have two "hacking" options today...
  • You can wire up an SD card to a socket on the go!mainboard, temporarily, using an SD breakout board and a socket breakout. Then initialize the card the way you are doing here--but using the (Cpu.Pin) of the SPI select (and optionally GPIO, for card detect) of that socket.
  • You can also deploy C# code directly to the shield base. I'm not sure that we've put the SD drivers in the shield base NETMF firmware, but you could compile them into the Shield Base's firmware...and then use the shield you're using today. You could also add custom code to the Shield Base proxy C# app which read/wrote data to your shield base.
Using the upcoming SD go!bus module is your best long-term bet. Wiring up an SD card breakout to a socket is your best immediate option. Whichever you choose to do, we can make hardware recommendations and help you get up and running with it.

Chris

#5 dieguich

dieguich

    New Member

  • Members
  • Pip
  • 4 posts

Posted 21 May 2012 - 11:29 AM

Hello Chris,

Thanks for your reply.

We have two questions...issues :(

  • Create directory

    As we were discussing the last day with Fabien, we would like also to have your insights about the CreateDirectory issues, because it seems we're not able to create a directory in the netduinoGo:

    As you can see for our post, we always get the IOException error. Digging into the code (reverse engineering) we have realised that the Exception is caused because we are not able neither to create a directory (Directory.CreateDirectory) within the netduinoGo (This what the StorageDevice.MountSD internally does, doesn't it?).


  • number of SPI connections

    Concerning the SPI as we have understood, the netduinoGo features just 2 SPIs, right?
    What we thought when we purchased the NetduinoGo + BaseShield was to be able to use as many SPI connections as sockets (i.e. 8 sockets divided in two channels). Let's imagine we want to have several modules (e.g communication interfaces, SD reader, LCD, ..) connected to the NetduinoGo where all of them use the SPI. Are we limited to two modules? is there any other approach? have you any insight about SPI multiplexing/extending by software?

    Are all of these issues extrapolated to UART connection?

Thanks a lot for your support,

Regards from Jon and Diego.

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 21 May 2012 - 11:26 PM

Hi dieguich,

As we were discussing the last day with Fabien, we would like also to have your insights about the CreateDirectory issues, because it seems we're not able to create a directory in the netduinoGo:

Do you have a link to the post? If there's a bug in System.IO, we should be sure to post a bug report on netmf.codeplex.com. If we can repro it, we can probably dig into the source to figure out what's going on.

Concerning the SPI as we have understood, the netduinoGo features just 2 SPIs, right?
What we thought when we purchased the NetduinoGo + BaseShield was to be able to use as many SPI connections as sockets (i.e. 8 sockets divided in two channels). Let's imagine we want to have several modules (e.g communication interfaces, SD reader, LCD, ..) connected to the NetduinoGo where all of them use the SPI. Are we limited to two modules? is there any other approach? have you any insight about SPI multiplexing/extending by software?

Are all of these issues extrapolated to UART connection?

The Netduino Go has two go!bus channels (one for sockets 1-4 and one for socket 5-8) which use two independent physical SPI channels (with DMA feature). The Shield Base also has a SPI channel on digital pins D11-D13.

We are enabling one feature at a time on the Shield Base. Once we shift from the UART connection currently used on the Shield Base over to the fast SPI connection, we'll be able to enable the UART and SPI features on the Shield Base for managed code. So if you have a SPI-based LCD, you can plug it into your shield base and use it via that SPI channel...which will appear as a virtual SPI module on your mainboard.

BTW, with SPI you can have many devices connected to a single bus. You need one "chip select" pin per device...but you can have several devices per SPI channel.

Chris

#7 echeva

echeva

    New Member

  • Members
  • Pip
  • 2 posts

Posted 28 May 2012 - 11:20 AM

Hi Chris,

Regarding this quote:

Hi dieguich,

Do you have a link to the post? If there's a bug in System.IO, we should be sure to post a bug report on netmf.codeplex.com. If we can repro it, we can probably dig into the source to figure out what's going on.


We still have the CreateDirectory issue, so we have flashed the NetduinoGo firmware again (in case anything was wrong in our platform's firmware). But nothing has changed, the CreateDirectory always throws System.IO.Exception. As you recommend us we have been looking to post the issue into netmf.codeplex.com, but there is not much activity referring to NetduinoGo, so we decided to post here our program and the error we get:

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using System.IO;
using SecretLabs.NETMF.Hardware.NetduinoGo;
namespace CreateDirectory
{
    public static class CreateDirectory
    {
        public static void Main()
        {
            try
            {
                string[] fs = VolumeInfo.GetFileSystems();
                VolumeInfo[] vols = VolumeInfo.GetVolumes();
                int i = 0;
                Debug.Print("Volume Count: " + vols.Length.ToString());
                foreach (VolumeInfo vi in vols)
                {
                    Debug.Print("Root Directory: " + vi.RootDirectory.ToString());
                    Debug.Print("Total Volume: " + vi.TotalSize.ToString());
                    Debug.Print("Free Space: " + vi.TotalFreeSpace.ToString());
                    Debug.Print("Formatted: " + vi.IsFormatted.ToString());
                    Debug.Print("Volume ID: " + vi.VolumeID.ToString());
                }
                Debug.Print("current directory: " + System.IO.Directory.GetCurrentDirectory());
                string[] directories = System.IO.Directory.GetDirectories(@"\");
                Debug.Print("directory count: " + directories.Length.ToString());
                for (i = 0; i < directories.Length; i++)
                {
                    Debug.Print("directory: " + directories[i]);
                }
                string[] files = System.IO.Directory.GetFiles(@"\");
                Debug.Print("file count: " + files.Length.ToString());
                for (i = 0; i < files.Length; i++)
                {
                    Debug.Print("filename: " + files[i]);
                    FileStream fis = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
                    StreamReader sr = new StreamReader(fis);
                    Debug.Print("contents: " + sr.ReadToEnd());
                }
                System.IO.Directory.CreateDirectory(@"\SD");
            }
            catch (Exception e)
            {
                Debug.Print("Error: " + e.Message);
            }
        }
    }
}

And the error we get when creating directory is:
Volume Count: 0
current directory: \
directory count: 0
file count: 0
Exception type 'System.IO.IOException' in Microsoft.SPOT.IO.dll
Error: Exception was thrown: System.IO.IOException

Any hints would be appreciated. Btw. is there any site where download the current firmware (in case anyone solved CreateDirectory issue for NetduinoGO)?

Thanks and kind regards,
Juan and Diego

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 May 2012 - 07:46 PM

Hi Juan and Diego, The CreateDirectory method is part of NETMF, common to all NETMF-based devices which access files. If there's a bug in it, we need to fix it in the NETMF core. We're happy to help diagnose and create the fix...we just need to make sure it's fixed in the right place or it could get unfixed later. In the sample you just posted, you're trying to create a folder named "\SD". The way that NETMF works, all drives are mounted within the root folder. If you have an SD card, it'll be mounted at "\SD" automatically (or using the StorageDevice.MountSD method). You'll then create a directory _inside_ that folder, such as "\SD\MyFolder". If you do not see the "\SD" folder in the root, then the SD card isn't yet mounted. Mount it first, then create a directory, and everything should work for you at that point. Does that clarify how to create a directory? Chris

#9 echeva

echeva

    New Member

  • Members
  • Pip
  • 2 posts

Posted 29 May 2012 - 11:22 AM

Hi Juan and Diego,

The CreateDirectory method is part of NETMF, common to all NETMF-based devices which access files. If there's a bug in it, we need to fix it in the NETMF core. We're happy to help diagnose and create the fix...we just need to make sure it's fixed in the right place or it could get unfixed later.

In the sample you just posted, you're trying to create a folder named "\SD". The way that NETMF works, all drives are mounted within the root folder. If you have an SD card, it'll be mounted at "\SD" automatically (or using the StorageDevice.MountSD method). You'll then create a directory _inside_ that folder, such as "\SD\MyFolder".

If you do not see the "\SD" folder in the root, then the SD card isn't yet mounted. Mount it first, then create a directory, and everything should work for you at that point.

Does that clarify how to create a directory?

Chris


Yes Chris, now we understand how it works. We were trying to create the directory without being able to access the SD. We will try to communicate with the SD card directly from the NetduinoGo, without using the base shield.
Thanks a lot for the help.

Juan




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.