i2c driver problem after resume from standby

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

Moderator: RoccoMarco

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

i2c driver problem after resume from standby

Post by enrico.dallavia »

Good evening,
I'm using a stm32 f429 chip, I have some peripherals which I control with i2c bus (I2CD1). When I first flash the device, all is working. But today I need to implement the standby, and now I am facing a problem. When the system restarts after an interrupt on pin0, the systems hangs (means no more thread working) when I make a call to i2c.

Code: Select all

i2cAcquireBus(&I2CD1);
status = i2cMasterTransmitTimeout(&I2CD1, isl29020_addr, txbuf, 2, rxbuf, 0, tmo);


the call to i2cAcquireBus(&I2CD1); works, means the system continues to working if for example I make a cycle like this:

Code: Select all

int i = 0;
do{
chThdSleepMilliseconds(250);
}while(i++ < 50);


but it hangs at i2cMasterTransmitTimeout.
From what I know, after a standby, everything is resetted (exept for the backup sram), so it is likely a start after reset.

does anyone know where could be the problem? I'm quite troubled by now!

Thanks a lot.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: i2c driver problem after resume from standby

Post by Giovanni »

Try stopping drivers before entering the standby mode. After reset everything should be reinitialized.

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

Re: i2c driver problem after resume from standby

Post by enrico.dallavia »

Thanks for the suggestion!
Is there any other driver that needs to be stopped before going to standby? like spi or exti ?
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: i2c driver problem after resume from standby

Post by enrico.dallavia »

Sorry, you wrote drivers, that means all drivers should be stopped before go to standby.
enrico.dallavia
Posts: 105
Joined: Thu Mar 12, 2015 10:15 am
Has thanked: 2 times

Re: i2c driver problem after resume from standby

Post by enrico.dallavia »

I make a call to i2cStop(&I2CD1); just before go to standby.
unfortunately the problem still here, system hangs :(
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: i2c driver problem after resume from standby

Post by Giovanni »

Is it just I2C? do other peripherals work?

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

Re: i2c driver problem after resume from standby

Post by enrico.dallavia »

I've tried SPI,

Code: Select all

  unsigned char header_master[2] = {0x0a, 0x00};
        unsigned char header_slave[2]  = {0xaa, 0x00};

        chprintf((BaseSequentialStream *)&SERIAL_PORT, "SPI\r\n");
        chThdSleepMilliseconds(300);

        spiStart(&SPID3, &spiCfg);

        spiAcquireBus(&BLUE_NRG_SPI);

        spiSelect(&BLUE_NRG_SPI);

        spiExchange(&BLUE_NRG_SPI, 1, header_master, header_slave);

        spiUnselect(&BLUE_NRG_SPI);

        spiReleaseBus(&BLUE_NRG_SPI);


It works, or at least it does not hang.

After I wrote a i2c call

Code: Select all


..........
 spiReleaseBus(&BLUE_NRG_SPI);

 chprintf((BaseSequentialStream *)&SERIAL_PORT, "i2c\r\n");

 int ret = i2cMasterTransmit(&I2CD1, 0, &ch, 1, 0, 0);


it hangs (from serial I can only see "i2")
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: i2c driver problem after resume from standby

Post by Giovanni »

Assuming that the code is correct, this makes me think to an HW origin for this issue because it seems to affect I2C only. You may try to reset I2C using RCC after exiting the standby mode.

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

Re: i2c driver problem after resume from standby

Post by enrico.dallavia »

Thanks, I wil try and let you know.

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

Re: i2c driver problem after resume from standby

Post by enrico.dallavia »

Nope,

Code: Select all

RCC->APB1RSTR |= 0x00200000; // Reset i2c peripheral
RCC->APB1RSTR &= 0xFFDFFFFF;

i2cStart(&I2CD1, &i2cfg1);

chprintf((BaseSequentialStream *)&SERIAL_PORT, "i2c\r\n");
int ret = i2cMasterTransmit(&I2CD1, 0, &ch, 1, 0, 0);


still hangs :(

and I give a i2cStop before go to standby

ps: the driver already calls a rccResetI2C1(); inside i2c_lld_start, so I guess what I've done is not necessary
Post Reply