Permalink
Browse files

STM32: i2c_lld: Fix i2c slave restart behavior

When performing random reads, multiple start conditions are encountered
before a stop condition.  If this happens, txcount or rxcount will be
nonzero.

Ordinarily, this would cause the current buffer to get dropped.  Modify
the i2c LLD code to instead call the callback (if one exists) if we
get a STARTF condition when data has been received.

Signed-off-by: Sean Cross <xobs@kosagi.com>
  • Loading branch information...
Sean Cross
Sean Cross committed Nov 18, 2014
1 parent edd713a commit 4180582a7d39a81cf19d9a11bb4d62e1f7aeaa4e
Showing with 11 additions and 0 deletions.
  1. +11 −0 os/hal/ports/STM32/LLD/I2Cv1/i2c_lld.c
@@ -299,6 +299,17 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
}
else {
if (event & (I2C_SR1_ADDR | I2C_SR1_ADD10)) {
/* If a start condition is received but data is present, then
* it likely is a restart case, e.g. where the host sent us an
* address and then wants to immediately read that address.
* In this case, finish up the transaction by calling the callback,
* if one exists.
*/
if (i2cp->rxcount && i2cp->rxcb)
i2cp->rxcb(i2cp, i2cp->rxcount);
if (i2cp->txcount && i2cp->txcb)
i2cp->txcb(i2cp, i2cp->txcount);
/* Reset rx buffer pointer when starting new reception.*/
i2cp->rxind = 0;
i2cp->rxcount = 0;

0 comments on commit 4180582

Please sign in to comment.