From 65068fb4dfbc4b0d5d8f0bbfbeef299bf7a9d20e Mon Sep 17 00:00:00 2001 From: Tim Woolliscroft Date: Fri, 24 Nov 2023 10:10:03 +0000 Subject: [PATCH] drivers: i2c: stm32: Fix routing of secondary target address Fixes the routing of the events associated with a secondary i2c target address being routed to the primary config. The i2c_target_config/slave_cfg was being selected from the driver address match but then over written by the primary. This change fully implements the if/else of 10bit addressing and includes a assert if the slave_cfg is NULL, and explains why dual 10bit addresses on STM32 won't work. Signed-off-by: Tim Woolliscroft --- drivers/i2c/i2c_ll_stm32_v2.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_ll_stm32_v2.c b/drivers/i2c/i2c_ll_stm32_v2.c index c75d68e4f19..8292b2f6738 100644 --- a/drivers/i2c/i2c_ll_stm32_v2.c +++ b/drivers/i2c/i2c_ll_stm32_v2.c @@ -142,9 +142,19 @@ static void stm32_i2c_slave_event(const struct device *dev) __ASSERT_NO_MSG(0); return; } + } else { + /* On STM32 the LL_I2C_GetAddressMatchCode & (ISR register) returns + * only 7bits of address match so 10 bit dual addressing is broken. + * Revert to assuming single address match. + */ + if (data->slave_cfg != NULL) { + slave_cfg = data->slave_cfg; + } else { + __ASSERT_NO_MSG(0); + return; + } } - slave_cfg = data->slave_cfg; slave_cb = slave_cfg->callbacks; if (LL_I2C_IsActiveFlag_TXIS(i2c)) {