Spi driver demo - #161
Conversation
signed off by Ayushman a-ayushman@ti.com
PR Summary by QodoAdd AM243x PRU eQEP and AM261x SPI driver demos
AI Description
Diagram
High-Level Assessment
Files changed (63)
|
Code Review by Qodo
1. Project skipped by root builds
|
| ABZHandle[i]->baseMemAddr0 = (uint32_t *)( | ||
| ((PRUICSS_HwAttrs *)(gPruIcssXHandle->hwAttrs))->pru0DramBase + | ||
| DMEM_OFFSETS[i] | ||
| ); |
There was a problem hiding this comment.
1. Wrong dmem base channels 🐞 Bug ≡ Correctness
In pru_eqep_example_main(), ABZHandle[i]->baseMemAddr0 is computed from pru0DramBase for all 6 channels, but the PRU1-side firmware channels (RTU_PRU1/PRU1/TX_PRU1) place their buffers in the PRU1 DRAM bank. This causes channels 3–5 to read stale/incorrect ring-buffer data and report wrong speed/position/phase-error results.
Agent Prompt
## Issue description
`pru_eqep_example_main()` initializes each channel’s `baseMemAddr0` using `hwAttrs->pru0DramBase` unconditionally. However, the PRU firmware assigns distinct DMEM base offsets for PRU1-side cores (RTU_PRU1/PRU1/TX_PRU1), which correspond to the PRU1 DRAM bank. As a result, channels 3–5 (PRU1-side) will read from the PRU0 DRAM bank instead of PRU1, producing incorrect diagnostics.
## Issue Context
- Channels 0–2 correspond to PRU0-side cores; channels 3–5 correspond to PRU1-side cores.
- Firmware memory layout shows PRU1-side cores use DMEM offsets in the PRU1 region (e.g., 0x2C00/0x3000/0x3400), which conceptually is `PRU1_DRAM_BASE + {0x0C00,0x1000,0x1400}`.
## Fix
- Compute `baseMemAddr0` with `pru0DramBase` for channels 0–2 and `pru1DramBase` for channels 3–5.
- Keep `DMEM_OFFSETS[i]` as-is (since offsets 3–5 are already the per-bank offsets), but switch the base pointer depending on `i`.
## Fix Focus Areas
- examples/pru_eqep/mcuplus/pru_eqep_example.c[238-259]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // Typedef for ABZ handle | ||
| typedef struct ABZ_Config_s *ABZ_Handle; |
There was a problem hiding this comment.
2. Header missing guards 🐞 Bug ⚙ Maintainability
eqep_diagnostic.h has no include guard and does not include the headers that define types it uses (e.g., uint8_t/uint32_t, PRUICSS_Handle), making it dependent on include order and susceptible to redefinition errors if included multiple times. This can cause brittle build failures as the example evolves or headers are reorganized.
Agent Prompt
## Issue description
`eqep_diagnostic.h` declares public types using `uint8_t`, `uint32_t`, and `PRUICSS_Handle` but does not include headers that define these types, and it lacks an include guard. This makes compilation depend on transitive includes and include order, and can cause redefinition errors if the header is included more than once.
## Issue Context
This header is intended to define shared types (`ABZ_Config`, `ABZ_Handle`) used by the PRU EQEP MCU+ example.
## Fix
- Add an include guard (`#ifndef / #define / #endif`) or `#pragma once`.
- Include required headers directly (at minimum `<stdint.h>`; and whichever project header provides `PRUICSS_Handle`, typically `<drivers/pruicss.h>` in this repo’s examples).
## Fix Focus Areas
- examples/pru_eqep/mcuplus/eqep_diagnostic.h[1-20]
- examples/pru_eqep/mcuplus/eqep_diagnostic.h[33-75]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
45b14ca to
c7b425c
Compare
| PROJECT_NAME := spi_driver | ||
| SUPPORTED_PROCESSORS := am261x |
There was a problem hiding this comment.
1. Project skipped by root builds 🐞 Bug ⚙ Maintainability
The new spi_driver project is not registered in examples/makefile, so repository-wide make, make pru, make host, and make clean silently skip it. This also prevents normal aggregate builds from detecting regressions in the new firmware and host application.
Agent Prompt
## Issue description
The newly added `spi_driver` project has its own build targets but is absent from the parent examples directory list, so aggregate repository builds never invoke it.
## Issue Context
The root build delegates to `examples/makefile`, whose recursive targets process only entries in `SUBDIRS`. Add `spi_driver` to that list and ensure aggregate clean, PRU, and host targets reach the project.
## Fix Focus Areas
- examples/makefile[3-7]
- examples/spi_driver/makefile[7-12]
- examples/spi_driver/makefile[60-80]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| DebugP_log("\r\nEnter command (0-3): "); | ||
| DebugP_scanf("%d", &input); |
There was a problem hiding this comment.
2. Failed input reuses command 🐞 Bug ≡ Correctness
empty_example_main ignores whether DebugP_scanf successfully parsed a value and then validates and dispatches the uninitialized or previously retained input. Malformed or unavailable console input can therefore trigger an unintended SPI transaction, and an unconsumed invalid token can repeat this behavior.
Agent Prompt
## Issue description
The command loop uses `input` even when console parsing fails, allowing an indeterminate or stale command to be sent.
## Issue Context
Initialize the input variable, check the `DebugP_scanf` result before range validation, and consume or otherwise handle invalid input so the same malformed token does not repeatedly fail.
## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[131-133]
- examples/spi_driver/mcuplus/empty_example.c[167-180]
- examples/spi_driver/mcuplus/empty_example.c[182-189]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit c7b425c |
c7b425c to
a278e17
Compare
| if (elapsed >= TRIGGER_POLL_TIMEOUT_US) | ||
| { | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
1. Timeout desynchronizes transactions 🐞 Bug ☼ Reliability
PRU_SPI_runTransaction5 returns on timeout while leaving the outstanding trigger active, and the caller immediately permits another transaction. If the timed-out PRU operation later clears that shared trigger after the retry sets it, the retry reports success and reads responses from the previous transaction.
Agent Prompt
## Issue description
A timed-out SPI transaction remains active because the shared trigger is left set. A late PRU completion can clear the trigger belonging to a subsequent retry, causing stale responses to be accepted as current.
## Issue Context
The PRU clears the same trigger only after publishing its responses, while the application continues its input loop after a timeout. Recovery must not simply clear the trigger while the PRU may still be processing; either stop/reinitialize the PRU transaction state or terminate further transactions, or introduce a sequence-based handshake that distinguishes completions.
## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[156-172]
- examples/spi_driver/mcuplus/empty_example.c[232-235]
- examples/spi_driver/firmware/am261x-lp/icss_m1_pru0_fw/main.asm[365-375]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit a278e17 |
a278e17 to
dc18a4d
Compare
| while (i < 5U) | ||
| { | ||
| DebugP_log(" cmd[%u]: ", i); | ||
| DebugP_scanf("%x", &input); |
There was a problem hiding this comment.
1. Decimal input parsed hexadecimal 🐞 Bug ≡ Correctness
The prompt requests decimal command words, but DebugP_scanf("%x", &input) parses them as
hexadecimal. For example, entering decimal 10 sends 0x10 (16), causing the SPI transaction to
use a different command than the user requested.
Agent Prompt
## Issue description
The console requests decimal command words but parses input using the hexadecimal `%x` conversion, so digit-only values can be transmitted with the wrong numeric value.
## Issue Context
Either parse decimal input with `%u`, or explicitly change the prompt and validation messages to request hexadecimal input.
## Fix Focus Areas
- examples/spi_driver/mcuplus/empty_example.c[215-224]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit dc18a4d |
signed off by Ayushman <a-ayushman@ti.com>
dc18a4d to
41a382f
Compare
|
Code review by qodo was updated up to the latest commit 41a382f |
No description provided.