Page 1 of 1

SD SPI breaks after i2cStart

Posted: Tue May 21, 2013 11:34 pm
by toxygen
Hello,
I'm working on logging to sd card over spi using 2.4.3 kernel. SD card is mounted only if I don't call i2cStart() before. If I call i2cStart(), the initialisation never occurs.

I have separate sd insertion/removal monitoring thread:

Code: Select all

static WORKING_AREA(waSDcard_monitor, 128);
static msg_t t_SDcard_monitor(void *arg) {
   (void)arg;
   
   chEvtRegister(&MMCD1.inserted_event, &el0, 0);
   chEvtRegister(&MMCD1.removed_event, &el1, 1);
   
   while (TRUE) {
      chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
   }

   return (msg_t) 0;
}


I2C stuff:

Code: Select all

static const I2CConfig i2cfg1 = {
    OPMODE_I2C,
    400000,              /* 400 kHz */
    FAST_DUTY_CYCLE_2,
};

void I2CInit_pns(){
   i2cStart(&I2CD2, &i2cfg1);
   chThdSleepMilliseconds(100);
}


It doesn't matter if I call i2cStart() before creating the thread of afterwards. Any idea what interaction between these two can be?

Re: SD SPI breaks after i2cStart

Posted: Wed May 22, 2013 8:40 am
by Giovanni
Hi,

Most likely because the two drivers are defaulted to a common DMA channel. The STM32 has more peripherals than channels. You have 2 alternatives:
1) Remap I2C on an alternate channel (see the RM, not all channels can be used as alternate), you do this in mcuconf.h.
2) Do not use SDC and I2C at the same time, one one must be in started state, you need to stop before starting the other one.

Giovanni

Re: SD SPI breaks after i2cStart

Posted: Wed May 22, 2013 11:03 pm
by toxygen
Thanks for the reply, I will try and post the results