os 3.0.2 crash with extStart and i2cStart

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

os 3.0.2 crash with extStart and i2cStart

Post by enrico.dallavia »

Hello,
I'm very troubled of this problem I discovered today.
I have an application that use stmf429 with SPI,i2c and external interrupt.

the ext configuration is this one:

Code: Select all

const EXTConfig extcfg = {
{
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_RISING_EDGE | EXT_MODE_GPIOC, extcb1},//bluenrg
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_FALLING_EDGE  | EXT_MODE_GPIOG, extcbTouch},//capsense
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL},
    {EXT_CH_MODE_DISABLED, NULL}
}
};


the i2c config is this one:

Code: Select all

static const I2CConfig i2cfg1 = {
    OPMODE_I2C,
    100000,
    STD_DUTY_CYCLE,
};


I developed the feature to read from accelerometer from i2c and from bluenrg through spi in two different branches (so when I've used the accelerometer, I don't have bluenrg and viceversa). Today I put them together. But I have a big problem, the application crashes during initialization of the bluenrg (it involves a reset of the bluenrg chip that triggered an external interrupt).
If I'm avoiding to give i2cStart(&I2CD1, &i2cfg1); the bluenrg works and OS doesn't hang.
But if I gave i2cStart(&I2CD1, &i2cfg1); even without any other thread that try to use i2c, the system hangs almost immediately.

Is there any limitations about using i2c and exti driver?
Does anyone could give me a hint about what is happening?

Thanks a lot!
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: os 3.0.2 crash with extStart and i2cStart

Post by enrico.dallavia »

I've tried to delay the i2c start after the bluenrg is completely initialized, but having the same results

Code: Select all


    extStart(&EXTD1, &extcfg);
//start a thread to make a led blinking
    chThdCreateStatic(waThread10, sizeof(waThread10), NORMALPRIO, Thread10, NULL);
    chprintf((BaseSequentialStream *)&SERIAL_PORT, "\r\nApplication started!\r\n");

    BNRG_SPI_Init();

    chThdSleepMilliseconds(10000);

    i2cStart(&I2CD1, &i2cfg1);


after i2cStart the system stop working (that means the led stop to blink)
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: os 3.0.2 crash with extStart and i2cStart

Post by enrico.dallavia »

Could it be a problem having I2CD1 and SPID3 active at the same time, with same time I mean call i2cStart and spiStart in two different point of the program? only 1 time during the first setup. Or I have to call stop i2c before using spi and viceversa?
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: os 3.0.2 crash with extStart and i2cStart

Post by enrico.dallavia »

I found the problem! Or at least now it seems to work.
the "problem" was inside the dma settings

Code: Select all

#define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 6)


#define STM32_SPI_SPI3_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 0)
#define STM32_SPI_SPI3_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 7)


once I 've changed the dma settings of SPI3 to

Code: Select all

#define STM32_SPI_SPI3_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 2)


the hang of the system seems to be solved!

I hope I'm doing the right thing.
Anyway if guru have a comment, please tell me how to do it better. THANKS!
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: os 3.0.2 crash with extStart and i2cStart

Post by Giovanni »

DMA collision, you cannot use the same DMA channel on different peripheral.

Giovanni
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: os 3.0.2 crash with extStart and i2cStart

Post by enrico.dallavia »

Thanks for the clarification!
Post Reply