Main Site Documentation

An unhandled exception of type 'System.InvalidOperationException' occurred in GHIElectronics.TinyCLR.IO.dll occurred


#1

I get this error when I try to use the Filesystem example.
The only difference is that I use a G120 module.
In my idea it worked before:

using GHIElectronics.TinyCLR.Devices.Storage;
using GHIElectronics.TinyCLR.IO;
using System;
using System.IO;
using System.Text;

namespace Filesystem
{
public class Program
{
private static void Main()
{
var sd = StorageController.FromName(@“GHIElectronics.TinyCLR.NativeApis.LPC17.SdCardStorageController\0”);
var drive = FileSystem.Mount(sd.Hdc);

        var file = new FileStream($@"{drive.Name}Test.txt", FileMode.OpenOrCreate);
        var bytes = Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString() + Environment.NewLine);

        file.Write(bytes, 0, bytes.Length);

        file.Flush();

        FileSystem.Flush(sd.Hdc);
        
    }
}

}


#2

what line do you get error?


#3

I get the error on the following line:
var drive = FileSystem.Mount(sd.Hdc);


#4

Try to reformat the sdcard with FAT or FAT32


#5

Thanks for your reaction.
I formatted the card but that did not help, so I tried the same with a Panda III board and also
with a Cobra III board. These two worked well, so I am afraid that there might be a problem with my board,
although all the other options (PWM, CAN, ADC, IO’s) work well on this board.


#6

Is it a custom board? has it ever work with SD?


#7

Yes, it is a custom board. It is similar to the Cobra III board (it is built around the G120 module), but it has some customized stuff integrated on it like driver IC’s , a CAN transceiver, build in leds and connectors. Funny is that it worked with the previous version (preview 3), but not anymore. I am not sure if the hardware could be damaged in some way (other features work fine as indicated before). How can I load the preview 3 firmware on the board just to make sure if that makes any difference? TinyCLR just looks for the most recent version.


#8

I think in Preview 3 pin P1.5 was low as default, in newest version it is high as default. Try to set it low before using SD Card.

Hopefully that is the reason.

var gpio1_5 = GpioController.GetDefault().OpenPin(1*32+5);
gpio1_5.SetDriveMode(GpioPinDriveMode.Output);
gpio1_5.Write(GpioPinValue.Low);

#9

Thanks for your reaction. Unfortunately this did not help.
What SD cards are supported with which file system? I found out on the Cobra III board that the sample code worked with a micro SD of 2Gb formatted with FAT. A micro SD of 8Gb formatted as FAT32 did not work on the Cobra III either, that gave as well the same invalid operation exception. On my custom board neither of the micro SD cards work.


#10

If you know the system is good but a specific card doesn’t work we can certainly look into the card to see why it didn’t work. You can send us the card to check or the model number so we can grab one.


#11

I will check the system first. But since I noticed as well that not all cards are supported in the Panda III and Cobra III, I would like to know which ones are supported. What works on those boards is a 2Gb formatted as FAT. I don’t need a lot storage space, but the small ones are getting difficult to get and are even more expensive than the one with a larger capacity.


#12

I just re-tested the official release 1.0.0 with these cases below:

  • FEZ Panda III (without adapter)
  • FEZ Cobra III (without adapter)
  • FEZ Cobra II (with adapter)
  • G80 Development (with adapter)
    With/Without VS debug.

All the case work fine to me. The card I tested Micro Center SDHC 8G - Class 10.
Try to eject - insert for sure the socket holder is working well.


#13

I had a misunderstanding with the developer of my customized board. I had to steer a FET open for the SD interface to get power. Writing to the board works fine now, sorry for the inconvenience.