MMC_SPI problems on STM32

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
CheBuzz
Posts: 17
Joined: Mon Dec 12, 2011 4:17 am

Re: MMC_SPI problems on STM32

Post by CheBuzz »

And I finally figured out what the problem was. As best as I can determine, I was trying to read the card too soon before power was applied. Changing MMC_POLLING_DELAY to 100 and MMC_POLLING_INTERVAL to 10 in halconf.h allowed enough time after power up to get everything working well.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: MMC_SPI problems on STM32

Post by Giovanni »

Looking at your code: You don't need to do spiObjectInit(), it is a static driver and the object is already initialized, however I doubt this is your problem. Your thread also seems to access the MMC before an insertion event initialized it using mmcConnect(). Apparently you do f_open() before the mmcConnect() executes, the order of operations is not respected.

In general I can only recommend sticking to the STM32F103 FatFS demo code as-is, at least initially, and running with all debug options activated in order to catch possible errors.

Giovanni
CheBuzz
Posts: 17
Joined: Mon Dec 12, 2011 4:17 am

Re: MMC_SPI problems on STM32

Post by CheBuzz »

I initially did follow the example almost exactly. Those were things I had added in my initial debugging before hooking up the logic analyzer. The problem was trying to talk to the SD card too soon after power was applied. The SD card simply never responded. The moment I changed the polling interval and the insertion events required before initialization, it came up just fine.

I wonder if this is a common problem for people who power up with the card already inserted or if it is unique to my board/SD card.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: MMC_SPI problems on STM32

Post by Giovanni »

If you work with a card always inserted then a good approach would be to call mmcConnect() until it is successful (may be with a 100mS delay between calls) without messing with the timers.

Giovanni
noether
Posts: 91
Joined: Wed Nov 16, 2011 3:18 pm

Re: MMC_SPI problems on STM32

Post by noether »

CheBuzz wrote:I initially did follow the example almost exactly. Those were things I had added in my initial debugging before hooking up the logic analyzer. The problem was trying to talk to the SD card too soon after power was applied. The SD card simply never responded. The moment I changed the polling interval and the insertion events required before initialization, it came up just fine.

I wonder if this is a common problem for people who power up with the card already inserted or if it is unique to my board/SD card.


If your board/application allows to remove/insert SD cards in a hot way, it might to be useful to employ the card present pin, then read the SD card datasheet for knowing its start-up time, and multiply it by two for waiting until call the mmcConnect routine.
Post Reply