Question
How to fix CPAL timeout problem
Posted on January 16, 2014 at 05:33
Hi,
My problem is similar to the following: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/CPAL%20Spin%20Waits%20in%20Interupt 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 */ __CPAL_I2C_TIMEOUT(!(__CPAL_I2C_HAL_GET_BUSY(pDevInitStruct->CPAL_Dev)), CPAL_I2C_TIMEOUT_BUSY); 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 #freeze #cpal #__cpal_i2c_timeout