Skip to content

Conversation

@dlech
Copy link
Collaborator

@dlech dlech commented May 1, 2025

Here is my naive attempt at a fix. 😃 I tested it on AD7606C-18.

PR Description

Fix shift data being shifted beyond word_length in SPI transfers.

In SPI transfers that have word_length (bits per word) that is not 8, 16, or 32, we want the unused bits to all be set to 0. Since the data_sdi_shift register is the same size as DATA_WIDTH, bits are shifted in that register beyond word_length bits. Then this register gets copied to the sdi_data_latch register and eventually makes its way to software. However, some software makes the assumption that the upper bits will be set to 0. Since this isn't the case, it breaks the software.

By adding a mask when we copy data_sdi_shift to sdi_data_latch, we avoid setting those bits.

Fixes: #1695

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)
  • Documentation

PR Checklist

  • I have followed the code style guidelines
  • I have performed a self-review of changes
  • I have compiled all hdl projects and libraries affected by this PR
  • I have tested in hardware affected projects, at least on relevant boards
  • I have commented my code, at least hard-to-understand parts
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe files, Copyright etc)
  • I have not introduced new Warnings/Critical Warnings on compilation
  • I have added new hdl testbenches or updated existing ones

Fix shift data being shifted beyond word_length in SPI transfers.

In SPI transfers that have word_length (bits per word) that is not
8, 16, or 32, we want the unused bits to all be set to 0. Since the
data_sdi_shift register is the same size as DATA_WIDTH, bits are
shifted in that register beyond word_length bits. Then this register
gets copied to the sdi_data_latch register and eventually makes its
way to software. However, some software makes the assumption that
the upper bits will be set to 0. Since this isn't the case, it breaks
the software.

By adding a mask when we copy data_sdi_shift to sdi_data_latch, we
avoid setting those bits.

Fixes: analogdevicesinc#1695
Signed-off-by: David Lechner <dlechner@baylibre.com>
@LBFFilho
Copy link
Contributor

LBFFilho commented May 8, 2025

Closing since as discussed this is better solved in software (unused bits left as undefined behavior)

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.

[BUG] AXI SPI Engine returns junk in higher bits when using bits-per-word less than data_width

2 participants