Skip to contentSkip to conversation

i2c: stm32f7: fix clearing the control register

PATCH Superseded Jorge Ramirez-Ortiz 4 participants 9 messages Aug 15, 2022 – Sep 15, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 i2c: stm32f7: fix clearing the control register

Bits should be set to 0, not 1.

---
 drivers/i2c/stm32f7_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/stm32f7_i2c.c +1 -1
index bf2a6c9b4b..3a727e68ac 100644
@@ -413,7 +413,7 @@ static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv)
 		setbits_le32(&regs->icr, STM32_I2C_ICR_STOPCF);
 
 		/* Clear control register 2 */
-		setbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
+		clrbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
 	}
 
 	return ret;
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 i2c: stm32f7: do not set the STOP condition on error

Sending the stop condition without waiting for transfer complete has been found to lock the bus (BUSY) when NACKF is raised.

Tested accessing the NXP SE05X I2C device.
https://www.nxp.com/docs/en/application-note/AN12399.pdf

---
 drivers/i2c/stm32f7_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/stm32f7_i2c.c +5 -3
index 3a727e68ac..14827e5cec 100644
@@ -485,9 +485,11 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv,
 		}
 	}
 
-	/* End of transfer, send stop condition */
-	mask = STM32_I2C_CR2_STOP;
-	setbits_le32(&regs->cr2, mask);
+	if (!ret) {
+		/* End of transfer, send stop condition */
+		mask = STM32_I2C_CR2_STOP;
+		setbits_le32(&regs->cr2, mask);
+	}
 
 	return stm32_i2c_check_end_of_message(i2c_priv);
 }
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCHv2 2/2] i2c: stm32f7: do not set the STOP condition on error

+Alain

Alain, can you have a look a this patch and give your feedback on it.

On my side i tested it on stm32mp157c-ev1 and stm32mp157c-dk2, i didn't see any regression but i prefer to get expert feedback ;-)

Thanks
Patrice

Quoted 31 lines · Jorge Ramirez-Ortiz

Sending the stop condition without waiting for transfer complete has been found to lock the bus (BUSY) when NACKF is raised.

Tested accessing the NXP SE05X I2C device.
https://www.nxp.com/docs/en/application-note/AN12399.pdf

---
 drivers/i2c/stm32f7_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/stm32f7_i2c.c +5 -3
index 3a727e68ac..14827e5cec 100644
@@ -485,9 +485,11 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv,
 		}
 	}
 
-	/* End of transfer, send stop condition */
-	mask = STM32_I2C_CR2_STOP;
-	setbits_le32(&regs->cr2, mask);
+	if (!ret) {
+		/* End of transfer, send stop condition */
+		mask = STM32_I2C_CR2_STOP;
+		setbits_le32(&regs->cr2, mask);
+	}
 
 	return stm32_i2c_check_end_of_message(i2c_priv);
 }
#3 lore raw

Re: [PATCHv2 2/2] i2c: stm32f7: do not set the STOP condition on error

In reply to Jorge Ramirez-Ortiz

+Alain (with the correct email address ;-))

Alain, can you have a look a this patch and give your feedback on it.

On my side i tested it on stm32mp157c-ev1 and stm32mp157c-dk2, i didn't see any regression but i prefer to get expert feedback

Thanks
Patrice

Quoted 31 lines · Jorge Ramirez-Ortiz

Sending the stop condition without waiting for transfer complete has been found to lock the bus (BUSY) when NACKF is raised.

Tested accessing the NXP SE05X I2C device.
https://www.nxp.com/docs/en/application-note/AN12399.pdf

---
 drivers/i2c/stm32f7_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/stm32f7_i2c.c +5 -3
index 3a727e68ac..14827e5cec 100644
@@ -485,9 +485,11 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv,
 		}
 	}
 
-	/* End of transfer, send stop condition */
-	mask = STM32_I2C_CR2_STOP;
-	setbits_le32(&regs->cr2, mask);
+	if (!ret) {
+		/* End of transfer, send stop condition */
+		mask = STM32_I2C_CR2_STOP;
+		setbits_le32(&regs->cr2, mask);
+	}
 
 	return stm32_i2c_check_end_of_message(i2c_priv);
 }
#4 lore raw

Re: [PATCHv2 2/2] i2c: stm32f7: do not set the STOP condition on error

Hi,

I confirm that a fix is necessary regarding this setting of the stop condition. As a matter of fact, the controller is already sending the stop condition in case of NACK so there is no need to send the stop condition.
However, this fix is not enough since the nack could be detected few lines above

	if (status & (STM32_I2C_ISR_NACKF | STM32_I2C_ISR_ERRORS))
		break;

and in this case the current check would not catch it.

I propose to set the STOP condition upon handling of the transfer complete.

I've put this fix within a small 3 patches series that I'm going to send, could you check it to confirm this fixes the issue ?

Regards,
Alain

Quoted 42 lines · Patrice CHOTARD

+Alain (with the correct email address ;-))

Alain, can you have a look a this patch and give your feedback on it.

On my side i tested it on stm32mp157c-ev1 and stm32mp157c-dk2, i didn't see any regression but i prefer to get expert feedback

Thanks
Patrice

Quoted 31 lines · Jorge Ramirez-Ortiz

Sending the stop condition without waiting for transfer complete has been found to lock the bus (BUSY) when NACKF is raised.

Tested accessing the NXP SE05X I2C device.
https://www.nxp.com/docs/en/application-note/AN12399.pdf

---
 drivers/i2c/stm32f7_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/stm32f7_i2c.c +5 -3
index 3a727e68ac..14827e5cec 100644
@@ -485,9 +485,11 @@ static int stm32_i2c_message_xfer(struct stm32_i2c_priv *i2c_priv,
 		}
 	}
 
-	/* End of transfer, send stop condition */
-	mask = STM32_I2C_CR2_STOP;
-	setbits_le32(&regs->cr2, mask);
+	if (!ret) {
+		/* End of transfer, send stop condition */
+		mask = STM32_I2C_CR2_STOP;
+		setbits_le32(&regs->cr2, mask);
+	}
 
 	return stm32_i2c_check_end_of_message(i2c_priv);
 }
#5 lore raw

Re: [PATCHv2 2/2] i2c: stm32f7: do not set the STOP condition on error

Hi,

Quoted 17 lines · Alain Volmat

Hi,

I confirm that a fix is necessary regarding this setting of the stop condition. As a matter of fact, the controller is already sending the stop condition in case of NACK so there is no need to send the stop condition.
However, this fix is not enough since the nack could be detected few lines above

	if (status & (STM32_I2C_ISR_NACKF | STM32_I2C_ISR_ERRORS))
		break;

and in this case the current check would not catch it.

I propose to set the STOP condition upon handling of the transfer complete.

Quoted 30 lines

I've put this fix within a small 3 patches series that I'm going to send, could you check it to confirm this fixes the issue ?

Regards,
Alain

Quoted 23 lines · Patrice CHOTARD

+Alain (with the correct email address ;-))

Alain, can you have a look a this patch and give your feedback on it.

On my side i tested it on stm32mp157c-ev1 and stm32mp157c-dk2, i didn't see any regression but i prefer to get expert feedback

Thanks
Patrice

Quoted 12 lines · Jorge Ramirez-Ortiz

Sending the stop condition without waiting for transfer complete has been found to lock the bus (BUSY) when NACKF is raised.

Tested accessing the NXP SE05X I2C device.
https://www.nxp.com/docs/en/application-note/AN12399.pdf

---
  drivers/i2c/stm32f7_i2c.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)

For reference, this patch is superseded by Alain Volmat patch:

[v2,1/3] i2c: stm32: fix comment and remove unused AUTOEND bit

http://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

in the serie "i2c: stm32: cleanup & stop handling fix"

http://patchwork.ozlabs.org/project/uboot/list/?series=317443&state=*

Regards

Patrick

Reviewed-by on v2 1/2
#6 lore raw
In reply to Jorge Ramirez-Ortiz

Hi Jorge

Quoted 12 lines · Jorge Ramirez-Ortiz

Bits should be set to 0, not 1.

---
 drivers/i2c/stm32f7_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/stm32f7_i2c.c +0 -0
index bf2a6c9b4b..3a727e68ac 100644

drivers/i2c/stm32f7_i2c.c static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv) · line 419

Quoted 8 lines
drivers/i2c/stm32f7_i2c.c +1 -1
@@ -413,7 +413,7 @@ static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv)
 		setbits_le32(&regs->icr, STM32_I2C_ICR_STOPCF);
 
 		/* Clear control register 2 */
-		setbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
+		clrbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
 	}
 
 	return ret;

Thanks
Patrice

Reviewed-by on v2 1/2
#7 lore raw
In reply to Jorge Ramirez-Ortiz

Hi,

Quoted 12 lines · Jorge Ramirez-Ortiz

Bits should be set to 0, not 1.

---
  drivers/i2c/stm32f7_i2c.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/stm32f7_i2c.c +0 -0
index bf2a6c9b4b..3a727e68ac 100644

drivers/i2c/stm32f7_i2c.c static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv) · line 419

Quoted 8 lines
drivers/i2c/stm32f7_i2c.c +1 -1
@@ -413,7 +413,7 @@ static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv)
  		setbits_le32(&regs->icr, STM32_I2C_ICR_STOPCF);
 
  		/* Clear control register 2 */
-		setbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
+		clrbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
  	}
 
  	return ret;

Thanks
Patrick

#8 lore raw
In reply to Jorge Ramirez-Ortiz

Hi,

Quoted 12 lines · Jorge Ramirez-Ortiz

Bits should be set to 0, not 1.

---
  drivers/i2c/stm32f7_i2c.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/stm32f7_i2c.c +0 -0
index bf2a6c9b4b..3a727e68ac 100644

drivers/i2c/stm32f7_i2c.c static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv) · line 419

Quoted 8 lines
drivers/i2c/stm32f7_i2c.c +1 -1
@@ -413,7 +413,7 @@ static int stm32_i2c_check_end_of_message(struct stm32_i2c_priv *i2c_priv)
  		setbits_le32(&regs->icr, STM32_I2C_ICR_STOPCF);
 
  		/* Clear control register 2 */
-		setbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
+		clrbits_le32(&regs->cr2, STM32_I2C_CR2_RESET_MASK);
  	}
 
  	return ret;

Applied to u-boot-stm/master, thanks!

Regards
Patrick