• AVR Freaks

Kingston 4GB SDHC class 4 cards - multi-block write problems.

Author
frostmeister
Super Member
  • Total Posts : 769
  • Reward points : 0
  • Joined: 2006/12/03 10:20:52
  • Location: UK
  • Status: offline
2011/04/18 10:14:19 (permalink)
0

Kingston 4GB SDHC class 4 cards - multi-block write problems.


Hardware:
PIC32MX795F512L @ 80MHz Fcy + PBCLK (yes, pbdiv = 0)
SPI2A @ 10MHz for now, card inits, writes & reads at up to 40MHz though
Kingston 4GB SDHC card, class 4

Software:
Language tool versions: pic32-as.exe v1.12, pic32-gcc.exe v1.12, pic32-ld.exe v1.12, pic32-ar.exe v1.12

MPLAB v8.66

Having problems, probably card related. Firstly, the card takes ~140mS for the first multi block write to go through. It succeeds ok, and this is only after a power up + reset on the card. Can be kludged by doing a non-critical write first of all I suppose.

My problem is that multi block writes are failing after n number of writes - always the same number. I've been trying to write 50 or 100 sectors, but, they fail like so:

Blank sectors@:
...16,17,18,19...32,33,34.....48,49.....64.....96,97,98,99

This suggests a pattern, with the 4,3,2,1 blank sectors, I haven't repeated for 200 sectors yet. I tried writing from sector 10, but same results bar the then offset of 10 sectors. It's always in the pattern described above.

I'm waiting for busy signals to clear (waiting until not 0x00 is returned) and get an E5 response for all the blocks written.

With multi-block writes, specs say prefix each block with 0xFC, until the last block, which should be prefixed with 0xFB to end writing. If I do that, the last block fails.So, I write an extra block of 0xFF as a work around, CRC'd @ 0x7FA1 again as per specs. I've got CRC turned on and working for CMDs and block / multi block writes. 

I've also checked the status after the last block of a multi-block write, and got back 0x00. I'm inclined to say this means it's ok, but it could again be a busy signal maybe?

I'm on the point of ordering more memory cards to check against, but the 2GB card I chucked in to try failed as the replies are out of sync with the code I've written for the 4GB card.

Any debug suggestions / ideas would be great :) 
#1

4 Replies Related Threads

    frostmeister
    Super Member
    • Total Posts : 769
    • Reward points : 0
    • Joined: 2006/12/03 10:20:52
    • Location: UK
    • Status: offline
    Re:Kingston 4GB SDHC class 4 cards - multi-block write problems. 2011/04/18 16:43:11 (permalink)
    0
    Got it working. Due to busy wait states after the last block. 
    #2
    pfg
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2010/07/24 14:50:48
    • Location: 0
    • Status: offline
    Re:Kingston 4GB SDHC class 4 cards - multi-block write problems. 2011/04/23 17:32:35 (permalink)
    0
    Do you have a model number for the card you are using ? We got some 4G's but they don't have SPI mode.
    #3
    frostmeister
    Super Member
    • Total Posts : 769
    • Reward points : 0
    • Joined: 2006/12/03 10:20:52
    • Location: UK
    • Status: offline
    Re:Kingston 4GB SDHC class 4 cards - multi-block write problems. 2011/04/24 03:14:59 (permalink)
    0
    As seen on the card underside:

    SD-K04G < part number I believe
    1041 WG6093F < card serial number? Varies on two identical cards.

    Card write times don't seem too amazing. I've clocked up the SPI bus which is now running @ 40MHz and it's still taking ~1mS per block in multi block mode, writing 10 blocks at a time. 

    Equates to speeds of approx ~500KB per second. Could probably get higher with a few more blocks in the transfer. I want to write some diagnostic routines which will tell me exactly where the card is waiting in terms of the block transfers.

    I've already had to "prime" the buffers by doing a multi block write *before* I start logging, which takes ~140mS for 10 blocks. After this priming, it backs down to 10mS per 10 block transfer. Already got CRC generation farmed out to DMA, so the 9uS for that calculation is done when it's transferring the data over SPI.

    Writes on a Sandisk ultra II 15MB/S get about the same though. 

    What's the part number on your cards by the way? I've never had any cards that don't support SPI mode - would like to avoid them if possible :)


    #4
    pfg
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Joined: 2010/07/24 14:50:48
    • Location: 0
    • Status: offline
    Re:Kingston 4GB SDHC class 4 cards - multi-block write problems. 2011/05/05 23:11:18 (permalink)
    0
    I will have to find the card again - once it did not work it was relegated to camera (not mine) duty.

    Can you tell me how you're getting 40 MHz spi ? ~1ms per block works out to only 4MHz. I'd expect some extra time in the idle portion but even at 10MHz its about 90%.

    I did a ton of testing to try find out were the actual write breaks occur and all I can say is the breaks are on sector boundaries that have nothing to do with the file system. One thing I did notice all the cards had super fast write times on their original fat and directory sectors - clearly these were either different flash or actually double buffered in hardware. The breaks did seem to be repeatable on the cards I did most of the testing on but there was never a 1:1 relationship to another card even of the same brand of another size. As a result I gave up any attempt to write optimize the code because it was not going to be transportable without knowing ahead of time the actual card being used.

    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5