cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 - SD card writing problem

lorant124
Associate III

Hi,

I have custom HW on HW I`m using MCU STM32L496RTx and SD card. SD card is connected with SDIO to MCU and in FW I`m using HAL libraries - DMA+SDIO+FATFS.

My aim is to periodically save datasets to SD card. I generate string with 51 characters. I don`t want to save each string alone but in one package.

When I`m trying to write 13056 bytes (256 * 51char) it is working properly. But when I`m trying to write a smaller amount of bytes (example 50 * 51char) writing is not correct. It seems to be ok but some chars are duplicated or missing. This wrong sequences seem to be periodical.

0693W00000APmRKQA1.png 

I tried it with not generated data, only with static string to find out if the problem is with the data generation but the problem remains. So problem is probably with writing to SD card.

Please help,:sad_but_relieved_face:

Thank you

1 REPLY 1

The FatFS ST supplies is relatively old, but reasonably stable to media <=32GB / FAT32

DMA has some alignment issues (32-bit), watch for spanning issues where write crosses sectors (512 byte) and FATFS has to deblock. Perhaps add a sanity check to DISKIO read/write for unaligned. The SDIO/SDMMC writes also need to wait for the FIFO to clear properly.

Also watch for errors from the DISKIO layer, sometimes these propagate poorly through the stack, and then the end-user ignores them.

If the issue is highly repeatable instrumentation will help confine the issue.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..