Page 1 of 1

SPI MMC attempt.

Posted: Sun Sep 04, 2016 4:36 pm
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....).

Re: SPI MMC attempt.

Posted: Sun Sep 04, 2016 4:46 pm
by Giovanni
Is the CS pin correctly configured in the SPIConfig structure?

spiUnselect() just calls PAL for pin set.

Giovanni

Re: SPI MMC attempt.

Posted: Sun Sep 04, 2016 7:27 pm
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....