glasgow icon indicating copy to clipboard operation
glasgow copied to clipboard

applet.interface.i2c_initiator: timeout & error message when SCL stuck low

Open electroniceel opened this issue 4 years ago • 2 comments

how to reproduce:

  • connect any port IO to GND (like A0)
  • issue any command that uses this io as i2c initiator SCL (like "glasgow run i2c-initiator --port A -V 3.3 scan")
  • glasgow is waiting endlessly for SCL to go high

I suggest to add a generous, but still reasonable timeout (like 1 second) for this case. Also return an explicit error message like "timeout, SCL stuck low" or similar.

I think this kind of error is not uncommon when testing or developing. Cases that come to mind are:

  • wrong IO pin selected
  • flaky connection
  • external pullup resistors not connected or forgotten to enable the internal ones
  • DUT misbehaving

It would be nice to add some similar detection for SDA too, currently you get back all zeros.

electroniceel avatar Mar 01 '20 14:03 electroniceel

Yes, that's pretty common. We can add a timeout for USB requests, which is already supported by the streaming code we have, and raise an exception in I2CInitiatorInterface. The state machine in the applet gateware will remain stuck, and that's OK because recovering from this state ~always requires a full reset, often even a power on reset.

I2C doesn't require a timeout (unfortunately, IMO) so it'll have to be optional, but having it something like 1 second by default seems generally OK.

(Aside: gateware and software tags are for base Glasgow code, applets get a per-applet label. I think you should be able to create them.)

whitequark avatar Mar 05 '20 02:03 whitequark

This will become far easier with #354.

whitequark avatar Jul 30 '23 02:07 whitequark