cancel
Showing results for 
Search instead for 
Did you mean: 

I2C causes STM32F051 to crash/reboot

evert2
Associate II
Posted on November 29, 2013 at 16:07

Hello,

I've an STM32F051 where i2c modules can be connected (SFP video modules)

These modules should be hot swappable, however it seems that the I2C communication is not dealing properly with these modules because sometimes a crash or reboot occurs when I plugin a i2c module.

I use next code to check if a I2C module is available, only when this check succeeded I retrieve some data from that specified module.

It looks like the crash occurs during this routine, which I borrowed from the LM75 example. Does someone have any idea what might go wrong?

Thanks in advance,

Evert Huijben

ErrorStatus SFP_GetStatus(I2C_TypeDef* I2Cx, uint8_t I2Caddr)

{

   uint32_t I2C_TimeOut = I2C_TIMEOUT;

  /* Configure slave address, nbytes, reload, end mode and start or stop generation */

  I2C_TransferHandling(I2Cx, I2Caddr, 0, I2C_AutoEnd_Mode, I2C_No_StartStop);

  /* Clear NACKF and STOPF */

  I2C_ClearFlag(I2Cx, I2C_ICR_NACKCF | I2C_ICR_STOPCF);

  /* Generate start */

  I2C_GenerateSTART(I2Cx, ENABLE);

  /* Wait until timeout elapsed */

  while ((I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) && (I2C_TimeOut-- != 0));

  /* Check if Temp sensor is ready for use */

  if ((I2C_GetFlagStatus(I2Cx, I2C_ISR_NACKF) != RESET) || (I2C_TimeOut == 0))

  {

    /* Clear NACKF and STOPF */

    I2C_ClearFlag(I2Cx, I2C_ICR_NACKCF | I2C_ICR_STOPCF);

    return ERROR;

  }

  else

  {

    /* Clear STOPF */

    I2C_ClearFlag(I2Cx, I2C_ICR_STOPCF);

    return SUCCESS;

  }

}

#stm32f051-i2c-crash
18 REPLIES 18
emalund
Associate III
Posted on November 30, 2013 at 14:44

  do you get to this line?

while ((I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) && (I2C_TimeOut-- != 0));

if yes, reduce the timeout
emalund
Associate III
Posted on November 30, 2013 at 22:20

The above based on crash/reboot being a WD timeout

evert2
Associate II
Posted on December 09, 2013 at 09:33

Hi,

No watchdog is implemented,

and it is very difficult to debug this code because only once in a while this problem appears.

I've seen sometimes the board reboots and sometimes a got a hangup.

Does anyone know if the ST code can manage a hot swappable i2c line?

Or should I implement a WD?

Evert Huijben

chen
Associate II
Posted on December 09, 2013 at 11:01

Hi

Reading about your problem - I suspect the problem may not be software.

It is more likely to be Electrical.

You said the modules are 'hot swappable'

It is very likely that when you connect one of these modules - the voltage

rail is being disturbed (introduced some noise).

There is no telling what this may do to the STM32.

The whole 'Hot swapping' thing has to be carefully designed electrically.

The way USB does it is that the power is controlled through software.

Only when a device is confirmed as being connected does the bus apply power.

This is done through a USB HUB device, which decouples the power bus.

I2C is not a very good bus to use for hot swapping.

I2C is a terrible bus to use externally (route the I2C bus outside of the enclosure).

evert2
Associate II
Posted on December 09, 2013 at 11:24

Hi,

That was also my first thing I thougt about,

However, I've measured the power with my scope and I can't find any peak or dip during this crash. When I trigger my scope for a voltage drop, no drops are found.

Regards,

Evert Huijben

chen
Associate II
Posted on December 10, 2013 at 12:39

What is the evidence for a reboot?

What is the evidence for a hang?

Unless you capture a scope trace of power lines for a reboot and hang - you do not have evidence that it is not the power.

A quick google of 'I2C hot swap' shows that various chip vendors do buffer chips to enable hot swappable I2C.

I strongly suspect that the STM32 is not capable of handling Hot swapping on the I2C bus. The STM32 is probably not going to like the disturbance on power or I2C lines.

Try using one of these buffer chips.

chen
Associate II
Posted on December 10, 2013 at 12:41

What is the evidence for a reboot?

What is the evidence for a hang?

Unless you capture a scope trace of power lines for a reboot and hang - you do not have evidence that it is not the power.

A quick google of 'I2C hot swap' shows that various chip vendors do buffer chips to enable hot swappable I2C.

I strongly suspect that the STM32 is not capable of handling Hot swapping on the I2C bus. The STM32 is probably not going to like the disturbance on power or I2C lines.

Try using one of these buffer chips.

frankmeyer9
Associate II
Posted on December 10, 2013 at 12:58

Try using one of these buffer chips.

 

I would avoid I2C hot-swap at all.

Any glitch on the bus, even in the normal voltage range, may cause a spurious state transition (start/stop/clock/etc.), which the peripheral unit is not really prepared to deal with.

evert2
Associate II
Posted on December 11, 2013 at 11:43

Thank you for all suggestions,

I'am sure the STM is rebooting because for debugging I use GPIO's and LED's and I see the program is reaching init states. I also have a bootloader, and I see the bootloader state is reached.

As I read all the suggestions, it looks like 'hot swapping' can disturb the micro. However if my device is rebooting and returns to it's original state it is not a very big issue.

But sometimes the device has a hangup. Debugging learns that the application has left and the bootloader is never started (which is done in case of a reboot). I have implemented a watchdog bus this is not helping. It looks like the watchdog is working because the application has left.

This is a bigger issue than the reboot.

Can anyone told me if it is possible that the micro has reached an undefined state?

Since this is an existing product, I cannot add a I2C buffer.

Since there are some doubts about the power supply I have measured this with an even better and faster scope. However the power stays very stable during a crash and reboot and I do not see any voltage drop or glitch during inserting a I2C module.

However, maybe the STM is not capable of handling how swappable I2C modules but I would like to resolve the hangup I described. Does anyone has any idea?

Regards,

Evert Huijben