AnsweredAssumed Answered

Bug in CPAL_I2C_IsDeviceReady

Question asked by nrp on Jan 30, 2014
There is a bug in CPAL_I2C_IsDeviceReady that prevents it from ever returning failure.

/* wait until timeout elapsed or target device acknowledge its address*/
while ((__CPAL_I2C_HAL_GET_ADDR(pDevInitStruct->CPAL_Dev) == 0) && (Timeout-- != 0));
/* If Timeout occurred  */
if (Timeout == 0)
  return CPAL_FAIL;   

The post-decrement on Timeout means that it checks for zero, breaks the while, and then decrements Timeout to UINT32_MAX.  This means that the check for Timeout == 0 fails and results in a return of CPAL_PASS rather than CPAL_FAIL.

This can be fixed by pre-decrementing Timeout (among other possible fixes).

while ((__CPAL_I2C_HAL_GET_ADDR(pDevInitStruct->CPAL_Dev) == 0) && (--Timeout));

If there is a better place to post bug reports, please let me know.  I filed this issue on the USB library a few months ago and never got a response: [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Bug%20in%20USB%20library%20v4.0.0%20usb_prop.c&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=]Bug in USB