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 mounting throws NotSupportedException


  • Please log in to reply
11 replies to this topic

#1 nhale

nhale

    Advanced Member

  • Members
  • PipPipPip
  • 64 posts
  • LocationHeidelberg, Germany

Posted 28 May 2012 - 04:26 AM

Hi,

I try to mount a SD Card on my Adafruit GPS shield, but as soon as the "StorageDevice.MountSD" method is called it throws a "System.NotSupportedException"

Firmware: 4.2.0.0 (RC5)
SD Card: SanDisk 1GB formatted with FAT32/4096 blocksize (No-SDHC!)

The shield description says "The SD card must be connected to the Arduino digital pins 13, 12, 11, and 10 for it to work and so those pins are 'taken'" (source)
So I would assume the information are correct.

For RC6 I would recommend to throw a more meaningful exception, what really went wrong...currently I'm stuck how to access my SD card. All examples use the API available only with FW:4.2.0.0 (RC5).

I would also stay with the official 4.1 as its more stable on deploying and debugging but until now found no example how to use my SD card on the shield.

Thanks

public static void Main()
        {
            try
            {
                //Just for debugging
                Thread.Sleep(10000);
                StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);

                using (var filestream = new FileStream(@"SD\test.txt", FileMode.Create))
                {
                    StreamWriter streamWriter = new StreamWriter(filestream);
                    streamWriter.WriteLine("Testcontent written to my file.");
                    streamWriter.Close();
                }

                using (var filestream = new FileStream(@"SD\test.txt", FileMode.Open))
                {
                    StreamReader reader = new StreamReader(filestream);
                    Debug.Print(reader.ReadToEnd());
                    reader.Close();
                }
                StorageDevice.Unmount("SD");
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }
        }


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 May 2012 - 04:35 AM

Hi nhale, The exception is being thrown by .NET MF itself... Perhaps we could get some more meaningful exceptions built into the core framework. You can make requests along those lines by opening an "issue" at netmf.codeplex.com. I know that the NETMF team tends to keep exceptions very simple in an effort to keep code size down. I do agree that it would really nice to know what didn't work :) Just FYI, the v4.1.1 beta firmware also supports SD card access. If that firmware works for you, we'll need to tweak the latest NETMF SD drivers (which changed a lot in NETMF 4.2). Chris

#3 nhale

nhale

    Advanced Member

  • Members
  • PipPipPip
  • 64 posts
  • LocationHeidelberg, Germany

Posted 28 May 2012 - 04:48 AM

Hi, I will try it with FW 4.1.1 and create an issue after testing if its successfull. Hope 4.1.1 is not as buggy as 4.2 in deploying and debuggin. Sometimes it takes several times to deploy and then just quits the debugger. Do you have any idea why I get a GPS fix with the Adafruit GPS shield when connecting to 9V block battery but not when using the USB-cable... Thanks

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 May 2012 - 05:11 AM

Do you have any idea why I get a GPS fix with the Adafruit GPS shield when connecting to 9V block battery but not when using the USB-cable...

How much current does the GPS receiver require? Is there a chance that you're needing more than ~400mA of current?

Also...this is on a Netduino and not a Netduino Plus correct?

Chris

#5 nhale

nhale

    Advanced Member

  • Members
  • PipPipPip
  • 64 posts
  • LocationHeidelberg, Germany

Posted 28 May 2012 - 05:27 AM

Hi, no it's on Netduino Plus (in Germany its currently very hard to get a Non-Plus). The GPS receiver is a EM-406a which requires 70mA at 4.5-6.5V USB is 500mA at 5V and the battery is 200mA at 9V. Regarding 4.1.1 Beta....where the hell do I get the SecretLabs.NETMF.IO.dll + pe file... - I have installed .NET Micro Framework 4.2 and Netduino SDK 4.2 but the 4.2 version of the dll does not work with a 4.1 application (and I would assume that I have to build it as 4.1 for FW 4.1.1) Error on build is always "Could not copy the file "C:\Netduino\POC\SDCardTest\bin\Debug\BE\SecretLabs.NETMF.IO.pe" because it was not found."

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 May 2012 - 05:38 AM

Hi nhale, I'm just realizing that you're using a Netduino Plus. Which as built-in MicroSD. Sorry I didn't see that sooner. Currently NETMF is limited to one SD card per board. Since you have MicroSD on your Netduino Plus already (using the "\SD" path) the additional SD card on the shield may not be available. Do you have a MicroSD card you can try? With Netduino Plus, it will auto-detect. Chris

#7 nhale

nhale

    Advanced Member

  • Members
  • PipPipPip
  • 64 posts
  • LocationHeidelberg, Germany

Posted 28 May 2012 - 05:49 AM

Hi Chris,

ok, thanks now it's clear why it doesn't work. Currently I have no microSD card available (and today is a public holiday in Germany ;-().
I also found some sources for the library and the exception is thrown in line with the "SDSPI_Mount(" call.
Maybe some kind of check if Netduino Plus is the device and then throw a meaninfull exception (2nd overload of NotSupportedException ;-)) would be great.
The check for "SdCardPath" does not work in this case (according to the comment above the code).

//StorageDevice.cs
public static void MountSD(string path, SPI.SPI_module spi, Cpu.Pin chipSelect, Cpu.Pin cardDetect)
        {
            // TEMPORARY LOGIC: if we already have an SD card mounted, don't do it again.
            if (SdCardPath != null)
                throw new NotSupportedException();

              SDSPI_Mount(path, (UInt32)spi, (UInt32)chipSelect, (UInt32)cardDetect);

            SdCardPath = path;
        }

Anyway thank you very much for the fast and instant replies :-)

#8 Martin Ayotte

Martin Ayotte

    Member

  • Members
  • PipPip
  • 15 posts

Posted 10 December 2012 - 10:49 PM

Hi Chris, Is there any reason why we can't have another SD slot hookup on different chipSelect if we use the MountSD ? Is it only because NETMF can't handle 2 CS during file i/o transactions ?

#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 December 2012 - 05:24 PM

Hi Martin,

Is there any reason why we can't have another SD slot hookup on different chipSelect if we use the MountSD ?
Is it only because NETMF can't handle 2 CS during file i/o transactions ?

It might be possible to hack the NETMF firmware to allow this.

NETMF makes a few assumptions at compile-time as to how many devices you will have hooked up, how to allocate pinned memory buffers (at a low memory address, so you don't have unnecessary fragmented memory issues), etc.

All that said, would you like us to add this to the feature request list?

Chris

#10 Martin Ayotte

Martin Ayotte

    Member

  • Members
  • PipPip
  • 15 posts

Posted 14 December 2012 - 03:06 PM

[...]

All that said, would you like us to add this to the feature request list?

Chris


Although there is no emergency for this feature, that will be a "nice to have" ...

#11 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 15 December 2012 - 01:41 AM

Although there is no emergency for this feature, that will be a "nice to have" ...



signed

#12 piiper

piiper

    New Member

  • Members
  • Pip
  • 6 posts

Posted 20 June 2014 - 07:27 AM

Any news on this?

 

I really need to hook up an SD card to my NetduinoPlus. Can't use the internal microSD.

 

Thanky you






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.