SD SPI breaks after i2cStart

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

Moderator: RoccoMarco

Post Reply
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

SD SPI breaks after i2cStart

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SD SPI breaks after i2cStart

Post 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
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

Re: SD SPI breaks after i2cStart

Post by toxygen »

Thanks for the reply, I will try and post the results
Post Reply