Author Topic: Getting FATFS working on the STM32.  (Read 7823 times)

0 Members and 1 Guest are viewing this topic.

Offline BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 266
Getting FATFS working on the STM32.
« on: April 25, 2016, 08:43:05 pm »
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
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26751
  • Country: nl
    • NCT Developments
Re: Getting FATFS working on the STM32.
« Reply #1 on: April 25, 2016, 08:47:01 pm »
Did you measure the lines to the SD card using a scope?
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 266
Re: Getting FATFS working on the STM32.
« Reply #2 on: April 25, 2016, 09:01:06 pm »
Did you measure the lines to the SD card using a scope?

I'm not really able to do as I'm using a custom PCB with lines hidden well. What were you thinking?
 

Offline BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 266
Re: Getting FATFS working on the STM32.
« Reply #3 on: April 25, 2016, 09:02:11 pm »
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.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26751
  • Country: nl
    • NCT Developments
Re: Getting FATFS working on the STM32.
« Reply #4 on: April 25, 2016, 09:14:51 pm »
Did you measure the lines to the SD card using a scope?
I'm not really able to do as I'm using a custom PCB with lines hidden well. What were you thinking?
Seeing 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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Getting FATFS working on the STM32.
« Reply #5 on: April 25, 2016, 09:55:02 pm »
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.
 

Offline richardman

  • Frequent Contributor
  • **
  • Posts: 427
  • Country: us
Re: Getting FATFS working on the STM32.
« Reply #6 on: April 25, 2016, 10:51:43 pm »
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.
// richard http://imagecraft.com/
JumpStart C++ for Cortex (compiler/IDE/debugger): the fastest easiest way to get productive on Cortex-M.
Smart.IO: phone App for embedded systems with no app or wireless coding
 

Offline bktemp

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: de
Re: Getting FATFS working on the STM32.
« Reply #7 on: April 26, 2016, 04:55:30 am »
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.
 

Offline BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 266
Re: Getting FATFS working on the STM32.
« Reply #8 on: April 26, 2016, 05:51:59 pm »
Did you measure the lines to the SD card using a scope?
I'm not really able to do as I'm using a custom PCB with lines hidden well. What were you thinking?
Seeing 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.

Okay, 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!
 

Offline BoscoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 266
Re: Getting FATFS working on the STM32.
« Reply #9 on: April 26, 2016, 08:02:25 pm »
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 now :( and not at any clock setting :(. Maybe a fluke? not sure!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf