Skip to content

Gpio toggle dual core enable - #194

Open
y-motwani wants to merge 2 commits into
TexasInstruments:mainfrom
y-motwani:gpio_toggle_dual_core_enable
Open

y-motwani wants to merge 2 commits into
TexasInstruments:mainfrom
y-motwani:gpio_toggle_dual_core_enable

Conversation

@y-motwani

Copy link
Copy Markdown
Contributor

Adding support for PRU0 and PRU1 cores enabled together for AM64x and AM243x. This toggles both the pins for the core. Updated the readme and main source files with detailed comments and debug steps to help new users.

@y-motwani
y-motwani marked this pull request as draft November 23, 2026 09:27
@qodo-code-review

qodo-code-review Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add PRU1 GPO4 to gpio_toggle examples and document them

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds a PRU1 GPO4 toggle instance to the AM64x and AM243x gpio_toggle (ASM) and gpio_toggle_c (C)
 examples, via a second PruGPIO entry in example.syscfg.
• Documents both examples in code and readmes: PRU1 pin mapping (J2 Row B, Pin 13 of J4), expected
 500 Hz / 1 Hz output, timing references, and debug steps.
• Updates academy/readme.md support matrix so gpio_toggle and gpio_toggle_c show PRU-based support
 (Yport) for AM64x/AM243x instead of N-sw.
Merge Risk 🟢 Low

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: Assembly GPIO-toggle EVM integration, C GPIO-toggle EVM integration.
  • The assembly firmware, its AM64x and AM243x SysConfig mappings, and the R5F loader jointly implement one bounded assembly example whose observable outcome is two PRU GPIO signals; the C example is a separate build and integration.
  • The C firmware, its AM64x and AM243x SysConfig mappings, and the R5F loader jointly implement one bounded C example whose observable outcome is two PRU GPIO signals; the assembly example is a separate build and integration.
Sources

academy/gpio/gpio_toggle/firmware/main.asm[64-69]

; &r0 = start at R0, 120 bytes = 30 registers x 4 bytes = R0 to R29.
    zero    &r0, 120

; Starting with every output low. Without this the
; level of the first half period is unknown.
    ldi     r30, 0

academy/gpio/gpio_toggle/mcuplus/am64x-evm/r5fss0-0_freertos/example.syscfg[52-58]

pruicss1.AdditionalICSSSettings[0].PruGPIO.create(2);
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].$name                     = "CONFIG_PRU_ICSS_GPIO0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.GPO4.$used = true;
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].$name                     = "CONFIG_PRU_ICSS_GPIO1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.GPO4.$used = true;

academy/gpio/gpio_toggle_c/mcuplus/am64x-evm/r5fss0-0_freertos/example.syscfg[52-58]

pruicss1.AdditionalICSSSettings[0].PruGPIO.create(2);
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].$name                     = "CONFIG_PRU_ICSS_GPIO0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.GPO4.$used = true;
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].$name                     = "CONFIG_PRU_ICSS_GPIO1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.GPO4.$used = true;
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before: the assembly example configured and toggled PRU0 without explicitly setting the initial R30 output.
  • After: it adds a direct PRU1 GPO4 mapping and one startup write clearing R30 before the unchanged delay-and-toggle loop.
  • The new conditions are per-core resource mapping and deterministic initial output; no new algorithm, persistent state, concurrency protocol, compatibility transition, or coordinated invariant is introduced.
Sources

academy/gpio/gpio_toggle/firmware/main.asm[64-69]

; &r0 = start at R0, 120 bytes = 30 registers x 4 bytes = R0 to R29.
    zero    &r0, 120

; Starting with every output low. Without this the
; level of the first half period is unknown.
    ldi     r30, 0

academy/gpio/gpio_toggle/mcuplus/am64x-evm/r5fss0-0_freertos/example.syscfg[52-58]

pruicss1.AdditionalICSSSettings[0].PruGPIO.create(2);
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].$name                     = "CONFIG_PRU_ICSS_GPIO0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.GPO4.$used = true;
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].$name                     = "CONFIG_PRU_ICSS_GPIO1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.GPO4.$used = true;
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the mapping or startup change is wrong, this assembly example could fail generation, fail to build, or lose an intended observable output.
  • Repair requires correcting source, regenerating configuration, rebuilding, and redeploying; no persistent or external data is involved.
  • Rebuild and redeploy the corrected or reverted assembly example.
  • A source revert alone does not alter an already running PRU image.
Sources

academy/gpio/gpio_toggle/firmware/main.asm[64-69]

; &r0 = start at R0, 120 bytes = 30 registers x 4 bytes = R0 to R29.
    zero    &r0, 120

; Starting with every output low. Without this the
; level of the first half period is unknown.
    ldi     r30, 0

academy/gpio/gpio_toggle/mcuplus/am64x-evm/r5fss0-0_freertos/example.syscfg[52-58]

pruicss1.AdditionalICSSSettings[0].PruGPIO.create(2);
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].$name                     = "CONFIG_PRU_ICSS_GPIO0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU0";
pruicss1.AdditionalICSSSettings[0].PruGPIO[0].PRU_ICSSG0_PRU.GPO4.$used = true;
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].$name                     = "CONFIG_PRU_ICSS_GPIO1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.$assign    = "PRU_ICSSG0_PRU1";
pruicss1.AdditionalICSSSettings[0].PruGPIO[1].PRU_ICSSG0_PRU.GPO4.$used = true;
Assessed commit c210417
Diagram

graph TD
  A["R5F host app"] --> B["example.syscfg PruGPIO[0]"]
  A --> C["example.syscfg PruGPIO[1]"]
  B --> D["PRU0 GPO4"]
  C --> E["PRU1 GPO4"]
  D --> F(["J2 Pin A13"])
  E --> G(["J2 Pin B13"])
Loading
High-Level Assessment

Driving the second PRU core from the same firmware image and a second PruGPIO entry in syscfg is the standard pattern for multi-core PRU GPIO examples. Documenting the pin mapping and timing in-readme is appropriate for an academy example. No meaningfully different approach was identified that would be clearly better.

Files changed (9) +306 / -78

Documentation (5) +284 / -72
main.asmDocument ASM toggle example and zero output register at init +89/-25

Document ASM toggle example and zero output register at init

• Adds header comments on purpose, the PRU runs-with-host model, and the cycle count (4 x DELAY_COUNT + 7). Adds an explicit ldi r30, 0 after clearing registers. Documents the three ways to change an output pin and removes unused TEMP_REG/OFFSET_ADDR definitions.

academy/gpio/gpio_toggle/firmware/main.asm

readme.mdDocument PRU0/PRU1 GPO4 pins, timing, and debug steps +54/-10

Document PRU0/PRU1 GPO4 pins, timing, and debug steps

• Adds PRU1 GPO4 header mapping (B13 on J2, Pin 13 on J4), an expected-output section with 500 Hz timing and clock caveats, and a six-step debug guide. Also adds AM261-LP and AM261-SOM pin locations.

academy/gpio/gpio_toggle/readme.md

main.cDocument C toggle example and initialize R30 to zero +89/-24

Document C toggle example and initialize R30 to zero

• Adds file header, R30/R31 register explanation, cycle-count and timing notes in the main() comment, and the three output-change methods. Adds __R30 = 0 before the loop and removes the old 0xFFFFFFFF comment.

academy/gpio/gpio_toggle_c/firmware/main.c

readme.mdDocument C example pins, timing, and debug steps +50/-11

Document C example pins, timing, and debug steps

• Adds PRU1 pin mapping, expected 1 Hz output, timing references, and debug steps. Replaces the Supported Combinations section with an Expected output section.

academy/gpio/gpio_toggle_c/readme.md

readme.mdUpdate support matrix for gpio_toggle examples on AM243x/AM64x +2/-2

Update support matrix for gpio_toggle examples on AM243x/AM64x

• Changes the SW-support column for gpio_toggle and gpio_toggle_c from N-sw to Yport, reflecting the PRU-based support now documented.

academy/readme.md

Other (4) +22 / -6
example.syscfgEnable PRU1 GPO4 pinmux on AM243x +5/-1

Enable PRU1 GPO4 pinmux on AM243x

• Changes PruGPIO.create(1) to create(2), adds a PruGPIO[1] entry assigned to PRU_ICSSG0_PRU1 with GPO4 used, and adds a $suggestSolution mapping to PRG0_PRU1_GPO4.

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

example.syscfgEnable PRU1 GPO4 pinmux on AM64x +6/-2

Enable PRU1 GPO4 pinmux on AM64x

• Adds the same second PruGPIO instance for PRU1 GPO4 as the AM243x variant. Adds an explicit $assign for PRU0 and drops the PRU0 $suggestSolution line.

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

example.syscfgEnable PRU1 GPO4 pinmux for C example on AM243x +5/-1

Enable PRU1 GPO4 pinmux for C example on AM243x

• Adds a second PruGPIO instance for PRU_ICSSG0_PRU1 with GPO4 used and a PRG0_PRU1_GPO4 suggested solution.

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

example.syscfgEnable PRU1 GPO4 pinmux for C example on AM64x +6/-2

Enable PRU1 GPO4 pinmux for C example on AM64x

• Adds the PRU1 GPO4 PruGPIO instance and an explicit PRU0 $assign. Removes the PRU0 $suggestSolution line, matching the ASM example.

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

@qodo-code-review

qodo-code-review Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


Action required

Nice, no open findings for this group


Remediation recommended

Nice, no open findings for this group


Informational

Nice, no open findings for this group


@y-motwani
y-motwani force-pushed the gpio_toggle_dual_core_enable branch from bae9bb9 to df083d5 Compare November 23, 2026 10:07
@y-motwani

Copy link
Copy Markdown
Contributor Author

/agentic_review

@y-motwani
y-motwani force-pushed the gpio_toggle_dual_core_enable branch from df083d5 to 8cbb08e Compare November 23, 2026 11:08
Comment thread academy/gpio/gpio_toggle/readme.md Resolved
Comment thread academy/gpio/gpio_toggle/readme.md Resolved
Comment thread academy/gpio/gpio_toggle/readme.md Resolved
Comment thread academy/gpio/gpio_toggle/readme.md Resolved
Comment thread academy/gpio/gpio_toggle/readme.md Resolved
Add a PRU1 GPO instance of the GPIO toggle, assembly
and C examples. This allows toggle of both PRU0 and
PRU 1 core pins simulataneously.

Signed-off-by: Yashraj Motwani <y-motwani@ti.com>
@y-motwani
y-motwani force-pushed the gpio_toggle_dual_core_enable branch from 8cbb08e to 157b0e4 Compare November 24, 2026 08:48
@y-motwani

Copy link
Copy Markdown
Contributor Author

/agentic_review

Comment thread academy/gpio/gpio_toggle/readme.md Resolved
@y-motwani
y-motwani force-pushed the gpio_toggle_dual_core_enable branch from 157b0e4 to d73def7 Compare November 27, 2026 12:23
@y-motwani
y-motwani marked this pull request as ready for review November 27, 2026 12:31
@y-motwani
y-motwani force-pushed the gpio_toggle_dual_core_enable branch from d73def7 to aec1e4f Compare November 30, 2026 06:55
Add comments and documentation to the GPIO toggle
assembly and C examples to make them easier to
follow for users new to the PRU.

- main.asm, main.c: describe what the example teaches
  and who loads the PRU, document the cycle count and
  expected frequency, and describe the three ways to
  change an output pin (overwrite, set/clear, XOR).
- readme.md: document the PRU0 and PRU1 GPO4 pins,
  expected output, PRU clock and timing references,
  and debug steps.

Signed-off-by: Yashraj Motwani <y-motwani@ti.com>
@y-motwani
y-motwani force-pushed the gpio_toggle_dual_core_enable branch from aec1e4f to c210417 Compare December 1, 2026 06:15
Comment thread academy/readme.md Resolved

Cores Tested for AM64x and AM243x: PRU0 and PRU1.
The default pinmux uses PRU0 GPO4. If the pinmux is modified to use PRU1 GPO4 on AM64x and AM243x, probe Pin 13 of the J4 header on the high speed expansion board instead of Pin 9 of the J2 header.
Cores Tested for AM64x and AM243x: PRU0 and PRU1.

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.

are these lines actually needed? Seem to just be repeating info from before

- BP.5 (J1/J3) for AM261-LP
- Pin 93 (J3 row B) for AM261-SOM
- To probe PRU0 GPO4, A13 (J2 Row A) on J2 Header, probe Pin 9 in J2 on TMDS64DC01 EVM (Expansion board) which is connected to the J2 header for AM64x and AM243x
- To probe PRU1 GPO4, B13 (J2 Row B) on J2 Header, probe Pin 13 in J4 on TMDS64DC01 EVM (Expansion board) which is connected to the J2 header for AM64x and AM243x

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.

Don't re-list the EVM pin info if it's already handled above

application asserts on most initialization failures (`Board_driversOpen()`, I/O expander, `PRUICSS_initMemory()`, `PRUICSS_loadFirmware()`). If it halts with an assert, the PRU is never
started. `Drivers_open()` and `PRUICSS_open()` return values are not
checked in this example.
2. **Is the PRU running?** In CCS, connect to the PRU core (for example

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.

Not a good test for if the PRU core is running, since you could randomly attach when the R30 happens to be at 0x10 several times in a row. Better options include the PRU cycle counter, watching the PC counter increment, etc.

If the pin does not toggle, work through steps 1-4. Steps 5 and 6 are
firmware edits to try once the basic example works.

1. **Is the R5F application running?** Open the UART console. The host

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.

I think some of these steps are are generic debug which should probably live somewhere other than within a specific example. Thoughts on in the PRU Getting Started Labs > Lab 5: How to debug PRU firmware? Or somewhere else? https://dev.ti.com/tirex/explore/node?isTheia=false&node=A__ASFrNyRlBnGGirCwEz1a1Q__AM64-ACADEMY__WI1KRXP__LATEST

different pins. See the Overview for which header pin belongs to which core.
5. **Slow it down.** Set `DELAY_COUNT` in `main.asm` to `50000000`, which
gives a half period of about 0.5 s at 200 MHz. You can now see the
signal change on a multimeter or on an LED.

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.

I like the multimeter suggestion

* * Wait for the toggle delay before the next flip
*
* return: none (never returns)
* PEAK cycles per loop iteration: TOGGLE_DELAY_CYCLES + a few cycles

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.

I don't like this. giving a vague "a few cycles" misses the point of giving cycles per loop. Ask me on Friday about the timing results for reading LBBO / LBCO from DMEM / SMEM

* level of the first half period is unknown. */
__R30 = 0;

/* Note: 0xFFFF_FFFF toggles all GPO pins */

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.

I wouldn't mind leaving the note "0xFFFF_FFFF toggles all GPO pins" in the comment above gpio = 0x10;

/* Toggle GPO4 pin */
gpio = 0x10;
/* Three ways to change an output pin. This example uses the third.
* 1. Overwrite: __R30 = 0x10;

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.

Was this validated that it used LDI32 in the disassembly? (i.e., 32 bits overwritten?)

Cores Tested for AM64x and AM243x: PRU0 and PRU1. Default: Enabled for PRU0.

The default pinmux uses PRU0 GPO4. If the pinmux is modified to use PRU1 GPO4 on AM64x and AM243x, probe Pin 13 of the J4 header on the high speed expansion board instead of Pin 9 of the J2 header.
Cores Tested for AM64x and AM243x: PRU0 and PRU1.

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.

apply the same comments from gpio_toggle readme to gpio_toggle_c

Comment thread academy/readme.md
| gpio/gpio_toggle | Y | Y | Y | Y | N-sw | Y |
| gpio/gpio_toggle_c | Y | Yport | Yport | Yport | N-sw | Y |
| gpio/gpio_toggle | Y | Y | Y | Y | Yport | Y |
| gpio/gpio_toggle_c | Y | Yport | Yport | Yport | Yport | Y |

@nsaulnier-ti nsaulnier-ti Dec 3, 2026 •

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.

Yport for AM62x is correct, adding pinmuxing to Linux devicetree should be trivial for the next PR.

Let me know if you need any guidance on how to do that. (pinmux settings need to be associated with a devicetree node, because the pinmux settings don't get applied until the driver for a specific node is probed. So you can't just define a new pinmux section without referencing it from a devicetree node, since it won't actually get applied. The "cheat" is to just add the pinmux settings to an existing pinmux section (after making sure there are no pinmux conflicts), but there might be cleaner or "more correct" ways to do this)

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.

2 participants