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.