Skip to content

Commit 2252e36

Browse files
committed
i2c: i2c_ll_stm32_v2: fix NACK handling for STM32L4
On STM32F0/F3/L0/L4, a NACK on the I2C bus triggers an I2C event interrupt. But the current logic expects an I2C error interrupt. As a result, the NACK interrupt is not acknowledged and leads to an IRQ storm which freezes the system. Move the NACK handling code to the event ISR. Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
1 parent 06840af commit 2252e36

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/i2c/i2c_ll_stm32_v2.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ void stm32_i2c_event_isr(void *arg)
117117
error:
118118
LL_I2C_DisableIT_TX(i2c);
119119
LL_I2C_DisableIT_RX(i2c);
120-
data->current.is_err = 1;
120+
121+
if (LL_I2C_IsActiveFlag_NACK(i2c)) {
122+
LL_I2C_ClearFlag_NACK(i2c);
123+
data->current.is_nack = 1;
124+
} else {
125+
data->current.is_err = 1;
126+
}
127+
121128
k_sem_give(&data->device_sync_sem);
122129
}
123130

@@ -128,12 +135,7 @@ void stm32_i2c_error_isr(void *arg)
128135
struct i2c_stm32_data *data = DEV_DATA((struct device *)arg);
129136
I2C_TypeDef *i2c = cfg->i2c;
130137

131-
if (LL_I2C_IsActiveFlag_NACK(i2c)) {
132-
LL_I2C_ClearFlag_NACK(i2c);
133-
data->current.is_nack = 1;
134-
} else {
135-
data->current.is_err = 1;
136-
}
138+
data->current.is_err = 1;
137139

138140
k_sem_give(&data->device_sync_sem);
139141
}

0 commit comments

Comments
 (0)