Skip to main content
Visitor II
February 28, 2023
Question

STM32F4 DSP and standard peripherals library - NEW bug in I2C_CheckEvent() ?

  • February 28, 2023
  • 2 replies
  • 1197 views

Reference manual RM0383, "STM32F411xC/E advanced ARM®-based 32-bit MCUs", says:

18.6.7 I2C Status register 2 (I2C_SR2) Note: Reading I2C_SR2 after reading I2C_SR1 clears the ADDR flag, even if the ADDR flag wasset after reading I2C_SR1.

 Consequently, I2C_SR2 must be read only when ADDR is found set in I2C_SR1 or when the STOPF bit is cleared.

 But theSTM32F4 DSP and standard peripherals library, STSW-STM32065, doesn't check if the flag STOPF is cleared in I2C_CheckEvent():

ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
{
 uint32_t lastevent = 0;
 uint32_t flag1 = 0, flag2 = 0;
 ErrorStatus status = ERROR;
 
 /* Check the parameters */
 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
 assert_param(IS_I2C_EVENT(I2C_EVENT));
 
 /* Read the I2Cx status register */
 flag1 = I2Cx->SR1;
 
 /* I2C_SR2 must be read only when ADDR is found set in I2C_SR1 or when the STOPF bit is cleared */
 if((flag1 & I2C_SR1_ADDR) || (flag1 & ~I2C_SR1_STOPF)) 
 {
 flag2 = I2Cx->SR2;
 }
 else 
 { 
 return ERROR; 
 }
 flag2 = flag2 << 16;

What is the meaning of this check?

(flag1 & ~I2C_SR1_STOPF)

This is not check if the flag STOPF is cleared in I2C_SR2, this is setting a bit to zero.

Maybe it would be more correct this?

( !(flag1 & I2C_SR1_STOPF))

    This topic has been closed for replies.

    2 replies

    Graduate II
    February 28, 2023

    Yes, I'd agree the test/logic here looks broken.

    Not sure the SPL is maintained at this point, it's use has been deprecated by ST for several years.

    Super User
    February 28, 2023

    > Not sure the SPL is maintained at this point

    This is a relatively new development. Looked at what I have archived, which was 1.7.0 and I2C_CheckEvent() there is different.

    Downloaded newest SPL v1.9.0 Changelog says nothing about v1.9.0....

    There's an entry for V1.8.1 / 27-January-2022. There's no V1.8.1 in the offerings.

    V1.8.1 / 27-January-2022 says:

     * stm32f4xx_i2c.c

       * Update I2C_CheckEvent() API to be aligned with the reference manual.

         * I2C_SR2 must be read only when ADDR is found set in I2C_SR1 or when the STOPF bit is cleared.  

    I mean, c'mon, ST.

    JW

    @Amel NASRI​ , can this please be rectified, thanks.