Getting FATFS working on the STM32. - Page 1
Forum section: electronics / general

author: Boscoe
author_rank: Frequent Contributor
timestamp: April 25, 2016, 08:43:05 pm
content: I've used STMCube to generate my base code for the STM32F429. All the code has initialized in the clocks and SDIO peripheral with FATFS middlewares. After stepping through the code all I get is SD_RSP_TIMEOUT. I'm using the example code from Chan for my main. I'm using 4bit SDIO and the default pins with external 47k pull-ups like in the 429-EVAL board. I've gone through the UM1721 'Developing Applications on STM32Cube with FatFs' documentation however none of the things in here make much sense either - or make it work!Any advice would be great!Thanks

author: nctnico
author_rank: Super Contributor
timestamp: April 25, 2016, 08:47:01 pm
content: Did you measure the lines to the SD card using a scope?

author: Boscoe
author_rank: Frequent Contributor
timestamp: April 25, 2016, 09:01:06 pm
content: Quote from: nctnico on April 25, 2016, 08:47:01 pmI'm not really able to do as I'm using a custom PCB with lines hidden well. What were you thinking?

author: Boscoe
author_rank: Frequent Contributor
timestamp: April 25, 2016, 09:02:11 pm
content: I've tried regenerating the code and now get FR_DISK_ERR with all three of my cards. really not sure what I could be doing wrong hardware wise.

author: nctnico
author_rank: Super Contributor
timestamp: April 25, 2016, 09:14:51 pm
content: Quote from: Boscoe on April 25, 2016, 09:01:06 pmSeeing the lines 'wiggle' when the SD card is accessed is a first indication the pins where setup correctly. Perhaps soldering some wires to the connector, pull-up resistors or microcontroller can help to find out whether the physical interface works.

author: andyturk
author_rank: Frequent Contributor
timestamp: April 25, 2016, 09:55:02 pm
content: I've used FATFS on STM32 before successfully under ChibiOS. Make sure your disks are formatted correctly. E.g., format them on a Windows machine to be sure. I think there's a format routine in FATFS itself, and that works too.Does your board have a FET or some way to power cycle the card? If so, make sure the card is getting power (duh!). I noticed that when the cards boot they'll often suck down a big gulp of current. If you see that pulse, it probably means the card is working. However, you'll want to make sure that the rest of the system isn't browning out somehow.

author: richardman
author_rank: Frequent Contributor
timestamp: April 25, 2016, 10:51:43 pm
content: ChanFS works fine on the STM32. I have done it a few times with both SDIO and SPI. The low level is in just one file. I will see if I can dig something up. I use JumpStart C of course (our compiler :-) ), but it's mostly Standard C code so you should be able to get it working on any compiler.

author: bktemp
author_rank: Super Contributor
timestamp: April 26, 2016, 04:55:30 am
content: FATFS works fine, but the code from ST has a few issues. I had to add some fixes in SD_PowerON function to make it work with all SD cards:- After __HAL_SD_SDIO_ENABLE(); there must be a small delay.- After Send CMD55 ignore SD_ILLEGAL_CMD response and continue. Without this mod some cards did not work.

author: Boscoe
author_rank: Frequent Contributor
timestamp: April 26, 2016, 05:51:59 pm
content: Quote from: nctnico on April 25, 2016, 09:14:51 pmOkay, so I managed to solder some probes onto the lines but everything looks good as far as I can tell.I get a lot of data sent in SPI mode to the card then the card replies the MCU replies to that. Then there's a period then twos lots of 4bit data transfer.I soldered some wires to an SD card and tested it on my STM32F4 discovery board and it worked absolutely fine - no pullups no other hardware just straight code right out of the STMCube generator then the ultra basic FatFs example in the main. Un soldered the wires and stuck it in the computer and the MCU had written the file. So I try exactly the same thing with my board - it doesn't work. All I initialized in STMCube was the SDIO peripheral and FATFS (just like the working one just for the 429 this time) and nothing! I've gone through the pinouts about 10 times checked continuity between the pins and the MCU and between the pins and pins to GND and 3V3 - measures fine. So all I can think it is now is the clock setup in the 429 or the SD card holder which I can't test because the only one I have is on the board!

author: Boscoe
author_rank: Frequent Contributor
timestamp: April 26, 2016, 08:02:25 pm
content: Okay I think it is something to do with the clocks. I have the I2S PLL clock set at 45MHz (i'm sure the SDIO clock is derived from this) so I quickly changed the PLL settings so it was 48MHz and it worked!!!!! I have the main clock at something like 70MHz so I made new settings so the I2S clock was 48MHz and the main clock 178MHz but it doesn't work nowand not at any clock setting. Maybe a fluke? not sure!