Handling Mount() UnMount() SD events

Can you try a different card and also try to format, not quick format, and try fat and fat32. The system is not happy with your current card for some reason.

Already triedā€¦ no success

How many cards have you tried?

Replace the cable used on the sd module please.

1 Like

Heā€™s using a Cerbuino Bee so itā€™s the internal SD slot.

2 Likes

@ Alex Bilityuk - What SD brands did you try?

@ Alex Bilityuk -

Hi Alex, long thread and I understand how you are feeling now. :slight_smile:

First thing now we may want you to try is, run my NETMF code above, no gadgeteer. It is easy easy and fast to try.

I know you want gadgeteer. But please try non-gadgeeter for sure the board is happy with your cards.

I have one card here, it runs perfectly in NETMF but when I tried gadgeteer driver, I had same problem with you. That why I said I was able to reproduce your issue. But I am lucky becuase after I formatted by PC then it works fine.

So, try NETMF code first to see what is happened.

If it works then no problem at hardware and firmware.

Next step is, although gadgeteer is always easier and faster, we also highly recommended to use gadgeteer in project. But sometime you may need to modify the driver a bit to flexible with your project. Instead of using standard dll driver, you can download whole gadgeteer driver and modify them, then you will be own these drivers.

By modifying the gadgeteer driver, you can still use gadgeteer and more important thing is, as I see your project is interesting and not small, so learning how to modify these driver will help you a lot so far, I think.

As I know, Cerbuino bee mainboard does not allow you to use SDCard class, that is why you have exception when implement this class in gadgeteer. Start form this. Just remember that, when removed and insert a card, the object is always need to be renew. You donā€™t see that when use gadgeteer that because gadgeteer driver done it for you.

Event when insert and remove a Card, I believe they use InterruptPort. You can try if you want.

1 Like

This link may help: https://www.ghielectronics.com/docs/122/gadgeteer-driver-modification

1 Like

@ Alex Bilityuk - I have verified that the code I gave works for me with the SD cards I have tried. The SDCardMounted event fires every time. As Dat said, he saw the issue briefly, but it went away after he formatted his SD card using his computer.

That said, I found a potential race condition that may be affecting you. Internally when we receive the SD card detect interrupt, we mount the SD card. That may happen so quickly that the SD card is not ready yet so you get the exception. I added some delays to the source that should alleviate this in the next SDK. You can see the change in this commit: https://bitbucket.org/ghi_elect/gadgeteer/commits/2a8cd274f03d85ce00cd5eeed69e85c8d4f70d24?at=master The link Dat gave you will help apply it to your current code.

1 Like

Thank you for really long reply and different suggestions you provided. How to use interrupt port in this scenario?

I tried sony and sandisc 1Gb

You are right i am using internal Cerbuino SD slot

Thank you guys you are really the best community! I will definitely try to manually change dll and use it.

Now i solved my problem this way:
I put a timer inside of my gadgeteer with 5 seconds interval and set it to ask SD IsMounted or UnMounted and if in is not mounted yet i force it to mount().
Here is my code:


     void sd_check_Tick(GT.Timer timer)
        {
            Debug.Print("Inside the SD timer");
            try
            {
                if (Mainboard.IsSDCardInserted == true)
                {
                    Debug.Print("SD card inserted");
                    if (Mainboard.IsSDCardMounted == false)
                    {
                        Debug.Print("SD card ready to be mounted");
                        string volname = Mainboard.GetStorageDeviceVolumeNames()[0];
                        Mainboard.MountStorageDevice(volname);
                        Debug.Print("SD card ready for use");
                        
                    }
                    else
                    {
                        sd_check.Stop();
                        Debug.Print("SD timer stoped");
                    }
                }
            }
            catch (Exception exp)
            {              
                Debug.Print(exp.Message.ToString());
            }
        }