SPI MMC attempt.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

SPI MMC attempt.

Post by rew »

Hi,

I'm trying to get MMC over SPI to work. My system crashes in spiUnselect when trying to initialize the SPI module:

Code: Select all

Breakpoint 1, chSysHalt (
    reason=reason@entry=0x8005034 <__func__.7105> "spiUnselect")
    at chibios/os/rt/src/chsys.c:192
192     void chSysHalt(const char *reason) {
(gdb) up
#1  0x08000e78 in spiUnselect (spip=spip@entry=0x20000b00 <SPID2>)
    at chibios/os/hal/src/hal_spi.c:156
156       osalDbgCheck(spip != NULL);
(gdb) print spip
$8 = (SPIDriver *) 0x20000b00 <SPID2>
(gdb)
What could be wrong? The panic happens at: osalDbgCheck(spip != NULL); which as far as I can tell should not be happening. (instead of letting mmcStart crash I now have: spiUnselect (&SPID2); simply in my main, and that crashes....).
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI MMC attempt.

Post by Giovanni »

Is the CS pin correctly configured in the SPIConfig structure?

spiUnselect() just calls PAL for pin set.

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: SPI MMC attempt.

Post by rew »

WOW! I can read from the SD card! (raw blocks for now. (*))

In the end it was something with calling mmcStart with an mmc config structure. The example calls with "NULL" implying it works with a default config in that case, but apparently it doesn't. Why I seem to be getting offsets in the errors I don't know.

(*) My goal is to write logfiles. If fatfs doesn't work on first try, I might fall back to writing raw records on the SD card...

[edit] Suggestion: The examples should be "robust", i.e. leave little to chance to make it work as easily as possible. So I would prefer the example SPI hs_config to be "slow" (I now have it at 1.5MHz) and a comment indicating that it usually works a lot faster too. In my case with 15cm cable to my logic analyser board, and then 15cm to the logic analyser and 20cm to the actual SD card, it didn't work at the highest speed. And it was confusing at first (for a few seconds) as my logic analyser couldn't keep up....
Post Reply