Skip to content

Fix issue #120: Add HW spinlock usage examples (assembly/C) in academy/spinlock - #142

Open
pratheesh wants to merge 12 commits into
TexasInstruments:mainfrom
pratheesh:fix/issue-120-spinlock-examples
Open

pratheesh wants to merge 12 commits into
TexasInstruments:mainfrom
pratheesh:fix/issue-120-spinlock-examples

Conversation

@pratheesh

@pratheesh pratheesh commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #120.

Adds HW spinlock usage examples (assembly and C) under academy/spinlock/.

Approach

Uses the PRU_ICSSG local hardware spinlock accessed over the broadside interface (XIN/XOUT), per the recommendation in #120. The spinlock accelerator owns 64 ownership flags (lock id 0–63), reached with broadside device id 0x90 (= 144) for the local PRU subsystem:

  • Lock id (0–63) is placed in R1.b0.
  • Acquire: XIN 0x90, &R1.b3, 1 → acquisition status in R1.b3 bit 0 (1 = acquired). One XIN is one attempt; busy-wait until acquired.
  • Release: XOUT 0x90, &R1.b3, 1 with the same lock id still in R1.b0.

A spinlock provides mutual exclusion only (not a mailbox); the README covers the correct signalling pattern (guard a shared buffer + raise a system event).

Files

  • spinlock.asm — C-callable spinlock_acquire() / spinlock_release() built on the broadside primitives.
  • main.c — C example: PRU0 and PRU1 contend for one lock and drive a per-core debug GPO while holding it, so ownership is observable on a scope.
  • spinlock_example.asm — pure-assembly example using M_SPINLOCK_ACQUIRE / M_SPINLOCK_RELEASE macros.
  • readme.md — semantics, usage pattern, and build notes.

Validation

All sources assemble/compile with clpru --silicon_version=3 (ti-cgt-pru 2.3.3); main.c builds for both PRU0 (-DPRU0) and PRU1.

Notes

Squashed to a single commit. An earlier revision of this PR used the SoC-level memory-mapped Spinlock module (0x2A000000); it has been reworked to the broadside local-spinlock approach requested in the issue.

@qodo-code-review

qodo-code-review Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (7) 📎 Requirement gaps (2)

Context used

Grey Divider


Action required

1. Busy-wait worst-case undocumented 📎 Requirement gap ☼ Reliability ⭐ New
Description
The README describes spinning until acquisition succeeds but does not explicitly document that the
busy-wait can be unbounded in the worst case, as required. This can mislead users about
timing/determinism implications of the blocking acquire loop.
Code

academy/spinlock/readme.md[R8-21]

+The PRU_ICSSG includes a hardware spinlock accelerator with **64 ownership flags**
+(lock id `0`–`63`). A PRU core reaches it over the **broadside interface** using the
+`XIN`/`XOUT` instructions — there is no memory-mapped load/store on the critical path,
+so acquire/release are only a couple of cycles.
+
+- The broadside device id (XID) **`0x90` (= 144)** selects the spinlock in the
+  **local** PRU subsystem. A different XID is needed to reach a spinlock in another
+  PRU subsystem.
+- The **lock id** to operate on is placed in **`R1.b0`**.
+- **Acquire** (`XIN 0x90, &R1.b3, 1`): the accelerator returns the acquisition status
+  in **`R1.b3`** — **bit 0 = 1** means the lock is now owned by this core, **bit 0 = 0**
+  means it is held by someone else, so retry. A single `XIN` is one attempt; busy-wait
+  until you get a 1.
+- **Release** (`XOUT 0x90, &R1.b3, 1`): with the same lock id still in `R1.b0`, frees
Evidence
PR Compliance ID 3 requires explicit documentation of best/worst-case timing, including that the
busy-wait acquire has unbounded worst-case time. The README instructs to busy-wait until success but
does not explicitly state the worst-case is unbounded.

Document the blocking busy-wait semantics and status interpretation for acquisition
academy/spinlock/readme.md[8-21]

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 documentation explains the status bit and that the PRU should busy-wait, but it does not explicitly state the worst-case acquisition time is unbounded.

## Issue Context
PR Compliance requires documenting busy-wait semantics including best/worst-case timing characteristics and how acquisition success is detected.

## Fix Focus Areas
- academy/spinlock/readme.md[8-22]

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


2. spinlock.asm missing required metadata 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The new assembly functions spinlock_acquire/spinlock_release are added without the mandatory
function metadata (pseudo code, peak/worst-case cycles, and registers modified). This reduces
reviewability and can hide timing/register-clobber assumptions in a low-level synchronization
primitive.
Code

academy/spinlock/spinlock.asm[R35-66]

+;******************************************************************************
+; uint8_t spinlock_acquire(uint8_t flag_id);
+;
+;   One non-blocking attempt to acquire spinlock 'flag_id'.
+;   Returns 1 if the lock was acquired, 0 if it is held by someone else.
+;
+;   Calling convention (PRU C/C++ compiler): the uint8_t argument arrives in
+;   R14.b0 and the uint8_t return value is passed back in R14.b0. The return
+;   address is in r3.w2.
+;******************************************************************************
+    .sect       ".text:spinlock_acquire"
+    .clink
+    .global     spinlock_acquire
+spinlock_acquire:
+    MOV         R1.b0, R14.b0           ; lock id -> R1.b0 (presented to accel)
+    XIN         INT_SPIN_XID, &R1.b3, 1 ; status returned in R1.b3 (bit0=acquired)
+    MOV         R14.b0, R1.b3           ; return status
+    JMP         r3.w2
+
+;******************************************************************************
+; void spinlock_release(uint8_t flag_id);
+;
+;   Release spinlock 'flag_id'. Only the owner should release, and it must do
+;   so promptly.
+;******************************************************************************
+    .sect       ".text:spinlock_release"
+    .clink
+    .global     spinlock_release
+spinlock_release:
+    MOV         R1.b0, R14.b0           ; lock id -> R1.b0
+    XOUT        INT_SPIN_XID, &R1.b3, 1 ; release the lock
+    JMP         r3.w2
Evidence
PR Compliance ID 24 requires pseudo code, peak/worst-case cycle budget, and registers modified
documentation for PRU assembly functions/macros. The function header comments for spinlock_acquire
and spinlock_release do not include these required fields.

academy/spinlock/spinlock.asm[35-66]
Best Practice: Repository guidelines

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 assembly functions added in `spinlock.asm` do not include the required metadata fields: pseudo code, peak/worst-case cycle count, and registers modified.

## Issue Context
The compliance checklist requires standardized documentation for PRU assembly functions/macros to prevent timing and register-corruption bugs.

## Fix Focus Areas
- academy/spinlock/spinlock.asm[35-66]

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


3. main.c header missing filename 📘 Rule violation ⚙ Maintainability
Description
academy/spinlock/main.c has a copyright/SPDX header but does not denote the file name in the
header section. This violates the required source file header convention and reduces traceability.
Code

academy/spinlock/main.c[R1-16]

+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2024-2026 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Spinlock Example - C Version (PRU_ICSSG local hardware spinlock)
+ *
+ * Demonstrates mutual exclusion between PRU0 and PRU1 using the PRU-local
+ * hardware spinlock, accessed over the broadside interface (XIN/XOUT). The
+ * low-level acquire/release are implemented in spinlock.asm; this file shows
+ * the usage pattern.
+ *
+ * Each PRU repeatedly takes the same spinlock, drives a debug GPO high while it
+ * holds the lock, waits a (per-core different) number of cycles, then releases
+ * and drives the debug GPO low. Probing the two debug pins shows that the two
+ * cores never hold the lock at the same time.
+ */
Evidence
PR Compliance ID 18 requires a file header that includes the file name and TI copyright statement.
The added header in main.c includes SPDX and copyright but does not include a File:/file-name
line identifying main.c.

academy/spinlock/main.c[1-16]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`academy/spinlock/main.c` is missing the required header field that denotes the file name.
## Issue Context
The compliance checklist requires each source file header to include both the file name and the TI copyright statement.
## Fix Focus Areas
- academy/spinlock/main.c[1-16]

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


View more (10)
4. TODO marker in main.c 📘 Rule violation ⚙ Maintainability
Description
academy/spinlock/main.c introduces a TODO marker, which is disallowed by the repository marker
standard. This makes tracking inconsistent and violates the required pending-work marker convention.
Code

academy/spinlock/main.c[R35-36]

+/* TODO: pinmux the debug signals (see the GPIO lab) and update the shift to */
+/*       match your board. PRU0 is selected via -DPRU0 in the makefile.      */
Evidence
PR Compliance ID 23 forbids introducing TODO markers. The comment in main.c contains TODO:
indicating pending work.

academy/spinlock/main.c[35-36]
Best Practice: Repository guidelines

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 code introduces a `TODO` marker; the repository standard requires `FIXME` instead.
## Issue Context
Use `FIXME` for pending work markers to keep consistency across the codebase.
## Fix Focus Areas
- academy/spinlock/main.c[35-36]

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


5. Multiple spaces in main.c 📘 Rule violation ⚙ Maintainability
Description
academy/spinlock/main.c contains multiple consecutive spaces within declarations for alignment
(for example between void and spinlock_release). This violates the whitespace policy that
restricts whitespace to single spaces and newlines.
Code

academy/spinlock/main.c[R28-29]

+uint8_t spinlock_acquire(uint8_t flag_id);
+void    spinlock_release(uint8_t flag_id);
Evidence
PR Compliance ID 16 disallows tabs and multiple spaces outside the documented Markdown exception.
The declaration void    spinlock_release(...) contains multiple consecutive spaces in the changed
C source.

academy/spinlock/main.c[28-29]
Best Practice: Repository guidelines

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 file uses multiple consecutive spaces for alignment, but the whitespace policy requires single spaces only.
## Issue Context
This applies to changed content in source files; alignment should be done without introducing multiple spaces (use one space and rely on formatting tools/settings if needed).
## Fix Focus Areas
- academy/spinlock/main.c[28-29]

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


6. Macros missing required docs 📘 Rule violation ⚙ Maintainability
Description
The new PRU assembly macros M_SPINLOCK_ACQUIRE and M_SPINLOCK_RELEASE are documented but do not
include all mandatory fields (pseudo code and registers modified). This reduces reviewability and
can hide register-clobber and timing assumptions.
Code

academy/spinlock/spinlock_example.asm[R29-51]

+;******************************************************************************
+;   Macro: M_SPINLOCK_ACQUIRE
+;       Acquire the spinlock and busy-wait until successful.
+;       R1.b0 - Input : spinlock id (set to SPINLOCK_ID)
+;       R1.b3 - Output: acquisition status (bit 0: 0=failed, 1=acquired)
+;       Best case 3 cycles; worst case unbounded (busy-wait).
+;******************************************************************************
+M_SPINLOCK_ACQUIRE  .macro
+    .newblock
+    LDI     R1.b0, SPINLOCK_ID          ; lock id (0-63)
+$1:
+    XIN     INT_SPIN_XID, &R1.b3, 1     ; attempt acquire; status in R1.b3
+    QBBC    $1, R1.b3, 0                ; bit 0 clear -> not acquired, retry
+    .endm
+
+;******************************************************************************
+;   Macro: M_SPINLOCK_RELEASE
+;       Release the spinlock. Must follow M_SPINLOCK_ACQUIRE (lock id is still
+;       in R1.b0). 2 cycles.
+;******************************************************************************
+M_SPINLOCK_RELEASE  .macro
+    XOUT    INT_SPIN_XID, &R1.b3, 1     ; release lock held in R1.b0
+    .endm
Evidence
PR Compliance ID 29 requires pseudo code, peak cycle budget, and registers modified for PRU assembly
functions/macros. The comment blocks for M_SPINLOCK_ACQUIRE/M_SPINLOCK_RELEASE describe behavior
and some timing notes but do not list pseudo code and the registers modified (for example
R1.b0/R1.b3).

academy/spinlock/spinlock_example.asm[29-51]
Best Practice: Repository guidelines

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 assembly macro documentation is missing mandatory fields (pseudo code, registers modified).
## Issue Context
The compliance checklist requires PRU macros/functions to document pseudo code, peak/worst-case cycle budget, and registers modified.
## Fix Focus Areas
- academy/spinlock/spinlock_example.asm[29-51]

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


7. Acquire return not boolean 🐞 Bug ≡ Correctness
Description
spinlock_acquire() claims to return 0/1 but actually returns the raw R1.b3 status byte; main.c
spins on result != 1, so it can keep spinning even when bit0 indicates the lock is acquired (if
any other status bits are set). This makes the example’s acquire loop depend on an exact byte value
instead of the documented “bit0=success” contract.
Code

academy/spinlock/spinlock.asm[R49-52]

+    MOV         R1.b0, R14.b0           ; lock id -> R1.b0 (presented to accel)
+    XIN         INT_SPIN_XID, &R1.b3, 1 ; status returned in R1.b3 (bit0=acquired)
+    MOV         R14.b0, R1.b3           ; return status
+    JMP         r3.w2
Evidence
The helper’s comment promises a boolean return, but the implementation returns the full status byte.
The documentation and assembly macro examples only test bit 0, while main.c requires the return to
equal 1 exactly, creating a contract mismatch.

academy/spinlock/spinlock.asm[36-52]
academy/spinlock/main.c[58-63]
academy/spinlock/readme.md[17-21]
academy/spinlock/spinlock_example.asm[36-42]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`spinlock_acquire()` is documented as returning `1` when acquired and `0` otherwise, but it currently returns the entire status byte from `R1.b3`. The C example (`main.c`) and README usage pattern compare the return value to `1`, so the loop is only correct if the hardware always returns exactly `0x00` or `0x01`.
## Issue Context
The README and the pure-assembly macro example both treat only **bit 0** as meaningful (they test the bit), not the entire byte.
## Fix Focus Areas
- academy/spinlock/spinlock.asm[48-52]
- academy/spinlock/main.c[58-63]
## Suggested fix
1. Normalize the return value in `spinlock_acquire()` to `0`/`1` by masking `R1.b3` to bit0 before moving into `R14.b0` (e.g., `AND` with `0x01`).
2. (Optional hardening) Update the C loop to test bit0 (`(spinlock_acquire(...) & 1) != 0`) so the usage pattern matches the documented semantics even if the helper is reused elsewhere.

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


8. Busy-wait loop lacks bound 📘 Rule violation ☼ Reliability
Description
The assembly acquire loop can spin forever because it has no timeout or max-iteration termination
condition. This can cause non-deterministic firmware behavior and a hard hang if the lock is never
released.
Code

academy/spinlock/spinlock_example.asm[R59-65]

+acquire_lock0:
+    ; Atomic test-and-set: a read of the lock register attempts to take it.
+    lbbo    &LOCK_VAL, SPINLOCK_BASE_REG, LOCK0_OFFSET, 4
+    ; read != 0  -> lock was already held, keep spinning.
+    ; read == 0  -> lock is now OWNED by this PRU, fall through.
+    qbne    acquire_lock0, LOCK_VAL, 0
+
Evidence
PR Compliance ID 5 requires loops in PRU assembly to have explicit termination conditions. The new
acquire_lock0 loop (qbne acquire_lock0, LOCK_VAL, 0) has no counter/timeout exit path, so it can
spin indefinitely.

academy/spinlock/spinlock_example.asm[59-65]
Best Practice: Repository guidelines

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 PRU assembly busy-wait acquire loop has no explicit termination bound, so it can run indefinitely.
## Issue Context
Compliance requires deterministic loops with termination conditions/bounds checking in PRU assembly.
## Fix Focus Areas
- academy/spinlock/spinlock_example.asm[59-65]

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


9. Uses .asg register aliases 📘 Rule violation ⚙ Maintainability
Description
The assembly example allocates registers via .asg aliases instead of using .struct/.sassign.
This increases the risk of register overlap/corruption and violates the required structured register
mapping convention.
Code

academy/spinlock/spinlock_example.asm[R37-40]

+; definitions
+    .asg    R2,    SPINLOCK_BASE_REG   ; holds the Spinlock module base address
+    .asg    R3,    LOCK_VAL            ; scratch for the value read from / written to the lock
+
Evidence
PR Compliance ID 8 requires .struct/.sassign for register allocation. The new example uses `.asg
R2 and .asg R3 to create aliases (SPINLOCK_BASE_REG, LOCK_VAL`) instead of structured
assignments.

academy/spinlock/spinlock_example.asm[37-40]
Best Practice: Repository guidelines

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 assembly code must map registers using `.struct` and `.sassign`, rather than `.asg` aliases to raw `R*` registers.
## Issue Context
Structured register allocation reduces overlap/corruption bugs and improves maintainability.
## Fix Focus Areas
- academy/spinlock/spinlock_example.asm[37-40]

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


10. XIN/XOUT spinlock example missing 📎 Requirement gap ≡ Correctness
Description
The new spinlock lab demonstrates memory-mapped polling (LBBO/SBCO and volatile pointer loops)
rather than the required local spinlock accelerator flow using XIN polling for acquisition status
and XOUT for release. This fails the requirement to provide documented, working PRU Assembly and C
examples specifically showing the __xin/__xout-based mechanism and register-byte ID/status
usage.
Code

academy/spinlock/readme.md[R51-65]

+### Assembly
+
+The spinlock is accessed by reading and writing to the memory-mapped address. The following assembly snippet shows acquiring lock number 0:
+
+```
+        LBBO &r0, r0, CSL_SPINLOCK0_BASE, 4   ; Read the spinlock register (lock 0)
+        QBEQ acquire, r0, 0                   ; If lock is free (0), we got it
+        SPINLOOP:                             ; Otherwise, spin
+        LBBO &r0, r0, CSL_SPINLOCK0_BASE, 4
+        QBNE SPINLOOP, r0, 0
+        acquire:
+        ; ... critical section ...
+        ; Release the lock by writing 0
+        SBCO &r0, r0, CSL_SPINLOCK0_BASE, 4, 1
+```
Evidence
PR Compliance ID 1 requires acquire via XIN polling against the local spinlock XID and release via
XOUT (or equivalent), with documented ID/status handling. The new lab instead documents and
implements memory-mapped polling loops and writes, and does not show XIN/XOUT or __xin/__xout
usage.

Add HW spinlock usage examples to open-pru/academy in both Assembly and C
academy/spinlock/readme.md[51-65]
academy/spinlock/readme.md[67-85]
academy/spinlock/spinlock_example.p[15-34]
academy/spinlock/spinlock_example.c[36-76]

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 spinlock examples use memory-mapped loads/stores and do not demonstrate the required local spinlock accelerator access using XIN/XOUT (and `__xin`/`__xout`). The C example also relies on `SPINLOCK0_BASE` but does not provide a working, self-contained definition/selection, so it is not clearly buildable as-is.
## Issue Context
Compliance requires two working examples (PRU Assembly and C) demonstrating HW spinlock acquire (XIN-based polling on local spinlock XID) and release (XOUT), including documentation/comments mapping: local spinlock XID, spinlock ID byte location, valid ID range, and how the acquisition status is checked.
## Fix Focus Areas
- academy/spinlock/readme.md[51-87]
- academy/spinlock/spinlock_example.p[1-35]
- academy/spinlock/spinlock_example.c[15-76]

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


11. clpru command uses .p ✓ Resolved 📘 Rule violation ≡ Correctness
Description
The documentation instructs building spinlock_example.p with clpru, but .p is a pasm assembly
extension, not a clpru .asm source. This can mislead users and break builds depending on the
selected toolchain.
Code

academy/spinlock/readme.md[R20-24]

+To build the assembly example, you can use the `clpru` assembler:
+
+```bash
+clpru --silicon_version=3 spinlock_example.p
+```
Evidence
PR Compliance ID 17 requires clpru assembly sources to use .asm and pasm sources to use .p. The
README explicitly instructs using clpru on a .p file, conflicting with this requirement.

academy/spinlock/readme.md[20-24]
academy/spinlock/readme.md[11-12]
Best Practice: Repository guidelines

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 shows `clpru` assembling `spinlock_example.p`, but `.p` is intended for pasm, while clpru assembly sources should use `.asm`.
## Issue Context
This repo enforces PRU toolchain/extension conventions to prevent build and user confusion.
## Fix Focus Areas
- academy/spinlock/readme.md[18-26]
- academy/spinlock/spinlock_example.p[1-35]

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


12. Missing TI file headers ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new spinlock_example.c and spinlock_example.p sources do not include the required header
fields including the file name and a Texas Instruments copyright statement. This reduces
traceability and violates the repository’s required legal/header convention.
Code

academy/spinlock/spinlock_example.c[R1-10]

+/*
+ * Spinlock Example - C Version
+ *
+ * This example shows how to use the hardware spinlock module for mutual
+ * exclusion between PRU cores or between PRU and host.
+ *
+ * Note: This example uses direct register access. If your device provides
+ * a Chip Support Layer (CSL) with spinlock APIs, you may prefer to use
+ * those instead for better portability.
+ */
Evidence
PR Compliance ID 15 requires all source files to include a header denoting the file name and a TI
copyright statement. The added C header contains only a descriptive comment without the required
legal text and does not state the file name; the assembly file has no header block at all.

academy/spinlock/spinlock_example.c[1-10]
academy/spinlock/spinlock_example.p[1-14]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New source files are missing required headers: explicit file name and Texas Instruments copyright statement.
## Issue Context
Repository compliance requires standardized headers for traceability and legal compliance.
## Fix Focus Areas
- academy/spinlock/spinlock_example.c[1-14]
- academy/spinlock/spinlock_example.p[1-14]

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


13. Spinlock acquire never claims ✓ Resolved 🐞 Bug ≡ Correctness
Description
acquire_spinlock_lock0() returns after observing the register value without performing any
operation that actually claims the lock, so it does not provide mutual exclusion and can race (or
hang) depending on the HW spinlock semantics. This makes the example incorrect for its stated
purpose (protecting a critical section).
Code

academy/spinlock/spinlock_example.c[R40-49]

+static void acquire_spinlock_lock0(volatile uint32_t *spinlock_base)
+{
+    volatile uint32_t *lock0_reg = spinlock_base; /* lock 0 at offset 0 */
+
+    /* Spin until lock is free (value == 0) */
+    while (*lock0_reg != 0) {
+        /* Optionally add a small delay or yield here */
+    }
+    /* Lock acquired */
+}
Evidence
The acquire helper only spins on reading the register and then returns; there is no atomic
claim/test-and-set behavior demonstrated (no write/claim step and no success-value check).

academy/spinlock/spinlock_example.c[40-49]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`academy/spinlock/spinlock_example.c` has a spinlock “acquire” helper that only polls a value and then returns; it never performs a lock-claiming operation. This defeats mutual exclusion and can lead to multiple agents entering the critical section or incorrect spinning behavior.
### Issue Context
This file is presented as a hardware spinlock usage example; the acquire function must demonstrate an atomic claim pattern consistent with the device’s spinlock semantics.
### Fix Focus Areas
- academy/spinlock/spinlock_example.c[40-49]
### What to change
- Replace the polling loop with the correct hardware acquire sequence (e.g., the documented “read-to-acquire” loop where a successful acquisition is detected and only then the function returns), and update the comments accordingly.
- Keep `release_spinlock_lock0()` consistent with the acquire semantics (often writing 0 releases, but verify against the intended mechanism for this lab).

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



Remediation recommended

14. Spinlock lab not indexed 🐞 Bug ⚙ Maintainability ⭐ New
Description
The new academy/spinlock lab is not listed in academy/readme.md and is not included in
academy/makefile’s SUBDIRS (which drives the recursive academy build), so it won’t be discoverable
via the academy index and won’t be built by make -C academy. This increases the risk the example
drifts/breaks without being noticed.
Code

academy/spinlock/readme.md[R1-5]

+# Spinlock Usage Examples
+
+This lab shows how a PRU core uses the **PRU_ICSSG local hardware spinlock** to get
+mutual exclusion over a resource shared between PRU0, PRU1 and/or the host CPU.
+
Evidence
The PR introduces a new lab under academy/spinlock, but the academy’s top-level README does not
list it among training labs, and the academy top-level makefile only recurses into the directories
listed in SUBDIRS, which does not include spinlock. Therefore, running the standard academy
build won’t build this new lab, and users browsing the academy README won’t discover it.

academy/spinlock/readme.md[1-5]
academy/readme.md[34-51]
academy/readme.md[78-85]
academy/makefile[3-9]
academy/makefile[24-26]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new lab directory (`academy/spinlock`) was added, but it is not referenced from the academy project index (`academy/readme.md`) and it is not part of the academy recursive build (`academy/makefile` SUBDIRS). As a result, users following the academy entry points won’t find it, and it won’t get built when running the standard academy build.

## Issue Context
`academy/makefile`’s `SUBDIRS` list is used as the set of directories to recurse into for `all/pru/host/clean` targets.

## Fix Focus Areas
- academy/readme.md[34-51]
- academy/readme.md[78-85]
- academy/makefile[3-9]
- academy/makefile[24-26]

## Suggested fix
1. Add `spinlock` to the “Training labs” list in `academy/readme.md`.
2. Add a row for `spinlock` in the supported processors table (or explicitly document it as a source-only lab if you don’t want it in the matrix).
3. If you intend it to be built by `make -C academy`, add `spinlock` to `academy/makefile`’s `SUBDIRS` **and** provide whatever minimal build infrastructure that target expects (so the recursive `$(MAKE) -C spinlock ...` invocation works). If it’s intentionally not built, document that explicitly in the academy index so the omission is not accidental.

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


15. R1 clobbered in helpers 🐞 Bug ☼ Reliability
Description
spinlock_acquire()/spinlock_release() modify R1 without saving/restoring it, which is
discouraged for function-style assembly helpers and can lead to caller register corruption if R1
holds live state across the call. This increases the risk that the example behaves differently
depending on compiler allocation and call context.
Code

academy/spinlock/spinlock.asm[R49-51]

+    MOV         R1.b0, R14.b0           ; lock id -> R1.b0 (presented to accel)
+    XIN         INT_SPIN_XID, &R1.b3, 1 ; status returned in R1.b3 (bit0=acquired)
+    MOV         R14.b0, R1.b3           ; return status
Evidence
The helpers visibly write to R1, and the repo’s best_practices.md documents this exact pattern
(using r1 without saving in a function) as a register corruption pitfall with an explicit
save/restore example.

academy/spinlock/spinlock.asm[48-66]
best_practices.md[859-875]

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 C-callable assembly helpers use `R1.b0`/`R1.b3` as scratch registers but do not preserve `R1`. The repo’s best-practices documentation explicitly calls out “using r1 without saving” as a common register-corruption pitfall for function-like assembly.
## Issue Context
Even if current builds happen to work, this is brittle: changes in compiler register allocation or additional code around the calls can expose the corruption.
## Fix Focus Areas
- academy/spinlock/spinlock.asm[48-66]
## Suggested fix options
- Preferred: save/restore `R1` within each helper (e.g., spill to a known scratch register that is safe in your calling convention, then restore before `JMP r3.w2`).
- Alternative: use only registers that are explicitly caller-saved for PRU C-callable assembly (and document which registers are clobbered).
- Also update the function comment block to list clobbered registers explicitly.

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


16. No lock-id range checks ✓ Resolved 📘 Rule violation ⛨ Security
Description
The C helpers accept an arbitrary lock index and directly index into the spinlock register array
without any validation. An out-of-range lock value can access unintended addresses and corrupt
state.
Code

academy/spinlock/spinlock_example.c[R38-50]

+/* lock N lives at base + N*4; as a uint32_t* index that is simply [N]. */
+#define SPINLOCK_REG(base, n)   (((volatile uint32_t *)(base))[(n)])
+
+/*
+ * Blocking acquire: spin until our read returns 0 (which means we just took it).
+ */
+static void spinlock_acquire(uintptr_t base, uint32_t lock)
+{
+    /* Each read is an atomic test-and-set; a non-zero result means "still held". */
+    while (SPINLOCK_REG(base, lock) != 0U) {
+        /* busy-wait; optionally insert a short delay / NOP here */
+    }
+    /* read returned 0 -> we now own the lock */
Evidence
PR Compliance ID 6 requires sanity checks when performance allows. The macro SPINLOCK_REG(base, n)
directly indexes [(n)] and spinlock_acquire() loops on that value with no validation that lock
is within the device's supported lock range (commonly 0–63).

academy/spinlock/spinlock_example.c[38-50]
Best Practice: Repository guidelines

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 spinlock helper APIs do not validate the `lock` index (and therefore may read/write outside the valid lock register range).
## Issue Context
Defensive checks are required when feasible to prevent uncontrolled behavior from invalid inputs.
## Fix Focus Areas
- academy/spinlock/spinlock_example.c[38-50]

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


View more (4)
17. e.g. used in docs ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new README uses the disallowed abbreviation e.g. instead of the required phrasing. This
violates the documentation wording standard intended to keep docs consistent and unambiguous.
Code

academy/spinlock/readme.md[R45-47]

+Not every device in the AM2x family exposes the same Spinlock IP to the PRU. If your
+target has no Spinlock module, use an alternative (e.g. a guarded flag in ICSS shared RAM
+with a consistent owner protocol, or a hardware mailbox). Check your TRM first.
Evidence
PR Compliance ID 14 forbids e.g. and requires "for example" instead. The README line includes
(e.g. a guarded flag in ICSS shared RAM ...), which violates the wording standard.

academy/spinlock/readme.md[45-47]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Docs must not use `e.g.`/`i.e.`/`etc,` per documentation standards.
## Issue Context
Replace `e.g.` with "for example".
## Fix Focus Areas
- academy/spinlock/readme.md[45-47]

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


18. Misleading build steps ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
academy/spinlock/spinlock_example.asm claims it can be built via gmake -all / CCS PRU project
import, but the repo’s academy aggregate makefile does not include the new spinlock lab directory,
so those instructions are not valid for the standard academy build flow.
Code

academy/spinlock/spinlock_example.asm[R25-27]

+;   Steps to build :
+;   - Using makefile: gmake -all
+;   - Using CCS: import the PRU project, build to get .out and firmware .h
Evidence
The assembly file explicitly instructs gmake -all / CCS project import, but the repository’s
academy aggregate makefile does not list academy/spinlock in its SUBDIRS, while the lab README
documents standalone clpru compilation instead.

academy/spinlock/spinlock_example.asm[25-27]
academy/makefile[3-9]
academy/spinlock/readme.md[49-63]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`academy/spinlock/spinlock_example.asm` contains boilerplate build steps (`gmake -all` / CCS project import) that do not apply to this new spinlock lab as currently added, and conflict with the README’s standalone `clpru` commands.
## Issue Context
In this repo, `academy/makefile` controls which labs are built by the aggregate academy build. The new `academy/spinlock` directory is not listed there, so running the academy build will not build this example.
## Fix Focus Areas
- academy/spinlock/spinlock_example.asm[25-27]
- academy/spinlock/readme.md[49-63]
- academy/makefile[3-9]
## Suggested fix
Choose one:
1) **Documentation-only**: Replace the asm file header’s “Using makefile/CCS” text with the same standalone `clpru --silicon_version=... spinlock_example.asm` guidance (or point directly to `academy/spinlock/readme.md`).
2) **Build integration**: Add a proper buildable lab/project structure for `academy/spinlock` and include it in `academy/makefile` `SUBDIRS`, so `make/gmake` builds it as claimed.

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


19. Undefined SPINLOCK0_BASE ✓ Resolved 🐞 Bug ≡ Correctness
Description
spinlock_example.c uses SPINLOCK0_BASE unconditionally, but the file only contains commented-out
candidate #defines, so compiling the example as instructed fails with an undefined macro. This
prevents the example from building out-of-the-box.
Code

academy/spinlock/spinlock_example.c[R63-64]

+    volatile uint32_t *spinlock_base = (volatile uint32_t *)SPINLOCK0_BASE;
+
Evidence
The file uses SPINLOCK0_BASE in main() while both potential #define lines are commented out.
The repo also defines CSL_SPINLOCK0_BASE in its SoC base-address headers, which the example could
reuse instead of an undefined macro.

academy/spinlock/spinlock_example.c[23-25]
academy/spinlock/spinlock_example.c[63-64]
source/include/am243x/cslr_soc_baseaddress.h[412-413]

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 example references `SPINLOCK0_BASE` but does not define it (the only definitions are commented out). This breaks compilation unless the user manually edits the file.
### Issue Context
The repo already carries device base-address headers that define `CSL_SPINLOCK0_BASE`.
### Fix Focus Areas
- academy/spinlock/spinlock_example.c[15-25]
- academy/spinlock/spinlock_example.c[63-64]
### What to change
- Add a compile-time guard:
- If you want users to pass the define via build flags: `#ifndef SPINLOCK0_BASE #error "Define SPINLOCK0_BASE (e.g. CSL_SPINLOCK0_BASE)" #endif`
- Or include the appropriate SoC base-address header and alias: `#define SPINLOCK0_BASE CSL_SPINLOCK0_BASE`.
- Ensure the README build instructions match the chosen approach.

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


20. Misleading PRU assembly snippet ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The README’s PRU assembly snippet uses r0 as the base register without showing it being
initialized to the spinlock base address, and it passes CSL_SPINLOCK0_BASE as an offset into
LBBO/SBCO, which does not match the addressing pattern used in existing PRU assembly code here.
As written, the snippet is incomplete/incorrect and will likely access the wrong address when
followed.
Code

academy/spinlock/readme.md[R56-65]

+        LBBO &r0, r0, CSL_SPINLOCK0_BASE, 4   ; Read the spinlock register (lock 0)
+        QBEQ acquire, r0, 0                   ; If lock is free (0), we got it
+        SPINLOOP:                             ; Otherwise, spin
+        LBBO &r0, r0, CSL_SPINLOCK0_BASE, 4
+        QBNE SPINLOOP, r0, 0
+        acquire:
+        ; ... critical section ...
+        ; Release the lock by writing 0
+        SBCO &r0, r0, CSL_SPINLOCK0_BASE, 4, 1
+```
Evidence
The README snippet dereferences CSL_SPINLOCK0_BASE using r0 as a base register but never shows
r0 being set to that address, and uses the absolute base as an offset. Other PRU assembly in the
repo demonstrates the standard pattern: load the full address into a register and use lbbo/sbbo
with offset 0 for the actual access.

academy/spinlock/readme.md[56-65]
examples/fft/split_radix_fft_4k_single_core/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/lut_load.asm[64-67]
examples/fft/split_radix_fft_4k_single_core/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/main.asm[53-56]

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’s assembly example does not show loading the spinlock base address into a register before using `LBBO`, and it uses an absolute base address as an immediate offset. This is misleading for readers and inconsistent with how PRU assembly in this repo performs memory-mapped accesses.
### Issue Context
Existing PRU assembly uses `ldi32` to load full addresses into a register, and then uses `lbbo`/`sbbo` with small offsets (often 0) for the access.
### Fix Focus Areas
- academy/spinlock/readme.md[53-65]
### What to change
- Update the snippet to:
- Load the base address into a register (e.g., `ldi32 rX, CSL_SPINLOCK0_BASE`).
- Use `lbbo`/`sbbo` with offset `0` (or `lock_id * 4`) and the correct byte count.
- Show the correct loop structure for acquisition and a correct release store.
- Keep the snippet minimal but complete (initialize base register, show correct access form).

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


Grey Divider

Previous review results

Review updated until commit f22b51c

Results up to commit 3164531


🐞 Bugs (2) 📘 Rule violations (6) 📎 Requirement gaps (1)

Context used

Action required
1. main.c header missing filename 📘 Rule violation ⚙ Maintainability ⭐ New
Description
academy/spinlock/main.c has a copyright/SPDX header but does not denote the file name in the
header section. This violates the required source file header convention and reduces traceability.
Code

academy/spinlock/main.c[R1-16]

+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2024-2026 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Spinlock Example - C Version (PRU_ICSSG local hardware spinlock)
+ *
+ * Demonstrates mutual exclusion between PRU0 and PRU1 using the PRU-local
+ * hardware spinlock, accessed over the broadside interface (XIN/XOUT). The
+ * low-level acquire/release are implemented in spinlock.asm; this file shows
+ * the usage pattern.
+ *
+ * Each PRU repeatedly takes the same spinlock, drives a debug GPO high while it
+ * holds the lock, waits a (per-core different) number of cycles, then releases
+ * and drives the debug GPO low. Probing the two debug pins shows that the two
+ * cores never hold the lock at the same time.
+ */
Evidence
PR Compliance ID 18 requires a file header that includes the file name and TI copyright statement.
The added header in main.c includes SPDX and copyright but does not include a File:/file-name
line identifying main.c.

academy/spinlock/main.c[1-16]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`academy/spinlock/main.c` is missing the required header field that denotes the file name.

## Issue Context
The compliance checklist requires each source file header to include both the file name and the TI copyright statement.

## Fix Focus Areas
- academy/spinlock/main.c[1-16]

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


2. TODO marker in main.c 📘 Rule violation ⚙ Maintainability ⭐ New
Description
academy/spinlock/main.c introduces a TODO marker, which is disallowed by the repository marker
standard. This makes tracking inconsistent and violates the required pending-work marker convention.
Code

academy/spinlock/main.c[R35-36]

+/* TODO: pinmux the debug signals (see the GPIO lab) and update the shift to */
+/*       match your board. PRU0 is selected via -DPRU0 in the makefile.      */
Evidence
PR Compliance ID 23 forbids introducing TODO markers. The comment in main.c contains TODO:
indicating pending work.

academy/spinlock/main.c[35-36]
Best Practice: Repository guidelines

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 code introduces a `TODO` marker; the repository standard requires `FIXME` instead.

## Issue Context
Use `FIXME` for pending work markers to keep consistency across the codebase.

## Fix Focus Areas
- academy/spinlock/main.c[35-36]

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

@qodo-code-review

qodo-code-review Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add PRU hardware spinlock examples in assembly and C

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

Grey Divider

AI Description

• Add assembly and C examples for the PRU_ICSSG local hardware spinlock.
• Demonstrate mutual exclusion between PRU0 and PRU1 with observable debug pins.
• Add board-specific builds, R5F firmware loaders, and instructions for running both examples.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: PRU ICSSG spinlock examples.
  • The assembly firmware and R5F loader jointly implement one bounded end-to-end local-spinlock demonstration; the loader is an implementation hop rather than an independent user capability.
  • The two PRU firmware instances, C-callable assembly routine, R5F loader, GPIO configuration, and optional I/O-expander setup jointly implement one bounded shared-resource demonstration.
  • PRU0 and PRU1 are participants in the same behavior, not independent functional scopes.
Behavioral complexity 🟡 Medium 🧩 Coordinated invariants

  • Before: no assembly spinlock demonstration existed in this project path.
  • After: acquisition, ownership, critical-section entry, and release are coordinated across PRU firmware and the R5F loader.
  • New correctness condition: release must use the same lock identifier preserved across the ownership transition.
  • The retry loop itself remains a direct loop.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If release does not clear the acquired hardware lock, the peer remains in its acquisition wait and the assembly demonstration stops making progress.
  • Resetting the PRU/ICSSG state and reloading corrected firmware is required; source rollback alone may not clear an already-owned hardware lock.
  • Reset or restart the PRU/ICSSG subsystem, then load corrected firmware.
  • No persistent application-state repair or external compensation is indicated.
Assessed commit 6db3234
Diagram

graph TD
  R5["R5F loader"] --> C["C firmware"] --> P["Assembly primitives"] --> L["Local spinlock"] --> G["Debug GPOs"]
  R5 --> A["Assembly example"] --> L
  R5 --> G
Loading
High-Level Assessment

Separate assembly-only and C demonstrations make the hardware operation and observable two-core behavior independently teachable. The board-specific project files follow the repository's existing build approach; a shared template would reduce duplication but would add a different build convention for these examples.

Files changed (101) +9159 / -0

Enhancement (11) +800 / -0
spinlock_example.asmDemonstrate broadside spinlock operations in assembly +91/-0

Demonstrate broadside spinlock operations in assembly

• Adds acquire and release macros using XIN/XOUT and an example that acquires lock 0, releases it, and halts.

academy/spinlock/spinlock/firmware/spinlock_example.asm

main.cStart AM243x EVM assembly-example FreeRTOS task +57/-0

Start AM243x EVM assembly-example FreeRTOS task

• Initializes the system and board, then starts a static task that invokes the assembly-example loader.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/main.c

main.cStart LaunchPad assembly-example FreeRTOS task +57/-0

Start LaunchPad assembly-example FreeRTOS task

• Initializes the system and board, then starts a static task that invokes the assembly-example loader.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/main.c

main.cStart AM64x EVM assembly-example FreeRTOS task +57/-0

Start AM64x EVM assembly-example FreeRTOS task

• Initializes the system and board, then starts a static task that invokes the assembly-example loader.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/main.c

spinlock.cLoad assembly firmware onto both PRUs +53/-0

Load assembly firmware onto both PRUs

• Opens ICSSG0, clears both PRU data RAMs, and loads the assembly image on PRU0 and PRU1.

academy/spinlock/spinlock/mcuplus/spinlock.c

main.cDemonstrate two-core spinlock contention +92/-0

Demonstrate two-core spinlock contention

• Both PRUs repeatedly contend for one lock and drive their debug pins only while holding it. A post-release delay gives the other core an opportunity to acquire it.

academy/spinlock/spinlock_c/firmware/main.c

spinlock.asmExpose C-callable broadside spinlock primitives +99/-0

Expose C-callable broadside spinlock primitives

• Implements single-attempt acquire and release with XIN/XOUT, documenting the PRU calling convention and register effects.

academy/spinlock/spinlock_c/firmware/spinlock.asm

main.cStart AM243x EVM C-example FreeRTOS task +57/-0

Start AM243x EVM C-example FreeRTOS task

• Initializes the system and board, then starts a static task that invokes the C-example loader.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/main.c

main.cStart LaunchPad C-example FreeRTOS task +57/-0

Start LaunchPad C-example FreeRTOS task

• Initializes the system and board, then starts a static task that invokes the C-example loader.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/main.c

main.cStart AM64x EVM C-example FreeRTOS task +57/-0

Start AM64x EVM C-example FreeRTOS task

• Initializes the system and board, then starts a static task that invokes the C-example loader.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/main.c

spinlock_c.cLoad C example and route EVM debug signals +123/-0

Load C example and route EVM debug signals

• Loads both PRU firmware images from R5F and configures the EVM I/O expander when needed so their debug signals reach the header.

academy/spinlock/spinlock_c/mcuplus/spinlock_c.c

Documentation (3) +140 / -0
readme.mdIndex spinlock examples and processor support +8/-0

Index spinlock examples and processor support

• Lists the assembly and C examples and records their supported processors.

academy/readme.md

readme.mdDocument the assembly spinlock example +51/-0

Document the assembly spinlock example

• Explains broadside lock semantics, macro usage, supported hardware, and steps for inspecting acquisition in CCS.

academy/spinlock/spinlock/readme.md

readme.mdDocument C spinlock contention example +81/-0

Document C spinlock contention example

• Explains lock semantics, fairness considerations, debug-pin locations, supported hardware, and build and run steps.

academy/spinlock/spinlock_c/readme.md

Other (87) +8219 / -0
makefileRegister both spinlock projects +2/-0

Register both spinlock projects

• Adds both projects to the academy build list. Each entry appears twice in the added lines.

academy/makefile

example.projectspecDefine AM243x EVM PRU0 assembly CCS project +80/-0

Define AM243x EVM PRU0 assembly CCS project

• Configures the PRU0 target, assembly source, linker file, and generated firmware header.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM243x EVM PRU0 assembly memory +52/-0

Map AM243x EVM PRU0 assembly memory

• Places the assembly image in PRU instruction memory and allocates PRU0 data sections.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/linker.cmd

makefileBuild AM243x EVM PRU0 assembly firmware +48/-0

Build AM243x EVM PRU0 assembly firmware

• Selects ICSSG PRU silicon and emits a PRU0 firmware header for the R5F loader.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM243x EVM PRU0 CCS build targets +16/-0

Add AM243x EVM PRU0 CCS build targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM243x EVM PRU1 assembly CCS project +80/-0

Define AM243x EVM PRU1 assembly CCS project

• Configures the PRU1 target, assembly source, linker file, and generated firmware header.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM243x EVM PRU1 assembly memory +52/-0

Map AM243x EVM PRU1 assembly memory

• Places the assembly image in PRU instruction memory and allocates PRU1 data sections.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/linker.cmd

makefileBuild AM243x EVM PRU1 assembly firmware +48/-0

Build AM243x EVM PRU1 assembly firmware

• Selects ICSSG PRU silicon and emits a PRU1 firmware header for the R5F loader.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM243x EVM PRU1 CCS build targets +16/-0

Add AM243x EVM PRU1 CCS build targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM243x LaunchPad PRU0 assembly CCS project +80/-0

Define AM243x LaunchPad PRU0 assembly CCS project

• Configures the LaunchPad PRU0 target, assembly source, linker file, and firmware-header generation.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdMap LaunchPad PRU0 assembly memory +52/-0

Map LaunchPad PRU0 assembly memory

• Allocates PRU0 instruction and data sections for the assembly firmware.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/linker.cmd

makefileBuild LaunchPad PRU0 assembly firmware +48/-0

Build LaunchPad PRU0 assembly firmware

• Builds the ICSSG PRU0 image and generates its R5F-loadable header.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecAdd LaunchPad PRU0 CCS build targets +16/-0

Add LaunchPad PRU0 CCS build targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM243x LaunchPad PRU1 assembly CCS project +80/-0

Define AM243x LaunchPad PRU1 assembly CCS project

• Configures the LaunchPad PRU1 target, assembly source, linker file, and firmware-header generation.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdMap LaunchPad PRU1 assembly memory +52/-0

Map LaunchPad PRU1 assembly memory

• Allocates PRU1 instruction and data sections for the assembly firmware.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/linker.cmd

makefileBuild LaunchPad PRU1 assembly firmware +48/-0

Build LaunchPad PRU1 assembly firmware

• Builds the ICSSG PRU1 image and generates its R5F-loadable header.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecAdd LaunchPad PRU1 CCS build targets +16/-0

Add LaunchPad PRU1 CCS build targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM64x EVM PRU0 assembly CCS project +80/-0

Define AM64x EVM PRU0 assembly CCS project

• Configures the AM64x PRU0 target, assembly source, linker file, and firmware-header generation.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM64x EVM PRU0 assembly memory +52/-0

Map AM64x EVM PRU0 assembly memory

• Allocates PRU0 instruction and data sections for the assembly image.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/linker.cmd

makefileBuild AM64x EVM PRU0 assembly firmware +48/-0

Build AM64x EVM PRU0 assembly firmware

• Builds the ICSSG PRU0 image and generates its R5F-loadable header.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM64x EVM PRU0 CCS build targets +16/-0

Add AM64x EVM PRU0 CCS build targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM64x EVM PRU1 assembly CCS project +80/-0

Define AM64x EVM PRU1 assembly CCS project

• Configures the AM64x PRU1 target, assembly source, linker file, and firmware-header generation.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM64x EVM PRU1 assembly memory +52/-0

Map AM64x EVM PRU1 assembly memory

• Allocates PRU1 instruction and data sections for the assembly image.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/linker.cmd

makefileBuild AM64x EVM PRU1 assembly firmware +48/-0

Build AM64x EVM PRU1 assembly firmware

• Builds the ICSSG PRU1 image and generates its R5F-loadable header.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM64x EVM PRU1 CCS build targets +16/-0

Add AM64x EVM PRU1 CCS build targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile_projectspec

makefileOrchestrate assembly example builds +120/-0

Orchestrate assembly example builds

• Builds PRU0 and PRU1 firmware before optional R5F applications for the supported AM243x and AM64x boards.

academy/spinlock/spinlock/makefile

example.syscfgConfigure AM243x EVM assembly-example host +260/-0

Configure AM243x EVM assembly-example host

• Sets up the R5F application, ICSSG0, and board resources used to load the assembly firmware.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/example.syscfg

example.projectspecDefine AM243x EVM assembly-example R5F CCS project +121/-0

Define AM243x EVM assembly-example R5F CCS project

• Configures the FreeRTOS host project, SysConfig inputs, and generated PRU firmware-header paths.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileBuild AM243x EVM assembly-example R5F image +355/-0

Build AM243x EVM assembly-example R5F image

• Compiles the FreeRTOS loader with MCU+ SDK dependencies and packages its application image.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genPackage AM243x EVM assembly-example CCS image +113/-0

Package AM243x EVM assembly-example CCS image

• Adds CCS post-build conversion and boot-image generation for the R5F application.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecAdd AM243x EVM assembly-example CCS targets +16/-0

Add AM243x EVM assembly-example CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsEnable AM243x EVM FreeRTOS runtime views +12/-0

Enable AM243x EVM FreeRTOS runtime views

• Registers FreeRTOS runtime-object viewer scripts for CCS.

academy/spinlock/spinlock/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

example.syscfgConfigure LaunchPad assembly-example host +259/-0

Configure LaunchPad assembly-example host

• Sets up the R5F application and ICSSG0 resources for loading the assembly firmware.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/example.syscfg

example.projectspecDefine LaunchPad assembly-example R5F CCS project +121/-0

Define LaunchPad assembly-example R5F CCS project

• Configures the FreeRTOS host project, SysConfig inputs, and generated PRU firmware-header paths.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileBuild LaunchPad assembly-example R5F image +355/-0

Build LaunchPad assembly-example R5F image

• Compiles the FreeRTOS loader and packages its MCU+ SDK application image.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genPackage LaunchPad assembly-example CCS image +113/-0

Package LaunchPad assembly-example CCS image

• Adds CCS post-build conversion and boot-image generation for the R5F application.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecAdd LaunchPad assembly-example CCS targets +16/-0

Add LaunchPad assembly-example CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsEnable LaunchPad FreeRTOS runtime views +12/-0

Enable LaunchPad FreeRTOS runtime views

• Registers FreeRTOS runtime-object viewer scripts for CCS.

academy/spinlock/spinlock/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

example.syscfgConfigure AM64x EVM assembly-example host +260/-0

Configure AM64x EVM assembly-example host

• Sets up the R5F application, ICSSG0, and board resources used to load the assembly firmware.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/example.syscfg

example.projectspecDefine AM64x EVM assembly-example R5F CCS project +121/-0

Define AM64x EVM assembly-example R5F CCS project

• Configures the FreeRTOS host project, SysConfig inputs, and generated PRU firmware-header paths.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileBuild AM64x EVM assembly-example R5F image +357/-0

Build AM64x EVM assembly-example R5F image

• Compiles the FreeRTOS loader with MCU+ SDK dependencies and packages its application image.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genPackage AM64x EVM assembly-example CCS image +114/-0

Package AM64x EVM assembly-example CCS image

• Adds CCS post-build conversion and boot-image generation for the R5F application.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecAdd AM64x EVM assembly-example CCS targets +16/-0

Add AM64x EVM assembly-example CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsEnable AM64x EVM FreeRTOS runtime views +12/-0

Enable AM64x EVM FreeRTOS runtime views

• Registers FreeRTOS runtime-object viewer scripts for CCS.

academy/spinlock/spinlock/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

example.projectspecDefine AM243x EVM PRU0 C CCS project +85/-0

Define AM243x EVM PRU0 C CCS project

• Configures the mixed C/assembly PRU0 target, linker file, and generated firmware header.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM243x EVM PRU0 C firmware memory +99/-0

Map AM243x EVM PRU0 C firmware memory

• Defines PRU0 instruction, data, shared, and peripheral regions for the mixed-language image.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/linker.cmd

makefileBuild AM243x EVM PRU0 C firmware +48/-0

Build AM243x EVM PRU0 C firmware

• Builds the mixed-language ICSSG image and generates the PRU0 loader header.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM243x EVM PRU0 C CCS targets +16/-0

Add AM243x EVM PRU0 C CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM243x EVM PRU1 C CCS project +85/-0

Define AM243x EVM PRU1 C CCS project

• Configures the mixed C/assembly PRU1 target, linker file, and generated firmware header.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM243x EVM PRU1 C firmware memory +100/-0

Map AM243x EVM PRU1 C firmware memory

• Defines PRU1 instruction, data, shared, and peripheral regions for the mixed-language image.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/linker.cmd

makefileBuild AM243x EVM PRU1 C firmware +48/-0

Build AM243x EVM PRU1 C firmware

• Builds the mixed-language ICSSG image and generates the PRU1 loader header.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM243x EVM PRU1 C CCS targets +16/-0

Add AM243x EVM PRU1 C CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/firmware/am243x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine LaunchPad PRU0 C CCS project +85/-0

Define LaunchPad PRU0 C CCS project

• Configures the LaunchPad mixed-language PRU0 target and firmware-header generation.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdMap LaunchPad PRU0 C firmware memory +99/-0

Map LaunchPad PRU0 C firmware memory

• Defines PRU0 instruction, data, shared, and peripheral regions for the mixed-language image.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/linker.cmd

makefileBuild LaunchPad PRU0 C firmware +48/-0

Build LaunchPad PRU0 C firmware

• Builds the ICSSG PRU0 image and generates its R5F-loadable header.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecAdd LaunchPad PRU0 C CCS targets +16/-0

Add LaunchPad PRU0 C CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine LaunchPad PRU1 C CCS project +86/-0

Define LaunchPad PRU1 C CCS project

• Configures the mixed-language PRU1 target to use GPO0 for its LaunchPad debug pin.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdMap LaunchPad PRU1 C firmware memory +100/-0

Map LaunchPad PRU1 C firmware memory

• Defines PRU1 instruction, data, shared, and peripheral regions for the mixed-language image.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/linker.cmd

makefileBuild LaunchPad PRU1 C firmware with GPO0 +48/-0

Build LaunchPad PRU1 C firmware with GPO0

• Builds the PRU1 image with DEBUG_PIN_SHIFT=0 and generates its loader header.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecAdd LaunchPad PRU1 C CCS targets +16/-0

Add LaunchPad PRU1 C CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM64x EVM PRU0 C CCS project +85/-0

Define AM64x EVM PRU0 C CCS project

• Configures the mixed C/assembly PRU0 target, linker file, and generated firmware header.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM64x EVM PRU0 C firmware memory +99/-0

Map AM64x EVM PRU0 C firmware memory

• Defines PRU0 instruction, data, shared, and peripheral regions for the mixed-language image.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/linker.cmd

makefileBuild AM64x EVM PRU0 C firmware +48/-0

Build AM64x EVM PRU0 C firmware

• Builds the ICSSG PRU0 image and generates its R5F-loadable header.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM64x EVM PRU0 C CCS targets +16/-0

Add AM64x EVM PRU0 C CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru0_fw/ti-pru-cgt/makefile_projectspec

example.projectspecDefine AM64x EVM PRU1 C CCS project +85/-0

Define AM64x EVM PRU1 C CCS project

• Configures the mixed C/assembly PRU1 target, linker file, and generated firmware header.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

linker.cmdMap AM64x EVM PRU1 C firmware memory +100/-0

Map AM64x EVM PRU1 C firmware memory

• Defines PRU1 instruction, data, shared, and peripheral regions for the mixed-language image.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/linker.cmd

makefileBuild AM64x EVM PRU1 C firmware +48/-0

Build AM64x EVM PRU1 C firmware

• Builds the ICSSG PRU1 image and generates its R5F-loadable header.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile

makefile_projectspecAdd AM64x EVM PRU1 C CCS targets +16/-0

Add AM64x EVM PRU1 C CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/firmware/am64x-evm/icss_g0_pru1_fw/ti-pru-cgt/makefile_projectspec

makefileOrchestrate C example builds +120/-0

Orchestrate C example builds

• Builds both PRU images before optional R5F applications for the supported AM243x and AM64x boards.

academy/spinlock/spinlock_c/makefile

example.syscfgConfigure AM243x EVM C-example pins and host +276/-0

Configure AM243x EVM C-example pins and host

• Configures ICSSG0, the R5F application, and PRU debug-pin routing.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/example.syscfg

example.projectspecDefine AM243x EVM C-example R5F CCS project +122/-0

Define AM243x EVM C-example R5F CCS project

• Configures the FreeRTOS host, SysConfig inputs, PRU firmware headers, and I/O-expander build flag.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileBuild AM243x EVM C-example R5F image +356/-0

Build AM243x EVM C-example R5F image

• Builds the FreeRTOS loader with generated PRU headers and EVM I/O-expander support.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genPackage AM243x EVM C-example CCS image +113/-0

Package AM243x EVM C-example CCS image

• Adds CCS post-build conversion and boot-image generation for the R5F application.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecAdd AM243x EVM C-example CCS targets +16/-0

Add AM243x EVM C-example CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsEnable AM243x EVM C-example runtime views +12/-0

Enable AM243x EVM C-example runtime views

• Registers FreeRTOS runtime-object viewer scripts for CCS.

academy/spinlock/spinlock_c/mcuplus/am243x-evm/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

example.syscfgConfigure LaunchPad C-example debug pins +268/-0

Configure LaunchPad C-example debug pins

• Configures ICSSG0 PRU0 GPO4 and PRU1 GPO0 alongside the R5F application resources.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/example.syscfg

example.projectspecDefine LaunchPad C-example R5F CCS project +121/-0

Define LaunchPad C-example R5F CCS project

• Configures the FreeRTOS host, SysConfig inputs, and generated PRU firmware-header paths.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileBuild LaunchPad C-example R5F image +355/-0

Build LaunchPad C-example R5F image

• Compiles the FreeRTOS loader with generated PRU headers and packages its application image.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genPackage LaunchPad C-example CCS image +113/-0

Package LaunchPad C-example CCS image

• Adds CCS post-build conversion and boot-image generation for the R5F application.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecAdd LaunchPad C-example CCS targets +16/-0

Add LaunchPad C-example CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsEnable LaunchPad C-example runtime views +12/-0

Enable LaunchPad C-example runtime views

• Registers FreeRTOS runtime-object viewer scripts for CCS.

academy/spinlock/spinlock_c/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

example.syscfgConfigure AM64x EVM C-example pins and host +276/-0

Configure AM64x EVM C-example pins and host

• Configures ICSSG0, the R5F application, and PRU debug-pin routing.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/example.syscfg

example.projectspecDefine AM64x EVM C-example R5F CCS project +122/-0

Define AM64x EVM C-example R5F CCS project

• Configures the FreeRTOS host, SysConfig inputs, PRU firmware headers, and I/O-expander build flag.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/example.projectspec

makefileBuild AM64x EVM C-example R5F image +356/-0

Build AM64x EVM C-example R5F image

• Builds the FreeRTOS loader with generated PRU headers and EVM I/O-expander support.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/makefile

makefile_ccs_bootimage_genPackage AM64x EVM C-example CCS image +114/-0

Package AM64x EVM C-example CCS image

• Adds CCS post-build conversion and boot-image generation for the R5F application.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_ccs_bootimage_gen

makefile_projectspecAdd AM64x EVM C-example CCS targets +16/-0

Add AM64x EVM C-example CCS targets

• Provides CCS project export, build, and clean targets.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/makefile_projectspec

syscfg_c.rov.xsEnable AM64x EVM C-example runtime views +12/-0

Enable AM64x EVM C-example runtime views

• Registers FreeRTOS runtime-object viewer scripts for CCS.

academy/spinlock/spinlock_c/mcuplus/am64x-evm/r5fss0-0_freertos/ti-arm-clang/syscfg_c.rov.xs

Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/spinlock_example.c Resolved
Comment thread academy/spinlock/spinlock_example.c Resolved
@qodo-code-review

qodo-code-review Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 035d859

Comment thread academy/spinlock/spinlock_example.asm Resolved
Comment thread academy/spinlock/spinlock_example.asm Resolved
@qodo-code-review

qodo-code-review Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

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

Comment thread academy/spinlock/main.c Resolved
Comment thread academy/spinlock/main.c Resolved
Closes TexasInstruments#120.

Demonstrates the PRU_ICSSG local hardware spinlock accessed over the broadside
interface (XIN/XOUT), as recommended in the issue:

  - lock id (0-63) in R1.b0
  - acquire: XIN 0x90, &R1.b3, 1  -> status in R1.b3 bit 0 (1 = acquired)
  - release: XOUT 0x90, &R1.b3, 1 (same id in R1.b0)

Files:
  - spinlock.asm: C-callable spinlock_acquire()/spinlock_release().
  - main.c: C example - PRU0/PRU1 contend for one lock, scope via debug GPO.
  - spinlock_example.asm: pure-asm example with M_SPINLOCK_ACQUIRE/RELEASE macros.
  - readme.md: usage, semantics, and build notes.

All sources assemble/compile with clpru --silicon_version=3 (ti-cgt-pru 2.3.3);
main.c builds for both PRU0 and PRU1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pratheesh
pratheesh force-pushed the fix/issue-120-spinlock-examples branch from 3164531 to f22b51c Compare June 14, 2026 00:16
@qodo-code-review

qodo-code-review Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

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

Comment thread academy/spinlock/readme.md Resolved
Add the required PRU assembly function metadata (pseudocode, registers
modified, peak cycle count) to spinlock_acquire and spinlock_release,
matching the repo convention (e.g. multicore_scheduler pwm_toggle.asm).
Documents timing and register-clobber assumptions for the low-level
synchronization primitive. Comments only; assembles with clpru 2.3.3.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pratheesh

Copy link
Copy Markdown
Contributor Author

Added the required PRU assembly function metadata to spinlock_acquire/spinlock_release in spinlock.asm (b8f1339): pseudocode, registers modified, and peak cycle count, following the repo convention (e.g. multicore_scheduler/.../pwm_toggle.asm). This documents the timing and register-clobber assumptions for the primitive. Comments-only; assembles with clpru 2.3.3 and CI is green.

Tested on LP-AM243 (ICSSG0 PRU0/PRU1). The lock gives mutual exclusion
(200000/200000 contended increments, zero overlaps), but main.c starved
PRU1: it re-acquired straight after releasing, before PRU1's retry loop
came round, and PRU1 never got the lock in 200 samples. main.c now waits
OUTSIDE_TIME cycles after releasing, and drops the debug pin before the
release so the two pins never overlap on a scope.

readme: --silicon_version=4 for AM64x/AM243x PRU_ICSSG (open-pru's AM243x
makefiles use PRU_VERSION 4; the asm assembles to identical code with
-v3), document that an owner re-acquire also reads 1, and that the lock
is not fair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pratheesh

Copy link
Copy Markdown
Contributor Author

Tested on LP-AM243 silicon (AM2434, ICSSG0 PRU0 + PRU1). The spinlock works as described. The first run found one problem in the C example, fixed in 67c816b.

Test: a CCS-scripted harness that builds the PR's files with clpru -v4 and runs them unmodified on the board, alongside small probe programs (25 checks).

Check Result
Acquire a free id, ids independent (0, 11, 12, 63), release then re-acquire pass
PRU1 cannot take a lock PRU0 holds; gets it after PRU0 releases pass
Two-PRU stress, spinlock.asm unmodified: 100,000 non-atomic increments each 200,000 / 200,000, zero overlaps, 825k failed attempts (contended)
Same loop without the lock (control) lost 87,500 updates, so the test can see a race
spinlock_example.asm unmodified runs to HALT, leaves lock 0 free
main.c on both PRUs, 200 halt-and-read samples of the debug bits see below

Found and fixed: main.c starved PRU1. With the original loop, PRU0 re-acquired straight after releasing, before PRU1's retry loop came round. In 200 samples PRU1 never held the lock (PRU0 199, PRU1 0). The lock is not fair, so the example now waits OUTSIDE_TIME cycles after releasing, and drops the debug pin before the release so the two pins never overlap on a scope. After the fix: PRU0 54, PRU1 134, both 0. That matches the 1000/2000-cycle hold times.

Also in 67c816b (readme):

  • --silicon_version=4 for AM64x/AM243x PRU_ICSSG. The open-pru AM243x makefiles use PRU_VERSION := 4. spinlock.asm and spinlock_example.asm assemble to identical code with -v3 and -v4, so this was a documentation error only.
  • Measured: an acquire by the core that already holds the lock also returns 1. It is not a nesting count, so the readme says not to use the lock recursively.

- spinlock_acquire returns bit 0 of the status only (AND, same cycle
  count), matching the documented 0/1 contract. Silicon returned exactly
  0x00/0x01, so behaviour on LP-AM243 is unchanged.
- spinlock_example.asm macros: pseudocode, registers modified, cycles.
- main.c: file name in the header, no TODO marker, single spaces.
- readme: the busy-wait has no upper bound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pratheesh

Copy link
Copy Markdown
Contributor Author

Pushed ad52b00, which addresses the latest Qodo review. Each of the 7 open threads has a reply and is resolved.

The earlier threads are outdated: they refer to files the PR no longer has.

  • XIN/XOUT example missing (and the SPINLOCK0_BASE / .p sources): both examples now use the local spinlock accelerator through broadside, XIN 0x90, &R1.b3, 1 to acquire and XOUT 0x90, &R1.b3, 1 to release, with the lock id in R1.b0. spinlock_example.asm is the assembly example and main.c + spinlock.asm the C one. The readme documents the XID, the id byte, the status bit and the valid id range.
  • Missing TI file headers: every source file (main.c, spinlock.asm, spinlock_example.asm) carries the SPDX line, the Texas Instruments copyright and the file name.
  • .asg register aliases: there are none left. The examples use R1.b0 / R1.b3 directly, because the accelerator defines those bytes.
  • Busy-wait without a bound: documented as unbounded on purpose, in the readme and in the macro header. What to do on timeout is application policy, so it is left to the caller.

Tested on hardware: the pru_spinlock test passes 25/25 on an LP-AM243 (ICSSG) with exactly this code (2026-10-16 04:30 UTC). It covers acquire, release, contention between PRU0 and PRU1 and the re-acquire case. The -v3 and -v4 builds produce identical code for both assembly files.

Comment thread academy/spinlock/main.c Resolved
Comment thread academy/spinlock/main.c Outdated
/* Spinlock flag id (valid range 0-63). Both PRUs must use the same id. */
#define SPINLOCK_FLAG 11

/* R30 drives the PRU GPO signals; use a debug pin to scope lock ownership. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the vision here to have the customer write code themselves (including creating their own OpenPRU project)? If so, I would want this to be divided into a "classwork" section where the user adds code themselves with the guidance of helpful comments, and a "solutions" folder with the full buildable project. Otherwise, this should be a full project which has all the infrastructure to build from a top-level or project-level make. If there is a separate vision, let's talk, but for now I do want every OpenPRU project merged into the repo to compile from a top-level build (unless you convince me otherwise). Ok to delay this until after #178 gets merged if we want to take advantage of the additional pinmux settings that are in that pull request. Note that there will be a second pull request to add pinmux settings for both PRU0 and PRU1 by default in the near future

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The plan is a full buildable project, not classwork. I'll wait for #178 to merge so the examples can use its pinmux and drive real debug pins, then restructure. Once it's done, both examples will build from the top-level make.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: the example is now two buildable projects, academy/spinlock/spinlock (assembly) and academy/spinlock/spinlock_c (C and assembly). Both are in academy/makefile, so they build from the top-level make (eb27ed6).

Comment thread academy/spinlock/main.c Resolved
Comment thread academy/spinlock/spinlock.asm Resolved
Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/readme.md Resolved
@@ -0,0 +1,89 @@
/*
* SPDX-License-Identifier: BSD-3-Clause

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

After the humans align on the desired project structure (one potential option below, but this might NOT be the structure the humans agree on), please create the project structure by following docs_ai/task_create_project.md

academy
---> spinlock
-------> spinlock
-------> spinlock_c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed: full projects, using your layout:

academy
---> spinlock
-------> spinlock      (assembly: spinlock_example.asm)
-------> spinlock_c    (C: main.c + spinlock.asm, PRU0 and PRU1)

I'll create them with docs_ai/task_create_project.md after #178 merges. Then I'll post a scope capture of the two debug pins from the C project.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in eb27ed6 with the layout above. Each project has PRU0 and PRU1 firmware and an R5F loader for am64x-evm, am243x-evm and am243x-lp. The silicon evidence is in the readme.md thread.

…adme, 2026 headers

spinlock_acquire returns R1.b3 with MOV, as in the issue TexasInstruments#120 reference (same
encoding size and cycles). Readme reduced to what the files are, a pointer to the
PRU Academy spinlock page, and the three behaviours measured on LP-AM243. main.c
points to the c_and_assembly lab and no longer reads as if PRU1 never gets the
lock. spinlock_example.asm notes that R1.b0 must hold the lock id at release.
…ssue TexasInstruments#120 reference

clpru already gives each macro expansion its own \ label (checked: two expansions in one file assemble, and each QBBC loops on its own XIN). Same machine code.
Comment thread academy/spinlock/readme.md Resolved
Comment thread academy/spinlock/readme.md Resolved
Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
@pratheesh

Copy link
Copy Markdown
Contributor Author

The five failing Build jobs on 01e7a829 failed while downloading the MCU+ SDK installer (wget exit 5) before compiling anything. Could a maintainer re-run them? Later runs on main and other PRs pass.

Review on TexasInstruments#142 asked for every merged project to build from the top-level
make. Split the example into two projects that follow the gpio_toggle /
gpio_toggle_c layout from TexasInstruments#178:

- academy/spinlock/spinlock: firmware/spinlock_example.asm (assembly)
- academy/spinlock/spinlock_c: firmware/main.c + firmware/spinlock.asm (C),
  PRU0 and PRU1 firmware

Each builds PRU0 and PRU1 firmware plus an R5F FreeRTOS loader for am64x-evm,
am243x-evm and am243x-lp, and is listed in academy/makefile and
academy/readme.md. am261x/am263x/am62x are N-hw: the local spinlock is a
PRU_ICSSG feature.

spinlock_c debug pins:
- The pinmux for both pins is in example.syscfg. The EVM loader also enables
  the TCA6424 I/O expander, as in TexasInstruments#178. It is guarded by PRU_GPIO_VIA_IOEXP,
  which only the EVM makefiles define, because the LaunchPad has no expander.
- Each core now drives its own GPO4. PRU1 used GPO5, which on LP-AM243 goes
  to the CAN transceiver's MCAN0_STB and to no header.
- The LaunchPad's PRU1 build passes -DDEBUG_PIN_SHIFT=0, because PRU1 GPO4
  reaches no header there either. Its pins are BoosterPack J2.17 (PRU0 GPO4)
  and J2.11 (PRU1 GPO0), per SPRUJ12E.
- The make build now passes -DPRU0/-DPRU1, as the CCS projectspecs already
  did, so main.c's per-core hold time applies there too.
- Dropped the unreachable __halt() after while(1). It caused a compiler
  warning, and the generated code is unchanged.

Built with CCS 21.0, MCU+ SDK am243x 12.01.00.33, SysConfig 1.28.0, clpru
2.3.3 and armllvm 4.0.4:
- `make` in academy/ for am243x exits 0, building both projects.
- `make pru` for am64x exits 0. The am64x R5F loader was not built, because
  no am64x MCU+ SDK is installed here.
- The PRU objects match the 2026-10-16 LP-AM243 hardware run (25/25 passed)
  instruction for instruction. The only difference is PRU1's SET/CLR bit
  number in main.obj.

Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
Comment thread academy/spinlock/spinlock_c/readme.md Resolved
Comment thread academy/spinlock/spinlock/readme.md Resolved
Address the Qodo review findings on the spinlock sources:

- Use lowercase instruction mnemonics, padded to the operand column
  (five spaces after three-letter ops, four after four-letter ops).
- Name the assembly macros m_spinlock_acquire and m_spinlock_release,
  and use a ?-suffixed macro-local label for the acquire retry loop.
- Mark the C-callable spinlock_acquire/spinlock_release with
  .asmfunc/.endasmfunc.
- Mark the acquire busy-wait as INTENTIONALLY_UNBOUNDED_LOOP.
- Document the flag_id range (0-63) at each function, and say how the
  peak cycle counts were obtained (hand-counted, one cycle per
  instruction).
- Add pseudocode comments to the R5F loader functions.

The PRU machine code is unchanged: spinlock.asm and spinlock_example.asm
assemble to the same instruction words as before.

Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
Comment on lines +64 to +65
m_spinlock_release .macro
xout INT_SPIN_XID, &r1.b3, 1 ; release lock held in R1.b0

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. Lock release may not send the lock id it is meant to free 📎 Requirement gap ≡ Correctness

The m_spinlock_release macro issues xout INT_SPIN_XID, &r1.b3, 1, so the byte transferred is the
status register R1.b3 and not the lock id in R1.b0 that the comments and the spec say must be
presented on release. The same operand is used in the C-callable spinlock_release in
spinlock.asm, where the pseudocode says R1.b0 = flag_id then XOUT, but the code never
transfers R1.b0. If the accelerator identifies the lock from the transferred byte, release targets
whatever value the last XIN left in R1.b3 and may not free the lock this core holds, which would
leave the other PRU spinning on a lock nobody releases. This is not checked against hardware, so the
fix should be confirmed against the accelerator's XOUT operand semantics.
Agent Prompt
## Issue description
The spinlock release XOUT transfers R1.b3 (the status byte) while the documented convention presents the lock id in R1.b0. Confirm the accelerator's XOUT operand semantics and make release transfer the lock id that was acquired.

## Fix Focus Areas
- academy/spinlock/spinlock/firmware/spinlock_example.asm[58-65]
- academy/spinlock/spinlock_c/firmware/spinlock.asm[79-94]

## Recommended Fix
In `m_spinlock_release` and `spinlock_release`, make the XOUT source the register that carries the lock id (R1.b0), or document explicitly why R1.b3 is the correct operand and update the pseudocode and readme accordingly. Keep the acquire XIN using `&r1.b3` as status. Verify the release on hardware with a scope or debugger.

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

Dismiss ↗ | View ↗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The hardware disagrees. The silicon test in this PR (LP-AM243, ICSSG0, PRU0 and PRU1 contending) used this PR's spinlock.asm from before c69b3b06, which assembles to the same instruction words: lock id 11, release as xout 0x90, &r1.b3, 1. After a successful acquire, R1.b3 holds 1. If the accelerator took the id from the transferred byte, every release would free lock 1, lock 11 would never be freed, and the other core would spin forever. Instead the lock was handed over 3,999 times, strictly alternating, with 0 overlapping holds. So the id is taken from R1.b0. 70e9b288 states this in the comments, so the operand no longer looks like a bug.

…isters

Address the remaining Qodo review findings on c69b3b0:

- Assert that PRUICSS_open() returned a handle before it is used, in
  both R5F examples. Drivers_open() returns void, so replace the
  misleading "check return status" comment.
- State the preserved registers in the register-usage block of each
  acquire/release routine and macro.
- Say explicitly that the release XOUT uses R1.b3 as its operand while
  the lock id is taken from R1.b0, so R1.b0 must still hold the id.

Signed-off-by: Pratheesh Gangadhar <pratheesh.gangadhar@gmail.com>
Both projects were tested on an LP-AM243 with MCU+ SDK 12.01.00.33 and OpenPRU v2026.02.00. The am64x row is removed because no AM64x hardware was tested.
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.

Create HW spinlock usage examples both assembly/C in open-pru/academy

2 participants