Skip to main content
Visitor II
July 24, 2025
Question

SD Card with FatFS and SPI on Nucleo-H753ZI

  • July 24, 2025
  • 1 reply
  • 426 views

I'm working on a project requiring me to save a frame captured by a camera to an SD Card. I'm using SPI to do this. I am able to save the image from an OV5640 camera to sram in a buffer using DMA, where the size is more than 300,000 bytes. I am able to save a text file to the card if I have something short like "Hello World," but when I try to save the buffer containing the frame, error code 1 is returned signaling a hard fault. Also, the errors aren't always the same, sometimes the close and un-mounting steps end in a hard fault too, but that usually goes away after rerunning the code. I am using SD Card drivers from KiwiH here. I added debug print statements throughout the f_write function in ff.c and I saw that the line that is causing the error is the here (line ~3691):

if (disk_write(fs->drv, wbuff, sect, cc) != RES_OK) ABORT(fs, FR_DISK_ERR);

This line is only ran when the contents of the buffer span multiple sectors, which than makes sense that the short messages work correctly. My code is exactly the same as the code in kiwiH's github repo for testing, but I try to write my frame buffer to the SD card. The github repository for my project is here.

 

Thanks so much in advance!

    This topic has been closed for replies.

    1 reply

    Super User
    July 24, 2025

    Why you choose a high speed cpu like H753 , but then use not its SDMMC interface to SDcard, but the only on tiny and slow cpus used SPI mode ?

    Only SDMMC in 4bit mode giving useful data rate for video. imho.

    Visitor II
    July 24, 2025

    Yeah, I realized that after I had already bought a micro-SD SPI interface peripheral. I probably would have went with that if I had realized earlier. I don't have too much more time to work on this project, so I decided to stick with SPI even if its slower.

    Super User
    July 24, 2025

    For testing just use a sd-card adapter with soldered wires; i always do it this way;

    anyway wires should be max. 30 mm long;

    AScha3_0-1753382299020.png