Repository navigation
Conversation
- Add I2C firmware - Create PRU0/PRU1 build projects for ICSS_M0 - Configure makefiles and projectspec for open-pru structure Signed-off-by: Achala Ram <a-ram@ti.com>
The am261x "Verify all makefiles were built" CI step failed with "makefile never built" for the two pru_i2c PRU firmware makefiles, because nothing in the top-level make recursed into them. - Add examples/pru_i2c/makefile aggregator (modeled on examples/empty), scoped to am261x with an am261x target that builds the pru0/pru1 ti-pru-cgt firmware. Non-am261x devices hit the SUPPORTED_PROCESSORS prebuild check and skip cleanly, so other device builds are unaffected. - Add pru_i2c to examples/makefile SUBDIRS so the top-level make recurses into it. Verified with GNU Make dry-runs: am261x recurses into both firmware leaf makefiles (each producing a .out, satisfying the verify step); am263x prints "does not have a build option" and builds nothing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…control Found by running the firmware ELFs on TI pru-simulator against an I2C target model (see the PR description for the harness and results). Per-core resources (both PRUs share the IEP and the scratchpad banks): - The makefile build defined neither PRU0 nor PRU1 (DFLAGS was empty), so icss_constant_defines.inc treated both cores as PRU1: the firmware read its frequency word from the other core's DMEM, got 0 and went to ERROR_LOOP. Neither IEP compare was enabled either. The committed pru0/pru1_load_bin.h were built this way and are identical apart from the array name. Add -DPRU0/-DPRU1 (as the projectspecs already do) and fail the build with .emsg if neither is defined. - I2C_WAIT_FOR_IEP_CMP polled the PRU0 status bit and I2C_SETUP_IEP_COUNTER programmed CMP0 on both cores, so PRU1 never saw a tick. Select CMP register, status bit and enable bit once per core. - I2C_SETUP_IEP_COUNTER wrote CMP_CFG with only its own enable bit set, disabling the other core's compare. Read-modify-write it instead. - The first compare value was a hardcoded 0x9C3 (debug guard commented out). Use the live IEP count + one tick, so a core can join a counter the other core already started. - I2C_IEP_INTC_CLEAR_EVENT wrote back the whole CMP_STATUS value, which (write-1-to-clear) also clears the other core's pending event. Clear only this core's bit. - Both cores saved their context to scratchpad bank 10. Use bank 10 for PRU0 and bank 11 for PRU1. - ERROR_LOOP stopped the shared IEP counter. Leave it running. I2C protocol: - Read: the master drove SDA high in the ACK slot after every byte (rx_data_ack_begin used SET_SDA_PIN_HIGH), so it NACKed each byte and multi-byte reads returned 0xFF after the first byte. Drive it low. - SET_SDA_PIN_INPUT/OUTPUT_DIRECTION wrote 0x50D00818 (ICSSM1_PRU0_GPIO_OUT_CTRL) with a hardcoded bit 9. These projects run on ICSSM0, so SDA was never released: ACKs were read back from the master's own drive (a write to an absent address reported success). Use this core's ICSSM0 register (ICSSM1 with -DICSSM1) and the configured SDA pin. - Release SDA on the SCL falling edge after the 8th bit instead of one tick later, and keep it released after the address ACK of a read, so the push-pull master does not drive SDA high while the target drives ACK or read data. Housekeeping: file header names, register usage map, wait macro docs, and a missing newline/indent on the final .endif (assembler warning W0004 "Open block(s) at EOF"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
The IEP counts in steps of DEFAULT_INC = 5. 0x270 (624) and 0x9C3 (2499) are not multiples of 5, so a compare that fires only when the counter equals the compare value is never hit at 400 kHz or 100 kHz. Use 0x271 (625, i.e. the 125 cycles the comment already describes) and 0x9C4 (2500). 1 MHz (0x140 = 320) was already a multiple of 5. SPRUJB6B does not say whether an IEP compare is an equality match or a crossing match. With these values the tick is exact under either. Also fix the file header name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
Rebuilt with the makefile flow (make -C examples/pru_i2c pru DEVICE=am261x BUILD_MCUPLUS=y), which now passes -DPRU0 / -DPRU1. The previous arrays were built with neither define and were identical for both cores apart from the array name. These arrays are 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>
PR Summary by Qodoexamples: pru_i2c: fix PRU1/dual-core IEP use, read ACK and SDA control
AI Description
Merge Risk
|
…le SDA Found on pru-simulator while checking the commands beyond TX. - Dispatcher: the SMBus stub checks (QUICK .. BLOCK_READ) only advanced to the next check from some stubs, so dispatch stopped at ICSS_SMBUS_QUICK_CHECK for every command after TX. READ_SCL, RESET_SLAVE and LOOPBACK were unreachable, and any SMBus or unknown command left the firmware spinning there until reset. Replace the stub chain with one range check: SMBus commands (not implemented) get INVALID_COMMAND, everything else goes on to READ_SCL / RESET_SLAVE / LOOPBACK and then INVALID_COMMAND. - RESET_SLAVE counted falling edges and ended with SCL low: 8 full SCL pulses and a bus left low. It also kept driving SDA high, fighting the stuck target it is meant to free. Release SDA, give 9 full pulses and end with SCL high. - SDA is now released whenever the bus is idle (after setup, after STOP, after RESET) and taken back at the start of each transfer, so an idle master never drives SDA high against a target holding it low. 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>
The example needs the firmware fixes (TexasInstruments#171) and the open-drain/SMBus firmware it is built for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
SMBus is now implemented as a follow-up stacked on this PR: pratheesh#2. It is a PR into this PR's branch, so merging it updates #171. It adds:
On pru-simulator, against an SMBus target model written independently from the spec:
Hardware note: SCL now needs a pull-up and its input path, like SDA. #172 is updated for this. @achala-ti this answers my earlier question about the SMBus stubs. If you'd rather keep SMBus out of the example, #171 stands on its own without it. |
|
/agentic_review |
Address review findings on the macros changed by the per-core IEP and scratchpad-bank fixes: - I2C_IEP_INTC_CLEAR_EVENT: add pseudocode, the arg1 no-event continuation label that was documented as 'Parameters: None', and the registers it modifies. - I2C_WAVE_FUNCTION0: add pseudocode and the registers it modifies, including the per-core context bank. - I2C_WAIT_FOR_IEP_CMP: tag the scheduler tick with INTENTIONALLY_UNBOUNDED_LOOP; there is no other time base to time it out against. Documentation only, no instruction changes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
White space between mnemonic and operand is 5 spaces for 3-letter and 4 for 4-letter operations (best_practices.md); the SET/CLR/LDI32/LBBO/SBBO lines in SET_SDA_PIN_INPUT/OUTPUT_DIRECTION used one space. Whitespace only, the assembled output is unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
NO_ADDRESS_ACK_RECIEVED took SDA back with the SDA GPO still holding the last address bit (0 for a write), so after a NACKed write address the master pulled SDA low on a bus it never STOPped, contradicting the 'SDA is released whenever the bus is idle' rule. Leave SDA released: SET_SCL_SDA_HIGH takes it back at the start of the next transfer. The data-byte ACK slot had the same pattern (SET_SDA_PIN_OUTPUT_DIRECTION before testing the ACK bit). Take SDA back only after an ACK, when the master transmits next (data or STOP). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…y selector I2C_SETUP_IEP_COUNTER and I2C_IEP_INTC_CLEAR_EVENT add I2C_GLOBAL_FREQ_REG.w2 to the compare value, but startup only loaded the configuration word and nothing set w2 for the selected frequency. A configuration holding just the selector (w0) gave an increment of 0, so the compare was re-armed at the current count and the tick had no period. Set w2 from the selector (IEP_CMP_INCREMENT_VAL_100KHZ / _400KHZ / _1MHZ) before the IEP is set up. An unsupported selector keeps w2 = 0 and still ends in ERROR_LOOP. Any w2 the host wrote is now replaced by the selector's value. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
PRU0 and PRU1 share the IEP counter and IEP_CMP_CFG_REG and nothing in hardware serialises their start-up. State that the two cores must be released one after the other, and what goes wrong otherwise (lost enable bit, counter reset under the running core). The race itself is not closed in firmware: the enable-bit update is already a read-modify-write rather than the earlier overwrite, and no cross-core lock is available to these cores in this example. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rebuilt with the makefile flow (make -C examples/pru_i2c pru DEVICE=am261x BUILD_MCUPLUS=y) after the review-fix changes. Not hardware tested. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Derive w2 from the frequency selector only when the host left it at 0, so a nonzero increment written by the host stays an override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ample branch TexasInstruments#137 is closed in favour of this PR, so this PR now also carries TexasInstruments#171's review follow-ups from 2026-10-16, which it did not have: - 146ccec: pseudocode, arg1 and registers-modified docs for I2C_IEP_INTC_CLEAR_EVENT and I2C_WAVE_FUNCTION0. The scheduler wait is marked INTENTIONALLY_UNBOUNDED_LOOP. The I2C_WAVE_FUNCTION0 register note now also covers this branch's R23/R26 open-drain pin registers. - 466c7af, 9b8099e: derive the IEP compare increment from the frequency selector when the host leaves it at 0, and keep a nonzero host value. The R5F example always writes a nonzero increment, so its path is unchanged. - e161b91: document the shared-IEP start-up ordering constraint. Two commits are not taken. This branch's open-drain bus replaces the push-pull SDA direction control they patch: - 6e43662 fixes spacing in SET_SDA_PIN_INPUT/OUTPUT_DIRECTION, which no longer exist here. - a0ca016 leaves SDA released after a NACK. Here SDA is only ever released or pulled low, and an address or data NACK ends with a STOP through DATA_PROCESSING_COMPLETE. pru0/pru1_load_bin.h are regenerated with the makefile flow (clpru 2.3.3, no warnings). Each image grows by exactly the 7 instructions of the selector-to-increment derivation.
TexasInstruments#137 is closed and this PR now targets main. The only conflict is the SUBDIRS list in examples/makefile, where main added pru_eqep and pru_i2s; keep all three.
|
Refreshed for All of this PR is also in #172, which builds on it with the open-drain bus, SMBus and the R5F example, and has run on silicon. If #172 is merged, this PR can be closed without merging. All review threads are answered and resolved. |
Status (refreshed after #137 was closed)
main.mainis merged in (e8f3a040). The only conflict was theexamples/makefileSUBDIRS list;pru_eqep,pru_i2candpru_i2sare all kept. The PRU build reproduces the committedpru0/pru1_load_bin.hexactly.40119da7), plus open-drain SCL/SDA, SMBus, the R5F example and the MCU+ SDK 11+ project. examples: pru_i2c: add R5F NORTOS host example for am261x-lp (for #137) #172 has also run on silicon (LP-AM263). If examples: pru_i2c: add R5F NORTOS host example for am261x-lp (for #137) #172 is merged, this PR can be closed without merging.Fixes for #137, originally targeted at its branch (
a0502729_PRU_I2C).I ran the PRU0 and PRU1 firmware ELFs on pru-simulator against a modelled I2C bus with an EEPROM-style target. The pass/fail judgement comes from a bus monitor that decodes the wire levels, not from the firmware's response codes. The PR head (
d3795004) failed every scenario. With these changes all scenarios pass. Each fix was also reverted on its own to confirm the scenario guarding it fails again (details below).What was wrong, and what changed
Per-core resources. The IEP and the scratchpad banks are shared by PRU0 and PRU1.
PRU0norPRU1(DFLAGS :=).icss_constant_defines.incthen treats the core as PRU1, soICSS_DMEM0_CONSTbecomes C25. No IEP compare is enabled either. The committedpru0/pru1_load_bin.hare this build: both arrays are identical apart from the array name.ERROR_LOOP. SETUP never completes and SCL never toggles.DFLAGS := -DPRU0/-DPRU1 -DSLICEn -DSOC_AM261X, matching the projectspecs..emsgif neither is defined.I2C_WAIT_FOR_IEP_CMPpolls the PRU0 status bit (qodo #5).I2C_IEP_CMP_*).I2C_SETUP_IEP_COUNTERprograms CMP0 on both cores (qodo #6).0x9C3(theDEBUG_CODEguard is commented out) (qodo #7).CMP_CFGis written with only this core's enable bit set.I2C_IEP_INTC_CLEAR_EVENTwrites the wholeCMP_STATUSvalue back. The register is write-1-to-clear, so this also clears the other core's pending event.XOUT/XINtheir context to scratchpad bank 10.ERROR_LOOPstops the IEP counter.I2C protocol
rx_data_ack_begindrives SDA high, so the master NACKs every byte it reads.5a ff ff ff. Wire trace:A1A 5AN FFN FFN FFN.SET_SDA_PIN_INPUT/OUTPUT_DIRECTIONwrite0x50D00818with a hardcoded bit 9. That address isICSSM1_PRU0_GPIO_OUT_CTRL, but these projects run on ICSSM0.COMMAND_SUCCESS(START A2A 00A STOP).ICSSM0_PRU0/1_GPIO_OUT_CTRLat0x50D00810/814, or ICSSM1 with-DICSSM1), with the bit taken from the configured SDA pin.IEP_CMP_INCREMENT_VAL_400KHZ=0x270(624) and_100KHZ=0x9C3(2499) are not multiples of the IEP DEFAULT_INC (5).0x271(625) and0x9C4(2500). These are exact under either compare model (see "Limits" below).Commands and bus recovery (added after the first push)
ICSS_SMBUS_QUICK_CHECKfor every command after TX.READ_SCL,RESET_SLAVEandLOOPBACKare unreachable. Any SMBus or unknown command leaves the firmware stuck in that check until reset.INVALID_COMMAND, and every other command continues toREAD_SCL/RESET_SLAVE/LOOPBACK, thenINVALID_COMMAND.RESET_SLAVEcounts falling edges and ends with SCL low. It also keeps driving SDA high.Housekeeping
.asgitself is the repo idiom, so kept)..endifgets an indent and a final newline. This fixes assembler warning W0004, "Open block(s) at EOF".pru0/pru1_load_bin.hregenerated with the makefile flow. They are byte-identical to the ELFs that were simulated.Not changed:
LOOPBACK_DATA_COUNTalready limits the count to 1..255 and the buffers are 256 bytes.postBuildSteplength). It is the same form as every other open-pru projectspec, for exampleexamples/empty.Verification
Builds: clpru 2.3.3.
make -C examples/pru_i2c pru DEVICE=am261x BUILD_MCUPLUS=ygives 0 warnings. A build with no core define now fails with a clear message. CI was dispatched on the fork (links below).Simulation: pru-simulator core and memory model, plus an AM261x ICSSM layer:
0xFFFFFFFFtoIEP_COUNTclears it.MSS_CTRL ICSSMx_PRUy_GPIO_OUT_CTRLdecides who drives SDA.The I2C target can only pull low. The bus monitor flags any cycle where the master drives SDA high while the target pulls it low.
ADDRESS_ACKNOWLDEGE_FAILED,START A2NINVALID_COMMAND; the next command still worksREAD_SCL/LOOPBACKSCL_VALUE_HIGH/ RX buffer equals TX buffer, no bus activityRESET_SLAVEwith a target holding SDA low (after a completed and after a NACKed transfer)Remaining overlap: at most 30 PRU cycles (150 ns) per ACK. The target model drives ACK on the same cycle SCL falls, and the master needs that long to write
GPIO_OUT_CTRL. That is the floor for a push-pull master.Ablation: reverting each fix one at a time re-fails its scenario, 12 of 12. The 9-pulse count is checked by the scenario but not ablated separately.
Limits of this evidence:
MSS_CTRLaccess latency is an estimate.This needs a run on an AM261x-LP before it is merged.
Questions for @achala-ti
0x50D00818would be correct there; build with-DICSSM1. The projectspecs sayICSS_M0, so ICSSM0 is the default here.ICSS_SMBUS_*) now getINVALID_COMMAND. The supporting states (CMD_CODE_*,*_BURST) are still there but unreachable: there is no repeated START, the command-code ACK does not release SDA, and the block count is not bounds-checked. Do you want to implement SMBus, or drop those states until it is implemented?Related: #172 (R5F example, open-drain bus, SMBus; includes this PR). #173 resolved the earlier
examples/makefileconflict on #137's branch.🤖 Generated with Claude Code