Author Topic: Detecting the presence of an SD card  (Read 8911 times)

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Detecting the presence of an SD card
« on: September 21, 2010, 08:51:53 PM »
In the application I'm using, I'm trying to store the configuration of the system on the SD card.  So what I need to have happen is this:

1. system startup
2. start SD card detection.
3. if SD card is detected, read configuration, otherwise, load default configuration.

The problem with 3 is that SD card mounting is done completely asynchronously.  So far, I can't find a way to determine the difference between "No SD card detected" and "Haven't checked yet", which is pretty important for this.

I'm thinking of adding a flag to the disk flags for this, which would be set in the fnInitialisationError() function.  Something like DISK_NOT_PRESENT which would be cleared before any check is made.

Is there any flag or combination of flags that can be used equivalently?  Or another way to determine this?

-Steve

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3191
    • View Profile
    • uTasker
Re: Detecting the presence of an SD card
« Reply #1 on: September 22, 2010, 12:02:46 AM »
Hi Steve

You can access the disk's flags using extern UTDISK *fnGetDiskInfo(unsigned char ucDisk);
The flag ucDiskFlags will change as the mounting and/or formatting takes place, which will help to monitor whether there is no card inserted, whether the card is in the progress of being mounted, etc.

It is also good when the socket has a switch built into it which can be used to detect the card's physical presence. This is however often not the case and so this is not integrated into the module.

If a card is inserted at reset it will be mounted and ready to use quite shortly after the reset. It makes sense to delay the check of the card until the process has had time to complete - I tend to delay the application start by this time so that the check will basically tell you immediately if the card is there or not.

Regards

Mark

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Detecting the presence of an SD card
« Reply #2 on: September 22, 2010, 04:21:23 PM »
Hi Mark,

The problem I have is that the card may very well be present, but the disk task hasn't tried to read it yet or hasn't finished mounting it yet.  In this case, I don't want to declare the SD card as missing, and load a default configuration.  I understand I can delay the initialization, but I tend to avoid relying on timing.  I want a positive confirmation that "yes, I checked and there is no SD card there."

I have added the flag to the disk flags of DISK_NOT_PRESENT, and set it in the fnInitializationError() function, and it seems to work fine.

-Steve

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3191
    • View Profile
    • uTasker
Re: Detecting the presence of an SD card
« Reply #3 on: September 22, 2010, 04:35:10 PM »
Hi Steve

I think that I understand. This means that the user can see that there has been a (positive) failed attempt of reading the card.
I will add this as you suggest.

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3191
    • View Profile
    • uTasker
Re: Detecting the presence of an SD card
« Reply #4 on: September 24, 2010, 09:40:20 PM »
Hi Steve

I have implemented the same now.
During the process I increased the width of utDisks[0].ucDiskFlags -> utDisks[0].usDiskFlags otherwsie I was running out of flag possibilities.
Also I added a flag DISK_TYPE_NOT_SUPPORTED so that the user can also identify that a card was detected but is not supported. This is set when an MMC card is found instead of an SD card.

Regards

Mark

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Detecting the presence of an SD card
« Reply #5 on: October 08, 2010, 01:13:25 PM »
This is good news.  Is there a place where you provide access to your code in development, or do I need to wait for the next release?

-Steve

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3191
    • View Profile
    • uTasker
Re: Detecting the presence of an SD card
« Reply #6 on: October 08, 2010, 08:31:33 PM »
Hi Steve

I have sent you the latest development version so that you can see the change and test it if required.
Since the various parts for the project are generally in flux and contain a fair amount of special test cases (messy stuff and some proprietary things when testing for certain users) I don't have then stored for general access.

However anyone who is interested can request to be kept up to date with anything that is relevant (Beta developers). This of course means also being able to live with the odd new problem during that phase... (and maybe an incompatibility or two, where one may need to work out why themselves).

Regards

Mark