Skip to content

Commit 9df839c

Browse files
authored
ReSTART fix, Sequencing fix
pr espressif#1665 introduce a problem with ReSTART, when solving this problem I found an interaction between the TxFifo refill, RxFifo empty and CMD[] fill. during certain sequences a dataqueue command would be skipped, this skipping resulted in a mismatch between the contents of the TxFifo and the i2c command sequence. The problem manifested as an ACK error. In addition to this required bug fix I propose: * `Wire.begin()` be changed from a `void` to a `bool` this will allow the reset functionality of `Wire.begin()` to be reported. Currently `Wire.begin()` attempts to reset the i2c Peripheral, but cannot report success/failure. * `Wire.busy()` be added. this `bool` function returns the hardware status of the bus. This status can be use in multi-master environments for application level interleaving of commands, also in single master environment, it can be used to detect a 'hung' bus. With the functional change to `Wire.begin()` this allows app level recover of a hung bus. * `Wire.lastError()` value updated for all errors, previously when interleaving `Wire.endTransmission(false)` and `Wire.readTransmission(false)`, the 128 byte `Wire.write()` buffer was exhausted without generating and error(very exotic). I discovered this error when I created a sequence of directed reads to a EEPROM. Each directed read used 2 bytes of the 128 byte `write()` buffer, so after 64 consecutive ReSTART writes with ReSTART reads, `Wire()` had no room to record the directed address bytes. It generated just a NAK check without setting the EEPROMs internal register address. The succeeding ReSTART read succeeded at incorrect address. * Changes to the HAL layer: ** added `i2cGetStatus()` which returns the i2c peripheral status word, used to detect bus_busy currently ** added `i2cDebug()` programmatic control of debug buffer output ** changed `i2cAddQueue()` to allow data_only queue element this will allow a i2c transaction to use multiple data pointers. ** removed direct access to DumpInts(), DumpI2c() from app, use i2cDebug() to set trigger points *
1 parent e346f20 commit 9df839c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cores/esp32/esp32-hal-i2c.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, uint8_t* buff, uint16_t size, b
4848
i2c_err_t i2cFlush(i2c_t *i2c);
4949
i2c_err_t i2cSetFrequency(i2c_t * i2c, uint32_t clk_speed);
5050
uint32_t i2cGetFrequency(i2c_t * i2c);
51+
uint32_t i2cGetStatus(i2c_t * i2c); // Status register of peripheral
5152

5253
//Functions below should be used only if well understood
5354
//Might be deprecated and removed in future
@@ -62,8 +63,17 @@ i2c_err_t i2cAddQueueWrite(i2c_t *i2c, uint16_t i2cDeviceAddr, uint8_t *dataPtr,
6263
i2c_err_t i2cAddQueueRead(i2c_t *i2c, uint16_t i2cDeviceAddr, uint8_t *dataPtr, uint16_t dataLen, bool SendStop, EventGroupHandle_t event);
6364

6465
//stickbreaker debug support
65-
void i2cDumpInts(uint8_t num);
66-
void i2cDumpI2c(i2c_t *i2c);
66+
uint32_t i2cDebug(i2c_t *, uint32_t setBits, uint32_t resetBits);
67+
// Debug actions have 3 currently defined locus
68+
// 0xXX------ : at entry of ProcQueue
69+
// 0x--XX---- : at exit of ProcQueue
70+
// 0x------XX : at entry of Flush
71+
//
72+
// bit 0 causes DumpI2c to execute
73+
// bit 1 causes DumpInts to execute
74+
// bit 2 causes DumpCmdqueue to execute
75+
// bit 3 causes DumpStatus to execute
76+
// bit 4 causes DumpFifo to execute
6777

6878
#ifdef __cplusplus
6979
}

0 commit comments

Comments
 (0)