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 Issues.


  • Please log in to reply
31 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 26 December 2010 - 08:36 PM

I finally got a nice little 2GB card for my netduino plus. I formated it to use FAT32 and I tried many code examples that are listed around here. With this code:

File.WriteAllBytes("\\SD\\text.txt", new byte[] { 4, 3, 2, 1 });
I get this error:

#### Exception System.IO.IOException - CLR_E_INVALID_DRIVER (1) ####
#### Message:
#### Microsoft.SPOT.IO.NativeIO::GetAttributes [IP: 0000] ####
#### System.IO.FileStream::.ctor [IP: 005c] ####
#### System.IO.File::WriteAllBytes [IP: 0012] ####
#### SD_Card.Program::Main [IP: 0014] ####
A first chance exception of type 'System.IO.IOException' occurred in System.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in System.IO.dll


also this: Debug.Print(File.Exists("\\SD\\text.txt").ToString()); returns false. but its there!

Here is my card: http://www.newegg.co...4-478-_-Product

The file is there, the card is inside the slot... I don't know whats wrong, I must be missing something....

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 December 2010 - 10:03 PM

Omar, Try two things really quick: 1. Try formatting the SD card using FAT16. Any difference? 2. If you use System.IO.Directory.GetDirectories(@"\"), does it show the SD directory as available? If not, the card is failing to mount. Chris

#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 26 December 2010 - 10:48 PM

Omar,

Try two things really quick:

1. Try formatting the SD card using FAT16. Any difference?
2. If you use System.IO.Directory.GetDirectories(@"\"), does it show the SD directory as available? If not, the card is failing to mount.

Chris

I got the following exception both before and after formating to FAT16:

#### Exception System.IndexOutOfRangeException - 0xa9000000 (1) ####
#### Message:
#### SD_Card.Program::Main [IP: 0009] ####
A first chance exception of type 'System.IndexOutOfRangeException' occurred in SD Card.exe
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in SD Card.exe

What can I do about this failure to mount?

EDIT:
I did this: string[] dirs = System.IO.Directory.GetDirectories(@"\"); and dirs is empty after executing that line.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 December 2010 - 10:59 PM

Omar,

If you execute the following code with your card inserted (and also ejected), does the debug output in your Output window properly reflect the insertion state of the card?

OutputPort SdPower = new OutputPort((Cpu.Pin)25, false); // ensure that the SD card is powered

InputPort sdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp);
Debug.Print("sd detected: " + (!sdDetected.Read()).ToString());
sdDetected.Dispose();

If this shows that your card is inserted/ejected appropriately, then unfortunately it's probably an issue with the MicroSD card. One or more of the MicroSD card manufacturers re-labels cards from multiple manufacturers. Do you happen to have a SanDisk or other MicroSD card laying around?

Chris

#5 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 26 December 2010 - 11:41 PM

Omar,

If you execute the following code with your card inserted (and also ejected), does the debug output in your Output window properly reflect the insertion state of the card?

OutputPort SdPower = new OutputPort((Cpu.Pin)25, false); // ensure that the SD card is powered

InputPort sdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp);
Debug.Print("sd detected: " + (!sdDetected.Read()).ToString());
sdDetected.Dispose();

If this shows that your card is inserted/ejected appropriately, then unfortunately it's probably an issue with the MicroSD card. One or more of the MicroSD card manufacturers re-labels cards from multiple manufacturers. Do you happen to have a SanDisk or other MicroSD card laying around?

Chris


OH darn, yup. so I guess I need to find a new micro sd card.... have you tested any cards? if so let me know which cards are known to work.

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 December 2010 - 11:52 PM

OH darn, yup. so I guess I need to find a new micro sd card.... have you tested any cards? if so let me know which cards are known to work.


We've tested a bunch of MicroSD cards, and almost all <=2GB cards work. Kingston is a bit of a wildcard since they reportedly rebrand various cards from other manufacturers...so you don't know what care you're getting. More details here.

I am currently using 256MB and 2GB SanDisk cards in my Netduino Plus.

If SparkFun or Adafruit or another Arduino reseller says that an SD card works with Arduino, and it's <=2GB, you're most likely good to go. 1GB from SparkFun || 2GB from Adafruit || 2GB SanDisk from Amazon

Chris

#7 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 27 December 2010 - 12:03 AM

We've tested a bunch of MicroSD cards, and almost all <=2GB cards work. Kingston is a bit of a wildcard since they reportedly rebrand various cards from other manufacturers...so you don't know what care you're getting. More details here.

I am currently using 256MB and 2GB SanDisk cards in my Netduino Plus.

If SparkFun or Adafruit or another Arduino reseller says that an SD card works with Arduino, and it's <=2GB, you're most likely good to go. 1GB from SparkFun || 2GB from Adafruit || 2GB SanDisk from Amazon

Chris


Thanks Chris

#8 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 January 2011 - 12:16 AM

I have a new issue, I got the card that Chris linked above, the one from amazon. and I get this now:

#### Exception System.IO.IOException - CLR_E_UNAUTHORIZED_ACCESS (1) ####
#### Message:
#### System.IO.FileSystemManager::AddToOpenList [IP: 007e] ####
#### System.IO.FileStream::.ctor [IP: 0052] ####
#### System.IO.File::WriteAllBytes [IP: 0012] ####
#### Weather.Program::Main [IP: 0017] ####
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll

            File.Create("\\SD\\yay.txt");
            File.WriteAllBytes("\\SD\\yay.txt", Encoding.UTF8.GetBytes("yay"));

no yay! <_<

EDIT:
I check the card, and the file is there, but no text is written inside it.

#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 January 2011 - 12:19 AM

Hi Omar, Have you tried creating the file as a filestream and then using a streamwriter to write the data? Chris

#10 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 January 2011 - 01:41 AM

Hi Omar,

Have you tried creating the file as a filestream and then using a streamwriter to write the data?

Chris

not yet, I'll do that now....

this worked
FileStream stream = new FileStream("\\SD\\info2.txt", FileMode.OpenOrCreate);
            byte[] buff = Encoding.UTF8.GetBytes("Works");
            stream.Write(buff, 0, buff.Length);


#11 alanb

alanb

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationNottingham UK

Posted 03 February 2011 - 06:43 PM

Hi,
I put a SanDisk 4GB SD card (in hope) into my N+ and then ran
VolumeInfo[] vols = VolumeInfo.GetVolumes();
foreach (VolumeInfo vi in vols)
{
  Debug.Print(vi.RootDirectory.ToString());
  Debug.Print(vi.TotalFreeSpace.ToString());
  Debug.Print(vi.IsFormatted.ToString());
  Debug.Print(vi.VolumeID.ToString());
}

OutputPort SdPower = new OutputPort((Cpu.Pin)25, false); // ensure that the SD card is powered

InputPort sdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp);
Debug.Print("sd detected: " + (!sdDetected.Read()).ToString());
sdDetected.Dispose();

And got

\ROOT
0
False
0
\WINFS
20000000
True
1
sd detected: True

But my point here is that I got sd detected: True in both instances i.e. when the card was in and again when ejected!! I expected the result to be False with no card inserted. To check I unplugged the N+ before running the code again but got the same result. Is this to be expected? Is \ROOT the card ?

I bought the card yesterday at the local supermarket, I assumed it was pre formatted!!

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 February 2011 - 07:25 PM

Hi alanb, The SD Detect works via a mechanical mechanism on the SD card slot. This mechanism is connected directly to pin "57". Reading that pin directly should return real-time results of insertion/ejection. If you do Directory.GetDirectories(@"\"), do you see \SD even when the card is not inserted? That is the "true test" of valid card detection. Card insertion/ejection detection is one of the dozens of tests done at Secret Labs before we ship a Netduino Plus...but it's possible that the detection circuitry wore out, got damaged, etc. We built the firmware to be resilient to that (failing gracefully during mounting if it thought a card was inserted). But we also offer a 30-day warranty. Chris

#13 alanb

alanb

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationNottingham UK

Posted 03 February 2011 - 07:55 PM

Sorry for the Newbie question but which assembly contains Directory. I cant seem to find it. Alan

#14 alanb

alanb

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationNottingham UK

Posted 03 February 2011 - 08:00 PM

Sorry, Me being stupid, I had not added System.IO to the references. Ran it and just got \ROOT and \WINFS with the SD card both in and out.

#15 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 03 February 2011 - 08:04 PM

Sorry for the Newbie question but which assembly contains Directory. I cant seem to find it.
Alan


I think you'll find it in System.IO. You may also need to add a reference to the DLL.

Forgive me if you already know this but to add an assembly;
  • Right click on the references and select Add Reference
  • In the new dialog select browse to the directory holding the assemblies. On my machine this is C:\Program Files\Microsoft .NET Micro Framework\v4.1\Assemblies\le
  • Select the System.IO.dll file and add this to the project.

Hope this helps,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#16 Jan Olof

Jan Olof

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • LocationSweden

Posted 03 February 2011 - 08:37 PM

alanb Please tell us if your 4GB card works, normally they don´t (mine Sandisk 4 GB did not work). If it should work, give us some more details of model and so on. /Jan Olof

#17 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 February 2011 - 08:53 PM

Sorry,
Me being stupid, I had not added System.IO to the references. Ran it and just got \ROOT and \WINFS with the SD card both in and out.


alanb,

Do you get \SD? Also, Netduino Plus (and .NET MF's SD_SPI driver) support cards up to 2GB. 4GB _may_ work, but we recommend <=2GB.

If you don't see \SD, then a valid card is not inserted.

Chris

#18 alanb

alanb

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationNottingham UK

Posted 04 February 2011 - 12:30 AM

alanb,

Do you get \SD? Also, Netduino Plus (and .NET MF's SD_SPI driver) support cards up to 2GB. 4GB _may_ work, but we recommend <=2GB.

If you don't see \SD, then a valid card is not inserted.

Chris

No didnt see /SD so I will get a 2GB card .
Alan

#19 Earthed

Earthed

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationAustralia

Posted 05 August 2011 - 07:58 AM

NETMF: v4.1.2821.0 on NetduinoPlus I tried to run the code suggested above on v4.1.2821.0: "... OutputPort SdPower = new OutputPort((Cpu.Pin)25, false); InputPort SdDetected = new InputPort((Cpu.Pin)57, false, Port.ResistorMode.PullUp); ..." I get the following Exception (with or without SD Card present: #### Exception System.Exception - CLR_E_PIN_UNAVAILABLE (1) #### #### Message: #### Microsoft.SPOT.Hardware.Port::.ctor [IP: 0000] #### #### Microsoft.SPOT.Hardware.OutputPort::.ctor [IP: 0006] #### #### namespace_Lib_SD.Lib_SD::Start [IP: 001f] #### #### NetduinoPlusLibrary.Program::Main [IP: 009c] #### A first chance exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll I had a look at the schematic and tried to relate to the code above. PB25-(71)-<< (input) /MICRO_SD_CARD_INSERTED (???<--->???) (Cpu.Pin)57 PA25-(59)->> (output) /PWR_CTRL_uSD (???<--->???) (Cpu.Pin)25 Is there some reference lookup table that relates the Schematic pinouts to the Cpu.Pin references? Aside: I heard that a lot of 'clone' SD cards 1GB., 2GB etc are actually fitted with a 64KB memory and addressing is overlayed. The only way to test integrity of the uSD is to copy a 1GB or 2GB file(s) on to the uSD and copy it back to the PC, and do a file compare (Beyond Compare)!. PS: Other than this have my class reading and writing using StreamReader/StreamWriter perfectly well.

#20 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 05 August 2011 - 08:41 AM

Hi Earthed, The power and detect pin are used behind the scenes by the .NET Micro Framework. If you have a card inserted, .NET Micro Framework may give you angry exceptions since the pins are already being used for something :) Chris




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.