SD card write problem on LPC54608

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SD card write problem on LPC54608

211 Views
jaf_developer74
Contributor II

based on the sdmmc polling example and usb vcom cdc example, I developed a program to read data from USB and write to the SD card. The program works flawlessly with some SD cards vendors such as samsung, but not with other venders such as unbranded Taiwan mde 8GB sd card.

The unbranded card works perfectly and reliably in Windows and Linux without  any problems. The hardware I use is LPCXpresso54608.

The problem is as follow:

-when block write commands (single or multiple) is used, it works flawlessly up to 16 write operation.

-After the 16 operation, the SD accept written data without any error or delay, the readback also show the correct data.

-When the power is cut or card is removed, the written data (beyond the 16 write operations) is lost and old data is found instead.

Investigation done:

-Changed SD clock down to 1M 

-Try writing in chunks of different block count (2, 4, 8, 16, 32) or single block

-Activated ACDM23 to define number of blocks to be erased before writting

-Wait for long time (2 hours) before power cut

problem not solved.

It seems that sd card controller caches the data in its buffer and never flush it to the nand, after the first successful 16-write-operation, which seems strange.

I wonder if there is a specific vender command that tells the controller to flush the written data. Why Windows and Linux driver works without problem, may be there is a secret vender-specific command. 

I know there are cards with reputable venders which overcome this problem but would like to develop a hardware wich can be used with any sd card including low-price cards.

0 Kudos
Reply
5 Replies

141 Views
jaf_developer74
Contributor II

Hi Jun Zhang,
Thank you for your input. I already tried sending CMD13 after write and also CMD7 as per LPC datasheet recommend. No change.

I have also added delays between writes without sucess. I think there is a magic command windows and Linux send after file or floder access which forces the sd to program its cached data. Maybe manual erasing one or more dummy blocks by SD_EraseBlocks() will trigger the lazy sd controller to start programming. Do you think filesystem do such thing while updating FAT?

 

0 Kudos
Reply

123 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi jaf_developer74,

Did SD card return the ready status after sending CMD13?

How does it work if explicit flush by CMD38 to triger SD card?

 I don't think windows/linux use magic command. All the available commands are listed here:

ZhangJennie_0-1761735224469.png

 

Hope this helps,

Jun Zhang

 

 

0 Kudos
Reply

89 Views
jaf_developer74
Contributor II

Hi Jun Zhang,

Thank you for your follow-up. 

Sending CMD13 command returns the sd card is not busy (DAT0 is not pulled low) and also it is ready for communication (trans state). 

I have figured out that manually erasing a dummy block with CMD32, CMD33 and CMD38, by calling SD_Erase function, triggers the lazy contoller and force it to flush bufferd data. This is not a perfect solution but suffice right now to deal with the lazy cards.

Cards tested:

SanDisk : No problem

Samsung: No problem

Kingston: No problem

Unbranded (made in Taiwan) 8GB and 2GB: problematic

 

0 Kudos
Reply

79 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi @jaf_developer74

Thanks for sharing your testing results with different brands of cards. It's invaluable.

Best Regards,

Jun Zhang 

0 Kudos
Reply

153 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi jaf_developer74,

Some low cost SD cards in order to have faster speed, once they receive data, they instantly report the write as complete, but in reality, the data is only temporarily stored in the card’s internal RAM cache and only gets properly written to the flash later. If the power cuts out at this point, the data in the cache will be lost.

So I suggest you using COM13 after each writing to make sure the internal operation is done.

ZhangJennie_0-1761648378913.png

 

Hope this helps,

Jun Zhang

 

0 Kudos
Reply