2013-11-29 07:07 AM
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 HuijbenErrorStatus 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-crash2013-11-30 05:44 AM
do you get to this line?
while ((I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) && (I2C_TimeOut-- != 0)); if yes, reduce the timeout2013-11-30 01:20 PM
The above based on crash/reboot being a WD timeout
2013-12-09 12:33 AM
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 Huijben2013-12-09 02:01 AM
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).2013-12-09 02:24 AM
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 Huijben2013-12-10 03:39 AM
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.2013-12-10 03:41 AM
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.2013-12-10 03:58 AM
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.
2013-12-11 02:43 AM
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