Skip to content

Spi driver demo - #161

Open
a1248924 wants to merge 3 commits into
mainfrom
SPI_driver_demo
Open

a1248924 wants to merge 3 commits into
mainfrom
SPI_driver_demo

Conversation

@a1248924

@a1248924 a1248924 commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

am261x: add SPI driver for configuring and running PRU SPI macros for 5x16 bit command/response

signed-off by Ayushman a-ayushman@ti.com

@qodo-code-review

qodo-code-review Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add AM261x spi_driver example: bit-banged PRU SPI master/slave demo

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds a new spi_driver example: PRU0 bit-banged SPI master, PRU1 fixed-response slave, and an R5F
 demo app.
• PRU0 runs 5 back-to-back 16-bit full-duplex transfers per CS-low burst, with runtime-selectable
 mode and bit order.
• Adds m_transfer_packet_spi_master_gpo_sclk_drv macro with runtime delay-compensation registers;
 clarifies DELAY_COMPEN comments in SPI macros.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: AM243x SPI loopback integration, AM261x PRU SPI driver integration.
  • The R5F trigger API, PRU0 wire transfer, PRU1 fixed response and DMEM result publication form one bounded end-to-end example integration.
  • The build and boot-image files deploy these same two firmware images rather than introducing an independent user outcome.
  • The timeout recovery changes the same bounded transaction integration: it reloads the two participating PRUs and determines the configuration used by the next transaction.
  • It is not an independent capability from the transaction itself.
  • This is a separate existing example whose affected outcome is firmware build resolution; it is independent of the new AM261x driver transaction, despite sharing common macro source files.
Sources

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/main.asm[98-114]

WAIT_CS_LOW:
    ; Poll until CS goes low (master asserts)
    qbbs    WAIT_CS_LOW, r31, CS_PIN

    ; Matches PRU0's DO_5X_TRANSFER_M3_MSB: master keeps CS low across 5
    ; back-to-back transfers. Each transfer sends its own fixed response
    ; while receiving the command word into its own register - not decoded,
    ; just latched to DMEM1 afterward for R5F/debug visibility.
    jal     retAddr, DO_5X_TRANSFER

    ldi32   temp, 0x00000000
    sbbo    &rx0, temp, DMEM_SLAVE_RX5_0, 4
    sbbo    &rx1, temp, DMEM_SLAVE_RX5_1, 4
    sbbo    &rx2, temp, DMEM_SLAVE_RX5_2, 4
    sbbo    &rx3, temp, DMEM_SLAVE_RX5_3, 4
    sbbo    &rx4, temp, DMEM_SLAVE_RX5_4, 4
    qba     LOOP_BACK
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before, the repository had no AM261x five-word R5F/PRU transaction capability.
  • After, one trigger coordinates five command writes, a persistent PRU0 state machine, five PRU1 transfers under one CS assertion, response publication, and a host polling loop.
  • The new correctness conditions are that the trigger is observed only after all command words are visible, PRU1 remains aligned to all five CS-low transfers, each response slot matches its transfer, and PRU0 clears the trigger only after publishing every response.
  • A timeout/reload transition additionally requires firmware startup configuration and core load ordering to remain consistent.
Sources

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/main.asm[98-114]

WAIT_CS_LOW:
    ; Poll until CS goes low (master asserts)
    qbbs    WAIT_CS_LOW, r31, CS_PIN

    ; Matches PRU0's DO_5X_TRANSFER_M3_MSB: master keeps CS low across 5
    ; back-to-back transfers. Each transfer sends its own fixed response
    ; while receiving the command word into its own register - not decoded,
    ; just latched to DMEM1 afterward for R5F/debug visibility.
    jal     retAddr, DO_5X_TRANSFER

    ldi32   temp, 0x00000000
    sbbo    &rx0, temp, DMEM_SLAVE_RX5_0, 4
    sbbo    &rx1, temp, DMEM_SLAVE_RX5_1, 4
    sbbo    &rx2, temp, DMEM_SLAVE_RX5_2, 4
    sbbo    &rx3, temp, DMEM_SLAVE_RX5_3, 4
    sbbo    &rx4, temp, DMEM_SLAVE_RX5_4, 4
    qba     LOOP_BACK

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/main.asm[121-135]

DO_5X_TRANSFER:
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx0, tx0, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx1, tx1, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx2, tx2, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx3, tx3, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx4, tx4, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    jmp     retAddr

ABORT_TRANSFER:
    qba     LOOP_BACK
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the transaction protocol or SPI timing regresses, the R5F can receive incorrect response words or incomplete results.
  • The slave's fixed responses are the intended demo behavior, while commands are separately latched for visibility.
  • Reverting the example firmware and host code stops new incorrect transactions; no persistent business data or external compensation is evidenced.
  • Re-run after restoring the firmware and restarting both PRUs; any already-observed incorrect response must be discarded by the caller.
Sources

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/main.asm[98-114]

WAIT_CS_LOW:
    ; Poll until CS goes low (master asserts)
    qbbs    WAIT_CS_LOW, r31, CS_PIN

    ; Matches PRU0's DO_5X_TRANSFER_M3_MSB: master keeps CS low across 5
    ; back-to-back transfers. Each transfer sends its own fixed response
    ; while receiving the command word into its own register - not decoded,
    ; just latched to DMEM1 afterward for R5F/debug visibility.
    jal     retAddr, DO_5X_TRANSFER

    ldi32   temp, 0x00000000
    sbbo    &rx0, temp, DMEM_SLAVE_RX5_0, 4
    sbbo    &rx1, temp, DMEM_SLAVE_RX5_1, 4
    sbbo    &rx2, temp, DMEM_SLAVE_RX5_2, 4
    sbbo    &rx3, temp, DMEM_SLAVE_RX5_3, 4
    sbbo    &rx4, temp, DMEM_SLAVE_RX5_4, 4
    qba     LOOP_BACK

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/main.asm[121-135]

DO_5X_TRANSFER:
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx0, tx0, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx1, tx1, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx2, tx2, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx3, tx3, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    qbbs    ABORT_TRANSFER, r31, CS_PIN
    m_transfer_packet_spi_slave_gpi_sclk rx4, tx4, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, "MODE3", "MSB"
    jmp     retAddr

ABORT_TRANSFER:
    qba     LOOP_BACK
Assessed commit f54e17b
Diagram

graph TD
  R5F["R5F demo app"] --> DMEM0[("PRU0 DMEM0 config")]
  R5F --> PRU1FW["PRU1 slave FW"]
  R5F --> PRU0FW["PRU0 master FW"]
  PRU0FW --> DMEM0
  PRU0FW -->|"SCLK / SDO / CS"| PRU1FW
  PRU1FW -->|"SDO response"| PRU0FW
  MACROS["spi_master_macros.inc"] --> PRU0FW
  SLAVEMAC["spi_slave_macros.inc"] --> PRU1FW
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Parameterized macro for the burst block
  • ➕ Single source of truth for the burst, transfer-done, and poll logic
  • ➕ Less copy-paste; fewer chances for the 8 variants to drift
  • ➖ Macro expansion must still fit within the 10-bit qbba/qbbc offset range, so the jal subroutine pattern stays
2. Use a hardware SPI peripheral (McSPI) via the R5F
  • ➕ Real SPI timing, higher rates, and no PRU timing dependence
  • ➖ Does not exercise PRU GPIO, which is the purpose of this example

Recommendation: The current approach works, but the 8-way MODE x bit-order branch table duplicates the 5-transfer burst and transfer-done code eight times. Wrapping the burst in one parameterized .macro and instantiating it per combination would cut the PRU0 firmware size and maintenance cost without changing behavior. Keep the bit-bang approach: this example targets PRU GPIO SPI without a hardware SPI peripheral.

Files changed (27) +2783 / -13

Enhancement (5) +1087 / -8
main.asmPRU0 SPI master firmware with 8-way mode/bit-order dispatch +463/-0

PRU0 SPI master firmware with 8-way mode/bit-order dispatch

• Reads mode, bit order, and delay compensation from DMEM0 at startup, then polls cfg_trigger in a persistent loop. Each of the 8 MODE x bit-order paths runs 5 back-to-back 16-bit transfers under one CS-low burst and writes the 5 responses to DMEM0. Delay-comp registers are decremented to offset the hardware-loop N+1 behavior.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm

main.asmPRU1 SPI slave firmware with fixed 5-word responses +135/-0

PRU1 SPI slave firmware with fixed 5-word responses

• Waits for CS low, then runs 5 MODE3/MSB full-duplex transfers sending 0x1111..0x5555 and latches received words to DMEM1. Command content is not decoded.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/main.asm

main.cFreeRTOS main task for spi_driver demo +84/-0

FreeRTOS main task for spi_driver demo

• Creates a static highest-priority task that calls empty_example_main and then deletes itself.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/main.c

empty_example.cR5F SPI config, PRU loading, and transaction loop +292/-0

R5F SPI config, PRU loading, and transaction loop

• Sets mode, bit order, and delay comp in DMEM0 before loading PRU1 then PRU0. Loops over user input, runs 5-word transactions with a 100 ms timeout, and reloads PRUs on timeout. The file name does not match its SPI content.

examples/spi_driver/mcuplus/empty_example.c

spi_master_macros.incAdd bit-bang master macro with runtime delay regs +113/-8

Add bit-bang master macro with runtime delay regs

• Adds m_transfer_packet_spi_master_gpo_sclk_drv, a full-duplex master transfer that takes delay compensation from registers. It also reworded DELAY_COMPEN comments to describe the shifting-to-sampling and sampling-to-shifting intervals.

source/firmware/common/spi_master_macros.inc

Documentation (4) +277 / -0
readme.mdDocument spi_driver example and its PRU support +6/-0

Document spi_driver example and its PRU support

• Adds an spi_driver description and a supported-processor row (N-hw for the hardware-only column).

examples/readme.md

readme.mdspi_driver design, API, and wiring documentation +270/-0

spi_driver design, API, and wiring documentation

• Documents the DMEM map, runtime vs build-time options, the 5x16-bit burst design, pin mapping, and the LaunchPad wiring. Some API signatures and the timeout value do not match the code (see review notes).

examples/spi_driver/readme.md

readme.mdClarify macro file location in spi_loopback readme +1/-0

Clarify macro file location in spi_loopback readme

• Notes that the SPI macro files live under source/firmware/common.

examples/spi_loopback/readme.md

spi_slave_macros.incClarify delay comp comments in slave macros +0/-0

Clarify delay comp comments in slave macros

• Updates DELAY_COMPEN comment text to match the new edge-interval semantics. No code change.

source/firmware/common/spi_slave_macros.inc

Other (18) +1419 / -5
makefileRegister spi_driver in examples build +1/-1

Register spi_driver in examples build

• Adds spi_driver to the SUBDIRS list so the top-level examples build includes it.

examples/makefile

example.projectspecCCS projectspec for PRU0 master firmware +80/-0

CCS projectspec for PRU0 master firmware

• Defines the PRU0 assembly project for AM261x, with post-build hex-array output to pru0_load_bin.h.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdLinker script for PRU0 memory map +43/-0

Linker script for PRU0 memory map

• Maps .text to PRU_IMEM and data sections to PRU0_DMEM_0.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/ti-pru-cgt/linker.cmd

makefileMakefile for PRU0 firmware build +49/-0

Makefile for PRU0 firmware build

• Sets build output name, include paths, and the PRU_VERSION 3 / am261x device target.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecCCS wrapper makefile for PRU0 project +16/-0

CCS wrapper makefile for PRU0 project

• Adds build, clean, and export targets that call CCS eclipse with the PRU0 projectspec.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecCCS projectspec for PRU1 slave firmware +80/-0

CCS projectspec for PRU1 slave firmware

• Defines the PRU1 assembly project for AM261x, outputting pru1_load_bin.h.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdLinker script for PRU1 memory map +43/-0

Linker script for PRU1 memory map

• Maps .text to PRU_IMEM and data sections to PRU1_DMEM_1 with PRU0 DMEM as secondary region.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/ti-pru-cgt/linker.cmd

makefileMakefile for PRU1 firmware build +49/-0

Makefile for PRU1 firmware build

• Defines the PRU1 build output name, hex-array prefix, and include paths.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecCCS wrapper makefile for PRU1 project +16/-0

CCS wrapper makefile for PRU1 project

• Adds build, clean, and export targets for the PRU1 projectspec.

examples/spi_driver/firmware/am261x-lp/icss_m1_pru1_fw/ti-pru-cgt/makefile_projectspec

makefileTop-level spi_driver build orchestration +106/-0

Top-level spi_driver build orchestration

• Builds PRU firmware first, then the MCU+ host app, gated on BUILD_MCUPLUS and device support.

examples/spi_driver/makefile

example.syscfgSysConfig for PRU-ICSS pins and R5F memory map +327/-0

SysConfig for PRU-ICSS pins and R5F memory map

• Configures PRU1 GPIO assignments for SCLK, CS, SDO, and SDI, plus UART and I2C settings and the R5F shared-memory layout.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/example.syscfg

example.projectspecCCS projectspec for R5F demo app +117/-0

CCS projectspec for R5F demo app

• Defines the TI ARM Clang FreeRTOS project and adds PRU firmware include paths.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileAuto-generated makefile for R5F demo build +352/-0

Auto-generated makefile for R5F demo build

• Generated TI ARM Clang build with SysConfig generation and boot-image targets.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genBoot image generation makefile for R5F app +112/-0

Boot image generation makefile for R5F app

• Generates the MCELF image and optional HS signing for the R5F app.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecCCS wrapper makefile for R5F project +16/-0

CCS wrapper makefile for R5F project

• Adds build, clean, and export targets for the R5F projectspec.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsROV configuration for FreeRTOS +12/-0

ROV configuration for FreeRTOS

• Lists FreeRTOS ROV and Theia files for runtime object view.

examples/spi_driver/mcuplus/am261x-lp/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

example.projectspecDrop spi_master_macros.inc copy from spi_loopback projectspec +0/-2

Drop spi_master_macros.inc copy from spi_loopback projectspec

• Removes the file copy entry for spi_master_macros.inc. This is not mentioned in the PR description and may break builds that relied on the copy.

examples/spi_loopback/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

example.projectspecDrop spi_slave_macros.inc copy from spi_loopback projectspec +0/-2

Drop spi_slave_macros.inc copy from spi_loopback projectspec

• Removes the file copy entry for spi_slave_macros.inc. This is not mentioned in the PR description and may break builds that relied on the copy.

examples/spi_loopback/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

@qodo-code-review

qodo-code-review Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


Action required

1. Wrong DMEM base channels 🐞
Description
In pru_eqep_example_main(), ABZHandle[i]->baseMemAddr0 is computed from pru0DramBase for all 6
channels, but the PRU1-side firmware channels (RTU_PRU1/PRU1/TX_PRU1) place their buffers in the
PRU1 DRAM bank. This causes channels 3–5 to read stale/incorrect ring-buffer data and report wrong
speed/position/phase-error results.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pru_eqep_example_main()` initializes each channel’s `baseMemAddr0` using `hwAttrs->pru0DramBase` unconditionally. However, the PRU firmware assigns distinct DMEM base offsets for PRU1-side cores (RTU_PRU1/PRU1/TX_PRU1), which correspond to the PRU1 DRAM bank. As a result, channels 3–5 (PRU1-side) will read from the PRU0 DRAM bank instead of PRU1, producing incorrect diagnostics.

## Issue Context
- Channels 0–2 correspond to PRU0-side cores; channels 3–5 correspond to PRU1-side cores.
- Firmware memory layout shows PRU1-side cores use DMEM offsets in the PRU1 region (e.g., 0x2C00/0x3000/0x3400), which conceptually is `PRU1_DRAM_BASE + {0x0C00,0x1000,0x1400}`.

## Fix
- Compute `baseMemAddr0` with `pru0DramBase` for channels 0–2 and `pru1DramBase` for channels 3–5.
- Keep `DMEM_OFFSETS[i]` as-is (since offsets 3–5 are already the per-bank offsets), but switch the base pointer depending on `i`.

## Fix Focus Areas
- examples/pru_eqep/mcuplus/pru_eqep_example.c[238-259]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


View medium (17)
Remediation recommended
2. Clock-delay lines use a single space after the mnemonic 📘 ⭐
Description
The qbeq and sub instructions that compensate the delay registers are followed by only one
space, but the spacing rule requires four spaces after a 4-letter mnemonic and five after a 3-letter
mnemonic. This breaks the column alignment used by the rest of main.asm, which uses four spaces
after qbeq and five after qba/jal.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In main.asm the `qbeq` and `sub` lines around the delay compensation do not use the required spacing after the mnemonic (4 spaces after 4-letter `qbeq`, 5 spaces after 3-letter `sub`).

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[116-120]

## Recommended Fix
Change `qbeq skip_sub_delay_1,...` and `qbeq skip_sub_delay_2,...` to use four spaces after `qbeq`, and change `sub delay_comp1_reg,...` and `sub delay_comp2_reg,...` to use five spaces after `sub`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

3. Copied SPI examples truncate delay values 🐞 ⭐
Description
The README's PRU_SPI_Config example still declares both delay fields as uint8_t, while the
implemented fields are uint32_t and accept values through 65535. A reader copying that documented
declaration into another application will truncate supported values above 255 before they reach the
firmware.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The README declares eight-bit delay fields even though the implemented configuration accepts 32-bit fields and validates values through 65535.

## Fix Focus Areas
- examples/spi_driver/readme.md[77-95]
- examples/spi_driver/mcuplus/empty_example.c[94-100]

## Recommended Fix
Update the README configuration and helper declarations to match the C implementation, including the delay field widths, configuration return type, and current transaction timeout.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

4. Long transfer-macro calls break the 128-column hard limit 📘 ⭐
Description
The m_transfer_packet_spi_master_gpo_sclk_drv calls in DO_5X_TRANSFER_M0_MSB are about 151
characters each, and the comment above the SCLK delay definition in empty_example.c is about 152
characters; both exceed the 128-column limit. The same call length occurs in every other
DO_5X_TRANSFER_* block, extending the issue across the burst section, while the limit also applies
to comments in source files.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The 5x transfer macro calls in `main.asm` and the comment above the `SCLK` delay definition in `empty_example.c` exceed the 128-column limit.

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[405-462]
- examples/spi_driver/mcuplus/empty_example.c[216-216]

## Recommended Fix
Split each `m_transfer_packet_spi_master_gpo_sclk_drv` call across lines, or move shared arguments (`PACKET_SIZE`, `bitId`, `SCLK_PIN`, `SDI_PIN`, `SDO_PIN`, `delay_comp1_reg`, `delay_comp2_reg`) into named `.asg`/`.set` symbols defined earlier. Apply the change to every `DO_5X_TRANSFER_*` block so each line fits within 128 columns. Split the comment into two or three `/* ... */` lines of no more than 128 characters each, preserving its content.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

5. Five-word transfer size repeated as bare literal 📘 ⭐
Description
The buffer size 5 is written as a bare literal in the array declarations commandWords[5] and
responses[5], and again in the loop bounds i < 5U and i < 5U further down. Changing the burst
length would require editing every one of these places consistently, and nothing ties them together.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The 5-word command/response burst size is repeated as a bare literal across empty_example.c (array sizes and loop bounds), so it is not defined in one place.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[237-243]
- examples/spi_driver/mcuplus/empty_example.c[280-280]

## Recommended Fix
Define `#define PRU_SPI_WORDS_PER_BURST (5U)` near the other DMEM defines, and use it for `commandWords`, `responses`, and every loop bound that currently uses `5U`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

6. Alignment spaces in defines break the spacing rule 📘 ⭐
Description
The #define lines for the DMEM offsets use runs of several spaces to align their values, and the
main.asm symbol table does the same with .set. The whitespace rule permits only single spaces in
source files outside line-end markers, and the C block also leaves a whitespace-only line at line
213.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new source files contain alignment runs of multiple spaces in `#define` and `.set` lines, plus a whitespace-only line in empty_example.c, which the whitespace rule forbids.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[45-49]
- examples/spi_driver/mcuplus/empty_example.c[213-213]
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[51-78]

## Recommended Fix
Replace each run of two or more spaces between a name and its value with a single space, and delete the whitespace-only line at empty_example.c line 213. Apply the same change to the `.set` declarations in main.asm (the indentation at the start of each line is a separate rule and can stay).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

7. Burst subroutines omit the registers they clobber 📘 ⭐
Description
The DO_5X_TRANSFER_* subroutines write rx0-rx4, invoke transfer macros that update bitId and
r_dataReg, and return with jmp retAddr, but their header comment lists only the inputs and
outputs. A caller that wants to know which registers a jal to these subroutines destroys has to
read the macro bodies to find out.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The DO_5X_TRANSFER_* subroutines in main.asm have no list of registers they modify, even though they write rx0-rx4 and the macros they call write other registers.

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[398-411]

## Recommended Fix
Add a `; Modifies:` line to the comment block above DO_5X_TRANSFER_M0_MSB (and the other variants), listing rx0-rx4 and every register written by the invoked transfer macro, including bitId and any temporaries it uses. State `Modifies: none` only where that is true.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

8. Fast SPI settings corrupt demo responses 🐞 ⭐
Description
PRU_SPI_setConfig accepts delay values down to 1 without checking whether the resulting clock is
within the bundled slave's practical limit. With both values set to 1, the example's clock formula
gives about 18.75 MHz, above the slave macro's documented 12.8 MHz limit, so an accepted
configuration can miss edges and return incorrect words.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The configuration validation accepts delay settings that produce an SPI clock faster than the bundled PRU1 slave's documented practical limit.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[118-148]
- examples/spi_driver/readme.md[59-65]

## Recommended Fix
Add a validation bound for the supported demo clock, accounting for the PRU clock and macro overhead, and document it separately from the hardware-loop counter range. Reject unsupported values before starting PRU0.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

9. The host can publish stale SPI data 📘
Description
PRU_SPI_runTransaction5 writes five command words and then sets DMEM_CFG_TRIGGER without a
memory barrier. A reordered or delayed data store can let PRU0 observe the trigger before the
command words, so the firmware may transfer stale commands.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The transaction helper writes shared PRU data and then sets the trigger flag without a full memory barrier.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[128-133]

## Recommended Fix
Insert the platform-appropriate full memory barrier after the five command writes and before writing `DMEM_CFG_TRIGGER`, preserving normal store semantics for the trigger.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

10. SPI timing lacks a total cycle bound 📘
Description
The new macro documents ~ (4+d1) + (6+d2) as its peak, but that expression describes one bit
rather than the full PACKETSIZE loop and omits the loop-control and branch paths. Users therefore
cannot determine the worst-case duration of the macro when it performs the configured 16-bit
transfer.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The SPI transfer macro's peak-cycle comment gives a per-bit expression but does not document the total worst-case cycles for the packet-sized loop.

## Fix Focus Areas
- source/firmware/common/spi_master_macros.inc[385-387]
- source/firmware/common/spi_master_macros.inc[438-473]

## Recommended Fix
Replace the per-bit expression with a parametrized total WCET that multiplies the per-bit cost by `PACKETSIZE` and includes loop control, conditional branches, delay-loop costs, and the assumptions used to derive the count.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

11. The application source omits its file header 📘
Description
empty_example.c begins with a copyright and project comment but does not identify the actual file
name empty_example.c in the first header comment. The required file-name header is therefore
absent before the include and declaration content.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The first comment block in `empty_example.c` does not explicitly contain the file name.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[1-6]

## Recommended Fix
Add `empty_example.c` to the opening header comment before the source includes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

12. New macro labels keep lowercase names 📘
Description
The new transfer macro defines the local label endloop1? in lowercase. The macro is expanded into
assembly code, so each expansion introduces a label that violates the required uppercase underscore
naming convention.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new transfer macro introduces the lowercase local label `endloop1?`, contrary to the required uppercase underscore label convention.

## Fix Focus Areas
- source/firmware/common/spi_master_macros.inc[449-451]

## Recommended Fix
Rename the local label and every reference to it using an uppercase underscore name while preserving the assembler's local-label suffix syntax.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

13. Register aliases bypass the required layout 📘
Description
The PRU0 firmware binds symbolic names directly to registers with .asg, including R20, R21,
and R6. Any code using these aliases bypasses the required struct-based register layout and makes
register ownership harder to verify across macros.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The firmware creates direct `.asg` aliases whose right-hand sides are PRU registers instead of binding symbols through a `.struct` and `.sassign` layout.

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[80-98]

## Recommended Fix
Define the register allocation in a `.struct`, bind the base register with `.sassign`, and replace direct register aliases with references to the assigned struct fields.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

14. SPI helpers lack algorithm documentation 📘
Description
PRU_SPI_setConfig has only a brief precondition comment and no pseudocode or algorithm section. A
reader cannot obtain the function's stepwise inputs, writes, or side effects from its documentation
before changing the configuration path.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new configuration helper is documented only with a precondition and does not include the required language-agnostic pseudocode.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[110-117]

## Recommended Fix
Add a clearly marked `Pseudocode:` section describing the configuration input, the four DMEM writes, and the resulting PRU startup state.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

15. The packet limit stays an unnamed literal 📘
Description
The new assembly macro validates PACKETSIZE against the literal 32 instead of a named
maximum-packet constant. A later change to the supported register width or packet limit can update
the validation inconsistently with the macro's documentation and callers.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The macro's packet-size validation embeds the protocol maximum as the unexplained literal `32`.

## Fix Focus Areas
- source/firmware/common/spi_master_macros.inc[426-429]

## Recommended Fix
Define a named constant for the maximum packet width supported by the 32-bit data register and use it in the validation expression and related documentation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

16. Short transaction buffers can corrupt memory 📘
Description
PRU_SPI_runTransaction5 dereferences both pointer parameters at five fixed indices without
checking for null or verifying that each buffer contains five elements. A caller that violates the
comment-only precondition causes out-of-bounds reads or writes before the transaction completes.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The transaction helper uses fixed indices 0 through 4 on both input and output pointers without mechanical size or null validation.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[124-132]
- examples/spi_driver/mcuplus/empty_example.c[148-152]

## Recommended Fix
Add explicit null and length validation at the function boundary, or replace the raw pointers with a fixed-size five-element interface such as an array parameter or a structure that guarantees the required capacity; return failure before any DMEM access when validation fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

17. Invalid SPI settings can generate bad code 📘
Description
m_transfer_packet_spi_master_gpo_sclk_drv validates only PACKETSIZE and S_BIT, then passes
MODE, pin numbers, and delay-register parameters directly into instruction-generating helpers and
loops. A bad mode, pin, or delay argument can therefore reach assembly expansion without an
allow-list or range failure.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new SPI macro checks packet size and bit order but does not validate the mode, pin, or delay parameters before using them to generate instructions.

## Fix Focus Areas
- source/firmware/common/spi_master_macros.inc[426-437]
- source/firmware/common/spi_master_macros.inc[438-475]

## Recommended Fix
Add assembler-time checks for `MODE` against `MODE0` through `MODE3`, for each pin against the supported PRU pin range, and for delay registers against the valid hardware-loop range; emit `.emsg` and stop expansion when any check fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

18. Firmware customization breaks the demo 🐞
Description
The fixed-configuration section directs users to edit only PRU0 firmware even though packet size and
pin assignments are independently defined by PRU1 and the pin routing is generated from SysConfig.
Changing either advertised setting by following these instructions leaves the two endpoints or
physical routing inconsistent, preventing the customized round trip from operating correctly.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The customization instructions name only PRU0 firmware, but packet-size and pin changes also require corresponding PRU1 firmware and SysConfig updates.

## Fix Focus Areas
- examples/spi_driver/readme.md[138-150]

## Recommended Fix
Split the build-time settings by component. State that packet-size changes must be applied consistently to both PRU firmware files, pin changes must update the relevant PRU constants and SysConfig routing before regeneration, and only the master timing compensation values are confined to PRU0.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Comment thread examples/spi_driver/makefile Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c7b425c

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a278e17

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit dc18a4d

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 41a382f

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 394ef65

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit cbef2f2

Comment thread examples/spi_driver/readme.md Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit ff049dd

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 3f78d69

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 2f41801

Comment thread examples/spi_driver/readme.md Resolved
Comment thread examples/spi_driver/readme.md Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit ae7524d

@a1248924

a1248924 commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

/agentic_review

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit b797160

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4861871

@a1248924
a1248924 requested review from dhavaljk, manojKoppolu and pratheesh and removed request for pratheesh October 8, 2026 08:51

@pratheesh pratheesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates — the idle-level fix, the register-width delay loads, the edge-relative delay wording and the dead-code cleanup all look good, and I confirmed against the SDK that 225 MHz is the default ICSSM1 core clock, so your 5 MHz capture and the readme figures agree. (I'd earlier suspected 200 MHz; that was wrong for ICSSM1.)

What's left:

  1. Moving the SPI macros to source/firmware/common/ changes spi_loopback's make build. pru_rules.mak searches source/firmware/common before the project's ../../, so spi_loopback now picks up the common spi_master_macros.inc instead of its own copy (I checked by adding a sentinel .emsg to the common file). That copy replaces the unrolled .loop N with a hardware loop, which adds one cycle per delay, so the 12.8 MHz 9, 7 call in spi_loopback gets ~2 cycles/bit slower, while the CCS projectspec still copies the old file. Please either keep the existing macro unchanged and add the register-delay version under a new name, or switch spi_loopback to the common file in this PR and adjust/re-check its timing, then drop the duplicate copies.
  2. DebugP_scanf doesn't report parse failures. It returns the UART read status, not the sscanf count (DebugP_uartScanf.c:114), so the new scanf_status check never fires and a non-hex line leaves input at the previous value, which is then accepted. Resetting input to an out-of-range value (e.g. 0xFFFFFFFF) before each call would work with your existing > 0xFFFF check.
  3. PRU1 still cannot resynchronise (icss_m1_pru1_fw/main.asm, WAIT_CS_LOW is checked once and the edge waits have no exit). One missed or extra SCLK edge leaves it off by a bit until it is reloaded. Please also test CS in the edge waits (or add a bounded spin) and restart at word 0 when CS goes high.
  4. Timeout handling. Clearing cfg_trigger on timeout helps, but PRU0 clears it again when a late burst finishes, so a retry can still pick up the previous burst's data. A sequence number echoed by PRU0, or treating a timeout as fatal and reloading the PRUs, would close it.
  5. Smaller items
    • PRU_CLK_CYC_PRD_CONST: at 225 MHz the period is 4.44 ns, so the value 5 gives fewer cycles than requested (35 ns -> 31 ns). Either use 4 or note the effective CS setup/hold, and mention in the readme that the 225 MHz comes from the SDK default for ICSSM1 (ICSSM0 defaults to 200 MHz).
    • empty_example.c:47,70: take the DMEM bases from PRUICSS_getAttrs() as pru_eqep does.
    • Delay range is 1–255 in the table (readme.md:62-63) and 1–65535 in the text (:149); please pick one and clamp it.
    • Stale comments: MODE3/LSB in empty_example.c:6, 25-26, 31, 54, 125 and icss_m1_pru1_fw/main.asm:102; the removed 0x08/0x0C slots at empty_example.c:20-21, 29; both DMEM rows named delay_comp_1 (:24).
    • readme.md:42 FIXME, and spi_driver is missing from examples/readme.md.
    • PR description is still empty; commit sign-offs would be easier to parse as Signed-off-by: trailers.

@a1248924

Copy link
Copy Markdown
Collaborator Author

Regarding point 1,
i included the modified macro under a new name in the macro file and used that for the spi driver demo and the spi loopback example will be using its original macro unchanged, is this approach ok ?

@a1248924
a1248924 force-pushed the SPI_driver_demo branch 5 times, most recently from 7a0c3c4 to 2faf4aa Compare October 14, 2026 06:11
@TexasInstruments TexasInstruments deleted a comment from a1248924 Oct 15, 2026
@pratheesh-ti

Copy link
Copy Markdown
Collaborator

/agentic_review

Comment on lines +80 to +82
.asg R4.b0, bitId
.asg R20, delay_comp1_reg
.asg R21, delay_comp2_reg

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Register aliases bypass the required layout 📘 Rule violation ≡ Correctness

The PRU0 firmware binds symbolic names directly to registers with .asg, including R20, R21,
and R6. Any code using these aliases bypasses the required struct-based register layout and makes
register ownership harder to verify across macros.
Agent Prompt
## Issue description
The firmware creates direct `.asg` aliases whose right-hand sides are PRU registers instead of binding symbols through a `.struct` and `.sassign` layout.

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[80-98]

## Recommended Fix
Define the register allocation in a `.struct`, bind the base register with `.sassign`, and replace direct register aliases with references to the assigned struct fields.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +110 to +117
/* Must be called BEFORE PRUICSS_loadFirmware(PRU0) - loadFirmware resets and
* starts the core immediately, so config has to already be in DMEM0. */
static void PRU_SPI_setConfig(const PRU_SPI_Config *cfg)
{
dmem_write32(pru_dmem0, DMEM_CFG_MODE, (uint32_t)cfg->mode);
dmem_write32(pru_dmem0, DMEM_CFG_BITORDER, (uint32_t)cfg->bitOrder);
dmem_write32(pru_dmem0, DMEM_CFG_DELAY_COMP1, (uint32_t)cfg->delay_comp_1);
dmem_write32(pru_dmem0, DMEM_CFG_DELAY_COMP2, (uint32_t)cfg->delay_comp_2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

5. Spi helpers lack algorithm documentation 📘 Rule violation ✧ Quality

PRU_SPI_setConfig has only a brief precondition comment and no pseudocode or algorithm section. A
reader cannot obtain the function's stepwise inputs, writes, or side effects from its documentation
before changing the configuration path.
Agent Prompt
## Issue description
The new configuration helper is documented only with a precondition and does not include the required language-agnostic pseudocode.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[110-117]

## Recommended Fix
Add a clearly marked `Pseudocode:` section describing the configuration input, the four DMEM writes, and the resulting PRU startup state.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +126 to +132
static int PRU_SPI_runTransaction5(const uint32_t *commandWords, uint32_t *responsesOut)
{
dmem_write32(pru_dmem0, DMEM_CFG_CMD0, commandWords[0]);
dmem_write32(pru_dmem0, DMEM_CFG_CMD1, commandWords[1]);
dmem_write32(pru_dmem0, DMEM_CFG_CMD2, commandWords[2]);
dmem_write32(pru_dmem0, DMEM_CFG_CMD3, commandWords[3]);
dmem_write32(pru_dmem0, DMEM_CFG_CMD4, commandWords[4]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

13. Short transaction buffers can corrupt memory 📘 Rule violation ≡ Correctness

PRU_SPI_runTransaction5 dereferences both pointer parameters at five fixed indices without
checking for null or verifying that each buffer contains five elements. A caller that violates the
comment-only precondition causes out-of-bounds reads or writes before the transaction completes.
Agent Prompt
## Issue description
The transaction helper uses fixed indices 0 through 4 on both input and output pointers without mechanical size or null validation.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[124-132]
- examples/spi_driver/mcuplus/empty_example.c[148-152]

## Recommended Fix
Add explicit null and length validation at the function boundary, or replace the raw pointers with a fixed-size five-element interface such as an array parameter or a structure that guarantees the required capacity; return failure before any DMEM access when validation fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

@pratheesh pratheesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of my 10-09 points are fixed at 2faf4aa4. The macro split leaves spi_loopback unchanged, DebugP_scanf input is validated, the clock note is in, and a timeout now reloads both PRUs. Both spi_driver and both spi_loopback firmwares assemble and link with clpru 2.3.3.

Still needed:

  1. PRU1 can still hang inside a word. The CS check happens only between words (icss_m1_pru1_fw/main.asm:122-130), and the edge-wait loops in spi_slave_macros.inc have no CS test or bound. One missing or extra clock edge mid-word leaves PRU1 stuck until a reload.
  2. PRU_SPI_setConfig passes delay_comp_1/2 through unchecked. Clamp or reject anything outside the documented 1-65535.
  3. The 5 ms TRIGGER_POLL_TIMEOUT_US (empty_example.c:69) is shorter than a valid burst. Five 16-bit words at 65535/65535 take about 80 x 131k = 10.5M cycles, about 47 ms at 225 MHz. That burst gets reported as a timeout and reloads the PRUs. Derive the timeout from the configured delays. (This is from the arithmetic; I haven't run it.)
  4. Minor:
    • readme.md:42 still has a FIXME.
    • icss_m1_pru0_fw/main.asm:88 says "MODE3/LSB" for registers that all 8 paths use.
    • The empty_example.c header says "MODE3/MSB only", but PRU0 implements all 8 paths.
    • The commits carry "signed-off by" in the subject line instead of a Signed-off-by: trailer.

Comment thread examples/makefile Resolved
@a1248924

a1248924 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

regarding this comment :
PRU1 can still hang inside a word. The CS check happens only between words (icss_m1_pru1_fw/main.asm:122-130), and the edge-wait loops in spi_slave_macros.inc have no CS test or bound. One missing or extra clock edge mid-word leaves PRU1 stuck until a reload.

-> this would require changes in the working of the SPI macro itself so i think that should be in a seperate PR, can mention in readme since PRU1 in this example is emulating an encoder ?

agreed with other changes, will fix

signed-off by Ayushman <a-ayushman@ti.com>
signed off by : Ayushman <a-ayushman@ti.com>
signed-off by Ayushman <a-ayushman@ti.com>
Comment on lines +406 to +409
m_transfer_packet_spi_master_gpo_sclk_drv rx0, tx0, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, delay_comp1_reg, delay_comp2_reg, "MODE0", "MSB"
m_transfer_packet_spi_master_gpo_sclk_drv rx1, tx1, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, delay_comp1_reg, delay_comp2_reg, "MODE0", "MSB"
m_transfer_packet_spi_master_gpo_sclk_drv rx2, tx2, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, delay_comp1_reg, delay_comp2_reg, "MODE0", "MSB"
m_transfer_packet_spi_master_gpo_sclk_drv rx3, tx3, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, delay_comp1_reg, delay_comp2_reg, "MODE0", "MSB"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Long transfer-macro calls break the 128-column hard limit 📘 Rule violation ✧ Quality

The m_transfer_packet_spi_master_gpo_sclk_drv calls in DO_5X_TRANSFER_M0_MSB are about 151
characters each, and the comment above the SCLK delay definition in empty_example.c is about 152
characters; both exceed the 128-column limit. The same call length occurs in every other
DO_5X_TRANSFER_* block, extending the issue across the burst section, while the limit also applies
to comments in source files.
Agent Prompt
## Issue description
The 5x transfer macro calls in `main.asm` and the comment above the `SCLK` delay definition in `empty_example.c` exceed the 128-column limit.

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[405-462]
- examples/spi_driver/mcuplus/empty_example.c[216-216]

## Recommended Fix
Split each `m_transfer_packet_spi_master_gpo_sclk_drv` call across lines, or move shared arguments (`PACKET_SIZE`, `bitId`, `SCLK_PIN`, `SDI_PIN`, `SDO_PIN`, `delay_comp1_reg`, `delay_comp2_reg`) into named `.asg`/`.set` symbols defined earlier. Apply the change to every `DO_5X_TRANSFER_*` block so each line fits within 128 columns. Split the comment into two or three `/* ... */` lines of no more than 128 characters each, preserving its content.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +116 to +117
qbeq skip_sub_delay_1,delay_comp1_reg,0
sub delay_comp1_reg,delay_comp1_reg,1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Clock-delay lines use a single space after the mnemonic 📘 Rule violation ✧ Quality

The qbeq and sub instructions that compensate the delay registers are followed by only one
space, but the spacing rule requires four spaces after a 4-letter mnemonic and five after a 3-letter
mnemonic. This breaks the column alignment used by the rest of main.asm, which uses four spaces
after qbeq and five after qba/jal.
Agent Prompt
## Issue description
In main.asm the `qbeq` and `sub` lines around the delay compensation do not use the required spacing after the mnemonic (4 spaces after 4-letter `qbeq`, 5 spaces after 3-letter `sub`).

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[116-120]

## Recommended Fix
Change `qbeq skip_sub_delay_1,...` and `qbeq skip_sub_delay_2,...` to use four spaces after `qbeq`, and change `sub delay_comp1_reg,...` and `sub delay_comp2_reg,...` to use five spaces after `sub`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +237 to +238
uint32_t commandWords[5];
uint32_t responses[5];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

5. Five-word transfer size repeated as bare literal 📘 Rule violation ≡ Correctness

The buffer size 5 is written as a bare literal in the array declarations commandWords[5] and
responses[5], and again in the loop bounds i < 5U and i < 5U further down. Changing the burst
length would require editing every one of these places consistently, and nothing ties them together.
Agent Prompt
## Issue description
The 5-word command/response burst size is repeated as a bare literal across empty_example.c (array sizes and loop bounds), so it is not defined in one place.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[237-243]
- examples/spi_driver/mcuplus/empty_example.c[280-280]

## Recommended Fix
Define `#define PRU_SPI_WORDS_PER_BURST (5U)` near the other DMEM defines, and use it for `commandWords`, `responses`, and every loop bound that currently uses `5U`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +45 to +46
#define DMEM_CFG_MODE (0x00U)
#define DMEM_CFG_BITORDER (0x04U)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

6. Alignment spaces in defines break the spacing rule 📘 Rule violation ✧ Quality

The #define lines for the DMEM offsets use runs of several spaces to align their values, and the
main.asm symbol table does the same with .set. The whitespace rule permits only single spaces in
source files outside line-end markers, and the C block also leaves a whitespace-only line at line
213.
Agent Prompt
## Issue description
The new source files contain alignment runs of multiple spaces in `#define` and `.set` lines, plus a whitespace-only line in empty_example.c, which the whitespace rule forbids.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[45-49]
- examples/spi_driver/mcuplus/empty_example.c[213-213]
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[51-78]

## Recommended Fix
Replace each run of two or more spaces between a name and its value with a single space, and delete the whitespace-only line at empty_example.c line 213. Apply the same change to the `.set` declarations in main.asm (the indentation at the start of each line is a separate rule and can stay).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +398 to +406
; Out-of-line subroutines: 5 independent full-duplex transfers within one
; CS-low burst, 16-bit each, one per (MODE x bit-order) combination. Reached
; via jal (full-range jump) instead of being inlined in DO_M*_*, since 5
; macro expansions inline pushed every qba in the file past the 10-bit
; PC-relative offset limit. tx0..4 must already hold the 5 command words;
; rx0..4 receive the 5 response words independently (each transfer uses its
; own register pair). No inter-transfer delay - back-to-back at full rate.
DO_5X_TRANSFER_M0_MSB:
m_transfer_packet_spi_master_gpo_sclk_drv rx0, tx0, PACKET_SIZE, bitId, SCLK_PIN, SDI_PIN, SDO_PIN, delay_comp1_reg, delay_comp2_reg, "MODE0", "MSB"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

7. Burst subroutines omit the registers they clobber 📘 Rule violation ✧ Quality

The DO_5X_TRANSFER_* subroutines write rx0-rx4, invoke transfer macros that update bitId and
r_dataReg, and return with jmp retAddr, but their header comment lists only the inputs and
outputs. A caller that wants to know which registers a jal to these subroutines destroys has to
read the macro bodies to find out.
Agent Prompt
## Issue description
The DO_5X_TRANSFER_* subroutines in main.asm have no list of registers they modify, even though they write rx0-rx4 and the macros they call write other registers.

## Fix Focus Areas
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[398-411]

## Recommended Fix
Add a `; Modifies:` line to the comment block above DO_5X_TRANSFER_M0_MSB (and the other variants), listing rx0-rx4 and every register written by the invoked transfer macro, including bitId and any temporaries it uses. State `Modifies: none` only where that is true.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +122 to +123
#define DELAY_COMP_MIN (1U)
#define DELAY_COMP_MAX (0xFFFFU)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

8. Fast spi settings corrupt demo responses 🐞 Bug ≡ Correctness

PRU_SPI_setConfig accepts delay values down to 1 without checking whether the resulting clock is
within the bundled slave's practical limit. With both values set to 1, the example's clock formula
gives about 18.75 MHz, above the slave macro's documented 12.8 MHz limit, so an accepted
configuration can miss edges and return incorrect words.
Agent Prompt
## Issue description
The configuration validation accepts delay settings that produce an SPI clock faster than the bundled PRU1 slave's documented practical limit.

## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[118-148]
- examples/spi_driver/readme.md[59-65]

## Recommended Fix
Add a validation bound for the supported demo clock, accounting for the PRU clock and macro overhead, and document it separately from the hardware-loop counter range. Reject unsupported values before starting PRU0.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +83 to +85
uint8_t delay_comp_1;
uint8_t delay_comp_2;
} PRU_SPI_Config;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Copied spi examples truncate delay values 🐞 Bug ⚙ Maintainability

The README's PRU_SPI_Config example still declares both delay fields as uint8_t, while the
implemented fields are uint32_t and accept values through 65535. A reader copying that documented
declaration into another application will truncate supported values above 255 before they reach the
firmware.
Agent Prompt
## Issue description
The README declares eight-bit delay fields even though the implemented configuration accepts 32-bit fields and validates values through 65535.

## Fix Focus Areas
- examples/spi_driver/readme.md[77-95]
- examples/spi_driver/mcuplus/empty_example.c[94-100]

## Recommended Fix
Update the README configuration and helper declarations to match the C implementation, including the delay field widths, configuration return type, and current transaction timeout.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

@a1248924
a1248924 requested review from nsaulnier-ti and removed request for pratheesh December 4, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants