Skip to content

Commit 85c1d90

Browse files
Pavlo Hamovnashif
authored andcommitted
drivers: i2c: stm32_Slave: Fix addr flag handling
In the main Addr handler code the F1 workaround was used. Add compile time swith depending on SOC family. So workaround is not afffecting F2/F4 families. Signed-off-by: Pavlo Hamov <[email protected]>
1 parent 55ace13 commit 85c1d90

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/i2c/i2c_ll_stm32_v1.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,32 @@ static inline void handle_addr(struct device *dev)
210210
}
211211
}
212212

213-
if (data->current.is_write || data->current.len > 2) {
213+
if (data->current.is_write) {
214214
LL_I2C_ClearFlag_ADDR(i2c);
215215
return;
216216
}
217-
if (data->current.len == 0U) {
217+
/* according to STM32F1 errata we need to handle these corner cases in
218+
* specific way.
219+
* Please ref to STM32F10xxC/D/E I2C peripheral Errata sheet 2.14.1
220+
*/
221+
if (data->current.len == 0U && IS_ENABLED(CONFIG_SOC_SERIES_STM32F1X)) {
218222
LL_I2C_GenerateStopCondition(i2c);
219-
LL_I2C_ClearFlag_ADDR(i2c);
220223
} else if (data->current.len == 1U) {
221224
/* Single byte reception: enable NACK and clear POS */
222225
LL_I2C_AcknowledgeNextData(i2c, LL_I2C_NACK);
226+
#ifdef CONFIG_SOC_SERIES_STM32F1X
223227
LL_I2C_ClearFlag_ADDR(i2c);
224228
LL_I2C_GenerateStopCondition(i2c);
229+
#endif
225230
} else if (data->current.len == 2U) {
226-
/* 2-byte reception: enable NACK and set POS */
231+
#ifdef CONFIG_SOC_SERIES_STM32F1X
227232
LL_I2C_ClearFlag_ADDR(i2c);
233+
#endif
234+
/* 2-byte reception: enable NACK and set POS */
228235
LL_I2C_AcknowledgeNextData(i2c, LL_I2C_NACK);
229236
LL_I2C_EnableBitPOS(i2c);
230237
}
238+
LL_I2C_ClearFlag_ADDR(i2c);
231239
}
232240

233241
static inline void handle_txe(struct device *dev)

0 commit comments

Comments
 (0)