From 617c91b3736fdfb55abf50faf7be4ee3304cfbec Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Tue, 12 Sep 2017 13:40:49 -1000 Subject: [PATCH] stm32:stm32f40xxx I2C ensure proper error handling. Injecting data errors would cause the driver to continually reenter the isr with BERR an RxNE. This fix allows the error to be cleared and propagated to the waiting task. --- arch/arm/src/stm32/stm32f40xxx_i2c.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm/src/stm32/stm32f40xxx_i2c.c b/arch/arm/src/stm32/stm32f40xxx_i2c.c index da50766f3f..72b1bc2031 100644 --- a/arch/arm/src/stm32/stm32f40xxx_i2c.c +++ b/arch/arm/src/stm32/stm32f40xxx_i2c.c @@ -2018,6 +2018,20 @@ static int stm32_i2c_isr_process(struct stm32_i2c_priv_s *priv) * the ISR cycle to handle the sending/receiving of the messages. */ + /* First check for errors */ + + if ((status & I2C_SR1_ERRORMASK) != 0) + { + stm32_i2c_traceevent(priv, I2CEVENT_ERROR, status & I2C_SR1_ERRORMASK); + + /* Clear interrupt flags */ + + stm32_i2c_putreg(priv, STM32_I2C_SR1_OFFSET, 0); + + priv->dcnt = -1; + priv->msgc = 0; + } + if (priv->dcnt == -1 && priv->msgc == 0) { i2cinfo("Shutting down I2C ISR\n");