I'm using the FatFS HAL driver with the STM32F405RGTx MCU on a custom PCB. I'm with the University of Calgary's Student Organization for Aerospace Research, and we are using the STM32 for our onboard flight systems for our rocket that will compete in the Spaceport America Cup 2018.
I did eventually get the MCU to write to the SD card, to first_file.txt with the correct information (I was so happy). But it was very very unstable. With a myriad of power cycles and reflashing the MCU, seemingly at random, sometimes the card will get mounted and the card will get written to, and otherwise it would not get mounted.
If the SD card gets mounted, it happens around 3 seconds after startup. Otherwise the SD card never gets mounted (I've waited up to a few minutes). If the SD card gets mounted, it always gets successfully written to.
Code Changes
I downloaded the code located on your website, which I did notice was out of date. I had to implement the fix on #25. I did some other changes as well so unnecessary includes didn't mess up the build.
Once the build worked, the mount was failing every time, it boiled down to the select() function in fatfs_sd.c on line 158. The timeout number was too short if (wait_ready(500)), I changed it to 10000, and then sometimes the disk would get mounted. It takes about ~3 seconds every time it works.
So with all that, I have two things I would like to ask.
Is increasing the timeout a change suitable to this repo? I can see how it might not because FatFS is a third party library. But if it is, I'd happily make a pull request for it.
Based on my setup, is there any red flags for instability with the SD card? Do you have any ideas for how to increase the stability of writing to the SD card?
Background
I'm using the FatFS HAL driver with the STM32F405RGTx MCU on a custom PCB. I'm with the University of Calgary's Student Organization for Aerospace Research, and we are using the STM32 for our onboard flight systems for our rocket that will compete in the Spaceport America Cup 2018.
I followed the guide on your website at http://stm32f4-discovery.net/2015/08/hal-library-20-fatfs-for-stm32fxxx/
Final Result
I did eventually get the MCU to write to the SD card, to
first_file.txt
with the correct information (I was so happy). But it was very very unstable. With a myriad of power cycles and reflashing the MCU, seemingly at random, sometimes the card will get mounted and the card will get written to, and otherwise it would not get mounted.If the SD card gets mounted, it happens around 3 seconds after startup. Otherwise the SD card never gets mounted (I've waited up to a few minutes). If the SD card gets mounted, it always gets successfully written to.
Code Changes
I downloaded the code located on your website, which I did notice was out of date. I had to implement the fix on #25. I did some other changes as well so unnecessary includes didn't mess up the build.
Once the build worked, the mount was failing every time, it boiled down to the
select()
function infatfs_sd.c
on line 158. The timeout number was too shortif (wait_ready(500))
, I changed it to10000
, and then sometimes the disk would get mounted. It takes about ~3 seconds every time it works.My Code
This is the code I used to write to the SD card. https://github.com/enochtsang/STM32F405RGT6_SdSpiWriteExample
These are the defines I used in my
defines.h
file.And the initialization parameters for the SPI peripheral.
Questions
So with all that, I have two things I would like to ask.
Is increasing the timeout a change suitable to this repo? I can see how it might not because FatFS is a third party library. But if it is, I'd happily make a pull request for it.
Based on my setup, is there any red flags for instability with the SD card? Do you have any ideas for how to increase the stability of writing to the SD card?