Author Topic: SD Card not formatting  (Read 18799 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
SD Card not formatting
« on: March 09, 2015, 03:15:55 PM »
Hi Mark,
  I am using V2.01 with the processor 52259 , and purchased 20 new 2GB Transcend micro sd cards . When I used (after being formatted on the computer for FAT32) the utFormat or utReformat about 8 of them never formatted. I know my board is ok as I can put a card i know that works in the board. I poll the card with the following command every second.
        if (!(ptrDiskInfo->usDiskFlags & DISK_MOUNTED))
            ...

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SD Card not formatting
« Reply #1 on: March 09, 2015, 03:40:23 PM »
Hi Neil

Are here any timeouts or error messages for the cards that don't format, or don't complete their formatting?
Can you find the state of iMemoryState when it stops?

It moves through the states

#define STATE_FORMATTING_DISK_1          20
#define STATE_FORMATTING_DISK_2          21
#define STATE_FORMATTING_DISK_3          22
#define STATE_FORMATTING_DISK_4          23
#define STATE_FORMATTING_DISK_5          24
#define STATE_FORMATTING_DISK_6          25
#define STATE_FORMATTING_DISK_7          26
#define STATE_FORMATTING_DISK_8          31
#define STATE_FORMATTING_DISK_8A         32
#define STATE_FORMATTING_DISK_9          33
#define STATE_FORMATTING_DISK_10         34
#define STATE_FORMATTING_DISK_11         35


so knowing in which state it stopped coud be helpful (also to see if it is the same for each card with the difficulty).

After completing formatting the mounting process re-starts - if the formatting actually terminated but the mounting fails (due to the format data not being read back correctly) the card would also not be ready. In thsi case the question woudl be at what point during mounting does it abort?

Regards

Mark


Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #2 on: March 09, 2015, 03:52:41 PM »
Hi Mark
    It gets stuck at on part STATE_FORMATTING_DISK_8

Regards
Neil

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #3 on: March 10, 2015, 05:19:55 PM »
Hi Mark,
  Any luck with this?

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SD Card not formatting
« Reply #4 on: March 10, 2015, 09:33:54 PM »
Hi Neil

Since I can't reproduce the problem and also it looks to be restricted to certain SD cards the best that I can do is explain what could be reasons for it to get stuck in a certain state during (re-)formatting - that is, in state STATE_FORMATTING_DISK_8.

What is happening during this state is that each sector belonging to the FAT is being deleted (written to 512 x 0x00). There are usually 2 FATs so the amount of sectors to be cleared is equal to the number of sectors in the FAT * the number of copies of the FAT.
[A 4G card has typically approx. 15'700 sectors to be deleted in its (typically)2  FATs - see the "info" command for overview of characteristics of the card]

The operation is a "background" operation which means that the system is not blocked when it is taking place. The mass storage task will delete one sector at a time and then the task will be re-scheduled so that it can delete the next one as soon as possible. During the progress there are some *** printed to the debug output so that an idea of the progress can be had. If the reformating doesn't complete I would expect this output to stop and the amount of progress actually made be visible (eg. 20%, 50, 75% of the total). By comparing the case with multiple cards that fail you can see whether it is always at the same point or whether it is more random.

The next question is whether the task is still trying or whether it has given up. In fact I wouldn't expect the task to give up unless there is also a write failure of some sort, which would be accompanied with an error such as "Write error\r\n" or possible "TIMEOUT!!!\r\n"

If there is no such error message (assuming they haven't been disabled) I would expect that the task will be in the active state and writing sectors or waiting for the SD card to inform that it is no longer busy after the previous write. Note that the D card will often be busys for a short time after each sector write so the task quits temporarily and tries again later. This means that the second question is, if no error messages were seen, whether the task is still regularly checking the state of the SD card but can't continue because the SD card always returns that it is busy (forever).

The final possibility is that there were no errors and the SD card is not busy but that the mass storage task has stopped polling/writing the card. This final possibiity would be more likely a SW error since it wouldn't be normal to stop before the process is complete. It is however unlikely that this woud be encountered only by certain SD cards and not by others.

Is it possible to identify which category of problem exists from this?

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #5 on: March 12, 2015, 10:36:14 AM »
Hi Mark,
  Thanks for the explanations. In case you get the same issue with other users, would it be useful if I sent you one of the cards so you can have a look?  The strange thing is quite a few of the cards we got did format okay , and all were purchased at the same time, and same brand.

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SD Card not formatting
« Reply #6 on: March 12, 2015, 02:43:12 PM »
Hi Neil

You are wecome to send me a card that shows a problem so that I can analyse it.

Have you been able to identify whether the problem always occurs at the same place during formatting (eg. the same number of progress *** are seen?
Also, if you try with an older version of utFAT or with a Kinetis (SDHC) instead of the SPI mode is there maybe a difference?

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #7 on: March 12, 2015, 04:59:43 PM »
Hi Mark,
  Ive no luck, but I am happy sending you one of the cards.  Can you give me the address to send it to (you can email me it if you wish)?

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SD Card not formatting
« Reply #8 on: March 12, 2015, 05:46:44 PM »
Neil

The address is at http://www.mjbc.ch/eng/contact.html

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #9 on: March 17, 2015, 09:18:42 PM »
Hi Mark,
  Thats it in the post now, hopefully you will get it in a couple of days

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SD Card not formatting
« Reply #10 on: March 23, 2015, 12:21:53 AM »
Hi Neil

I have received the 2GByte Transcend card and checked that I could format it normally with the PC (OK)

Then I put it (uSD) in a Kinetis FRDM-K64F and retried using the software from here: http://www.utasker.com/kinetis/FRDM-K64F.html
which operates in SDHC mode. This was also OK.

Therefore I don't have difficulties using the SDHC (4-bit) interface, whereas if you use the M52259 it will be communicating in SPI mode instead.

As reference, this is the "info" command output after formatting on this platform:

SD-card MARK (2008023040 bytes) FAT32
Bytes per sector: 512
Cluster size: 4096
Directory base: 0x00000002
FAT start: 0x0000005f
FAT size: 0x00000ef3
Number of FATs: 2
LBA: 0x00001e45
Total clusters: 0x00077737
Info sect: 0x00000040
Free clusters: 0x00077736
Next free: 0x00000003
CSD: 0x00 0x7f 0x00 0x32 0x5b 0x5a 0x83 0xbd 0x6d 0xb7 0xff 0x80 0x0a 0x80 0x00 0x00


As next step I will repeat with a hardware using SPI mode instead.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #11 on: March 23, 2015, 12:26:33 PM »
Hi Mark,
  Thanks for checking the card. You are right, we are using it with the 52259. Look forward to see the tests on the SPI .

Regards
Neil

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #12 on: March 25, 2015, 12:34:02 PM »
Hi Mark,
  Just wondering if you had a chance to try it using SPI on the 52259?

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: SD Card not formatting
« Reply #13 on: March 25, 2015, 01:37:40 PM »
Hi Neil

Not yet - I am having some difficulties with work load and would like to first check in SPI mode on the Kinetis and, if it is still Ok, move onto the Coldfire to be able to work out what the difference could be.

Unfortunately my first Kinetis tests failed (with all cards) so I need to work out what the problem is (the board was [partly] damaged recently when I connected something incorrectly so it could be a HW failure).

I expect to be able to continue this evening.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: SD Card not formatting
« Reply #14 on: March 25, 2015, 03:02:14 PM »
Thanks for the update Mark

Regards
Neil