Skip to main content
Associate II
March 14, 2025
Solved

FileX SD card using SPI

  • March 14, 2025
  • 4 replies
  • 1963 views

Hello,

I need to connect SD card to STM32H5 device. CubeMX does not support fatfs I was using in the past, but only ThreadX and FileX. We decided to use this as STM32H5 seems like a good choice for many future projects.

So we connected the SD via SPI.

My understanding is that I need to enable Custom interface like this: 

JeronymJ_0-1741946752464.png

And than implement several low level functions in FileX/Targer/fx_stm32_custom_driver.c. This looks like this should be common task, but I could find no examples anywhere. Is there something I could use or at least some useful documentation regarding the custom driver?
Thank you Jeronym

 

Best answer by JeronymJ

Hello, yes. I implemented the functions myself. I use ram-disk example to know what should be done and combined it with low level function for fatfs available online.

However the project is not complete and fully tested yet. So lets take it as a starting point.

I currently struggle with file name encoding (or maybe long file name issue) with fileX.

Ragards Jeronym

4 replies

Andrew Neil
Super User
March 14, 2025

@JeronymJ wrote:

CubeMX does not support fatfs 


That's not true.

While it might not have it built-in, it can certainly use it as 3rd-party source code - just as you'd use any other source code.

http://elm-chan.org/fsw/ff/ 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
JeronymJAuthor
Associate II
March 16, 2025

Hi,

thank you for the answer. Of course I know I can copy fatfs from my other applications, but that is beside the point. In this application I need to use FileX + SPI (on stm32H523), not fatfs.

AScha.3
Super User
March 14, 2025

I use H563 , has sd-mmc on board. Why not use H523 , H563 ...with SDIO ?

"If you feel a post has answered your question, please click ""Accept as Solution""."
JeronymJAuthor
Associate II
March 16, 2025

Hello, thank you for the reply.  I forgot to specify that this device uses stm32h523. Also the interface has to be SPI for legacy reasons.

matt-crc
Senior III
April 1, 2025

Hi @JeronymJ 

I struggled with the custom interface for a while.. it never configured properly with CubeMx and I could never get it to work.  I suggest you use the SD interface instead, and then modify the fx_stm_sd_driver_glue.c file to make it work with the spi device (or you can simply convert the SD device to a single bit.

mattcrc_1-1743493753989.png

Just be careful when re-configuring your system with CubeMX, because it will wipe out the changes you made in fx_stm32_sd_driver_glue.c

Good luck

 

Visitor II
March 31, 2025

Hello,

 

I am also trying to use FileX with SPI for an SD card interface. Were you able to figure out a solution?

JeronymJAuthorBest answer
Associate II
April 9, 2025

Hello, yes. I implemented the functions myself. I use ram-disk example to know what should be done and combined it with low level function for fatfs available online.

However the project is not complete and fully tested yet. So lets take it as a starting point.

I currently struggle with file name encoding (or maybe long file name issue) with fileX.

Ragards Jeronym

Visitor II
May 24, 2025

Hi JeronymJ,

I’ve been using Fatfs on STM32 and things have been going well. I recently bought a new board, the STM32 U545, and Fatfs isn’t supported anymore on it. I have an SPI SD card reader, I tried adapting the fatfs files to that new board, it works 1 time every 10+ tries.

I don’t really have any idea on how to have a stable system to control an SD card through SPI on that new board.

Have you found a solution?

JeronymJAuthor
Associate II
May 26, 2025

It you have unreliable reads/writes in my experience this may be related to HW related stuff. (speed, pull ups on the lines...)

My solution works fine. THREADX + FILEX + SPI (I did not check the with U545). I used some of the low level files previously used with fatfs and connected them to the SPI driver for FILEX. The messy but working code is attached Target.zip in previous message.