AnsweredAssumed Answered

How to fix CPAL timeout problem

Question asked by l.d.001 on Jan 16, 2014
Latest reply on Jan 16, 2014 by l.d.001
My problem is similar to the following:

My device used to freeze and have watchdog triggered.
I found that it is freezing in one of numerous __CPAL_I2C_TIMEOUT in cpal_i2c.c V1.2.0 21-December-2012,
like this one:
uint32_t CPAL_I2C_ER_IRQHandler(CPAL_InitTypeDef* pDevInitStruct)
      /* Wait until Busy flag is reset */

I see that there are several other places, where  __CPAL_I2C_TIMEOUT can be invoked from ISR.

I found that the original authors of my application  missed the following comment in cpal_i2c_hal_stm32f10x.h:
"The timeout mechanism interrupt priority should be the highest one and it should be able to interrupt any other ISR."
Also there is a recommendation to use 1ms tick.
But our application was designed with low priority 10 ms systick. This explains the freeze.

Now I wonder whether I should change systick interrupt priority and interval to be 1 ms and priority above I2C.
But it does not sound right to me.
I2C errors (like this busy flag) are really rare. Why should I interrupt important processes every 1 ms just to handle this rare event?
And even if I will do it, still my board will freeze for 1 ms.

I kind of always believed that interrupt routines should be short and have some reasonable maximum execution time,
but it appears that CPAL library has numerous places that may have unpredictably long busy loops or even infinite if one does not have high priority systick.
What is the proper way to fix it?

Thank you