Repository navigation
examples: pru_i2c: SMBus protocols, PEC, open-drain bus with clock stretching (stacked on TI #171) - #2
Open
pratheesh wants to merge 2 commits into
Open
examples: pru_i2c: SMBus protocols, PEC, open-drain bus with clock stretching (stacked on TI #171)#2pratheesh wants to merge 2 commits into
pratheesh wants to merge 2 commits into
Conversation
SMBus (commands 0x14..0x1C, previously stubs):
quick command, send/receive byte, write/read byte, write/read word,
block write/read. A transfer is a write phase (command code and block
count staged as prefix bytes in front of the Tx buffer, then the Tx
data) and, for the reads, a repeated START and a read phase. Block read
reports the target's byte count in the count register. SMBus always
sends START/STOP and NACKs the last byte read, whatever CON says.
10-bit addressing is rejected (ADDRESSING_MODE_FAILED).
PEC (CON bit 6, ICSS_I2C_PEC_BIT): CRC-8 (0x07) updated bit by bit over
every address and data bit; appended to write-only transfers and checked
on reads (new response PEC_ERROR 0x050F).
Open-drain bus: SCL and SDA are never driven high. R30 keeps both bits at
0 and the lines are switched with their OUTDISABLE bits in
ICSSMx_PRUy_GPIO_OUT_CTRL through a shadow register (one store per edge).
The SDA direction macros are gone; the master can no longer fight a
target on either line.
Clock stretching: every state that follows an SCL release waits for SCL
to read high. A new SCL-low timeout (instance offset 0xE8, in ticks,
0 = none) ends a transfer with TIME_OUT_ERROR. After a stretch the high
period is counted from the real rising edge (tHIGH).
Errors now end with a STOP: address NACK, data NACK, bad block count.
Bus timing (UM10204 Table 10, SMBus = Standard-mode):
- START hold, repeated START setup/hold and STOP setup are two ticks
(one tick is 2.5 us at 100 kHz, below the 4.0/4.7 us minimums).
- The 400 kHz tick is 680 IEP counts (367.6 kHz): with 625 the 2-tick
SCL low was 1.25 us, under the Fast-mode tLOW of 1.3 us.
Removed: the unreachable CMD_CODE_* / *_BURST states and the SMBus burst
CON latch (bit 5 is now reserved).
New interface fields: ICSS_I2C_PEC_BIT, ICSS_I2C_SCL_TIMEOUT_OFFSET,
PEC_ERROR; ICSS_I2C_PRU_CMD_CODE_OFFSET is the SMBus command code (bit 0
is the R/W bit for quick command); instance offsets 0xFE/0xFF are used to
stage the SMBus prefix bytes.
Hardware note: SCL now needs a pull-up and its GPI path (the pad
configured with rx), like SDA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
Byte-identical to the ELFs exercised on pru-simulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SMBus support for the PRU I2C master, stacked on TexasInstruments#171. Merging this into
fix/pr137-pru-i2c-reviewadds it to TexasInstruments#171.What it adds
SMBus protocols (commands
0x14..0x1C, which were stubs): quick command, send/receive byte, write/read byte, write/read word, block write and block read.RX[0..N-1].ADDRESSING_MODE_FAILED.PEC (
CONbit 6,ICSS_I2C_PEC_BIT): CRC-8 (polynomial 0x07), updated bit by bit over every address and data bit. It is appended to write-only transfers and checked on reads. A mismatch returns the new responsePEC_ERROR(0x050F).Open-drain bus. SCL and SDA are never driven high:
ICSSMx_PRUy_GPIO_OUT_CTRL, through a shadow register, so each edge costs a single store.Clock stretching. Every state that runs after an SCL release waits for SCL to read high.
TIME_OUT_ERROR.Errors end with a STOP: address NACK, data NACK, and a bad block count.
Bus timing (UM10204 Table 10; SMBus uses the Standard-mode values):
Removed: the unreachable
CMD_CODE_*and*_BURSTstates, and the SMBus burst CON latch (bit 5 is now reserved).Hardware note: SCL now needs a pull-up and its input path (pad configured with rx), the same as SDA.
Verification ([BUILD+MODEL], not run on hardware)
All results are from the same pru-simulator harness as TexasInstruments#171: real clpru ELFs, AM261x ICSSM map, wired-AND bus.
The SMBus target model was written separately from the SMBus 3.x spec without seeing this firmware, so it acts as an independent oracle. Its own suite is 61 tests, driven by a bit-banged reference master. Each check looks at three things: the firmware response, the target's record of the transaction (protocol, data, PEC verdict), and a wire decode.
Results, the same under both IEP compare models (crossing and exact match):
SMBus coverage:
PEC_ERROR.TIME_OUT_ERROR, and the next transfer works.I2C regression coverage:
Bus timing is measured on the wire: tLOW, tHIGH, tHD;STA, tSU;STA, tSU;STO and tSU;DAT against the spec minimums.
Ablation: reverting each change on its own fails its scenario, 14 of 14. The reverts covered:
Builds: clpru 2.3.3 for PRU0 and PRU1 with 0 warnings. The regenerated
pru0/pru1_load_bin.hare byte-identical to the simulated ELFs.Model limits: no pad electricals or rise times, no real IEP compare semantics, the MSS_CTRL access latency is an estimate, and a single master. This needs a run on an AM261x-LP with a real SMBus device before it is merged upstream.
The R5F example (TexasInstruments#172) is updated to match: SCL rx and pull-up, both lines released before start, the timing-safe tick, the 25 ms SCL timeout, and SMBus documentation.
🤖 Generated with Claude Code