Skip to main content
Associate II
January 29, 2025
Solved

STM32 FATFS with SPI FLASH

  • January 29, 2025
  • 3 replies
  • 1381 views

I am trying to interface a SPI flash from Winbond (W25Q64JV) with FATFS.

I have no previous experience with FATFS.

I initialize FATFS in CubeMX with the option "used-defined" and modified the MAXIMUM and MINIMUM Sector Size to 4096, as it is the smallest possible erase sector dimension.

I Got a Sample github code. This is It.
https://github.com/maxiufeng258/SPI_Flash_Uart_Led_Polling_V1.0.

i got w25Qxxx file from this github file which contain spi command to interact with w25q64.
Now i know i should edit User_diskio or diskio,c as mentioned in the gitcode.

i done it and got hardfault error at HAL_SPI_Transmit() function.
i know that so many done and success it before . 
but i dont get a clear picture of how it done. anyone guide ASAP 

This topic has been closed for replies.
Best answer by Tesla DeLorean

>>before first byte transfer it goes to hard fault error. 

Debug the Hard Fault cause, usually pretty fundamental. Look at the faulting code, look at the registers when it faults. Likely you're using a bad pointer, pointing to the wrong memory, or exceeding that memories limits. Potentially the stack might be too small.

Ideally have a Hard Fault Handler that outputs actionable data.

3 replies

ST Technical Moderator
January 29, 2025

Hello @NOVAL_______BOBY 

Could you please share more details about the issue?

Does the SPI start writing and then go to a hard fault after transmitting a given number of bytes?

Does the execution go to a hard fault since the first bytes?

You mentioned in the post below that you succeeded in making the writing process work but failed in the reading process.

FatFS write successful but read not working on w2... - STMicroelectronics Community

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
Associate II
January 29, 2025

before first byte transfer it goes to hard fault error. 
when i try to do first time , i write sucessfully. but after try to open it show no such file and if i try to list all files, shows no such root directory.

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
January 29, 2025

>>before first byte transfer it goes to hard fault error. 

Debug the Hard Fault cause, usually pretty fundamental. Look at the faulting code, look at the registers when it faults. Likely you're using a bad pointer, pointing to the wrong memory, or exceeding that memories limits. Potentially the stack might be too small.

Ideally have a Hard Fault Handler that outputs actionable data.

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