Skip to content

STM32 I2C Target v2 read transaction consumes one extra byte #70896

@AntoineGL

Description

@AntoineGL

Describe the bug
With STM32 v2 I2C Target: when a master requests to read N bytes, the zephyr i2c target callbacks end up requesting 1 extra byte.
Ex: Master wants to read 3 bytes, on target I observe 1 call to read_requested then 3 calls to read_processed => 4 bytes has been consumed.
This has been reproduced with Zephyr 3.3.0 and latest version of Zephyr and does not seem to be a regression.
Reproduced with a nucleo_g0b1re and a nucleo_f070rb.

Using an i2c analyzer, I observe that the correct number of bytes are read by the master.

This seems to be an issue with the TXIS flag. When this flag is set during an i2c event, it immediately triggers a call to read_processed (drivers/i2c/i2c_ll_stm32_v2.c function stm32_i2c_slave_event).
The issue is this flag only indicates that the last byte has been consumed, not that master requests another byte.

I have tried to add additional checks before calling read_processed (no stop condition nor NACK received) but it does not solve the issue as it seems that TXIS is set before master NACK or send stop condition.

To Reproduce
Steps to reproduce the behavior:

  1. Take a board with an STM32 MCU that uses stm32 i2c v2 driver (stm32g0b1, stm32f070 ...)
  2. Build an app that declares an i2c target with at least read callbacks for this board, and put some logs in read or stop callback to know how many bytes have been consumed.
  3. Use any i2c master to perform a read of N bytes on the target.

Expected behavior
N bytes should be consumed on the target, not N + 1.

Impact
This extra byte read is lost (not received by master but considered sent by the target).

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions