Skip to content

Instantly share code, notes, and snippets.

@dwagenk
Last active February 26, 2018 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwagenk/bd6391ebe3338ec3ccfa5292d0058187 to your computer and use it in GitHub Desktop.
Save dwagenk/bd6391ebe3338ec3ccfa5292d0058187 to your computer and use it in GitHub Desktop.

comparing

relevant for zephyrproject-rtos/zephyr#5224

relevant functions

(a) (b)
stm32f7_i2c_xfer i2c_stm32_transfer (i2c_ll_stm32.c)
stm32f7_i2c_xfer_msg msg_init
stm32f7_i2c_isr_event stm32_i2c_event_isr
stm32f7_i2c_isr_error stm32_i2c_error_isr
stm32f7_i2c_slave_isr_event stm32_i2c_slave_event and stm32_i2c_slave_error
  • (a) switches to master_mode in stm32f7_i2c_xfer_msg, directly before generating start condition on bus

    (b) does it already when preparing the messages in i2c_stm32_transfer

  • (a) exits master_mode in case of arbitration lost or when a stop condition is issued on the bus, both directly inside the isr

    (b) exits master_mode in case of arbitration lost or when all messages that were passed to i2c_stm32_transfer have been transfered.

  • (a) returns from stm32f7_i2c_xfer with -EAGAIN in case of arbitration lost

    (b) returns from i2c_stm32_transfer with -EIO in case of arbitration lost

  • both (a) and (b) could loose arbitration in the middle of multiple messages passed to stm32f7_i2c_xfer/i2c_stm32_transfer, if there's a stop condition somewhere inbetween them. Caller of stm32f7_i2c_xfer/i2c_stm32_transfer will not know if none, or just parts of the messages have been transfered.

    --> this should be declared undefined behaviour! A stop condition is only allowed in the last message passed to stm32f7_i2c_xfer/i2c_stm32_transfer

  • (a) uses SlaveByteControl mode to ack/nack each byte, (b) doesn't

  • (a) flushes RX buffer when master mode read is finished, (b) doesn't

Conclusions for zephyr:

  • move the switching ot master_mode directly before issuing start condition and disable it directly after issuing stop condition on the bus
  • move the switching out of master_mode directly after arbitration lost is detected
  • return -EAGAIN in case of arbitration lost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment