2014-01-29 11:24 PM
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=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx?Paged%3DTRUE%26p_StickyPost%3D%26p_DiscussionLastUpdated%3D20131123%252019%253a04%253a04%26p_ID%3D35679%26View%3D%257bF47A9ED8%252dE726%252d42BE%252dACED%252d732F13B66581%257d%26FolderCTID%3D0x012001%26PageFirstRow%3D481¤tviews=79]Bug in USB
#cpal
2024-09-25 02:42 AM
I found this bug too, thank you for the solution!