Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI Peripheral can only send a single byte #23

Open
SkydiverTricky opened this issue Jan 3, 2025 · 2 comments
Open

SPI Peripheral can only send a single byte #23

SkydiverTricky opened this issue Jan 3, 2025 · 2 comments

Comments

@SkydiverTricky
Copy link

SkydiverTricky commented Jan 3, 2025

Looking at the code in SpiPeripheral : https://github.com/OSVVM/SPI_GuyEschemann/blob/77d1e30c494d0e6032918cde70c179a5b575976a/src/SpiPeripheral.vhd#L267

It appears this code can only send a single byte without raising and re-asserting CSEL. It is pretty common in a SPI interface to send multiple bytes per transaction for as long as the controller holds CSEL low.

Currently, the while loop is exited while, but it then has a
wait until CSEL = '0'

which requires an event on CSEL to re-enter and send more data. This line should probably be:

if CSEL = '1' then wait until CSEL = '0' end if;

but with this, you will need to somehow catch when CSEL rises to 1 if the transaction is actually ended at the end of the current byte.
You could probably do this with the following code:

if CSEL = '1' then 
    wait until CSEL = '0'; 
    bitIdx  := TxData'high;
end if;

if OptSpiMode = 0 or OptSpiMode = 3 then
    wait until falling_edge(SCLK) or CSEL = '1';
else
    wait until rising_edge(SCLK) or CSEL = '1';
end if;

if CSEL = '1' then
    next;
end if;

if bitindex = TxData'high then
    if not Empty(TransmitFifo) then
        TxData := Pop(TransmitFifo);
    else
        TxData := (others => 'X');  -- X would be better here IMO to differentiate from actual data transmission
    end if;
end if;

while CSEL = '0' and BitIdx >= 0 loop
    POCI <= TxData(BitIdx) when OptSpiMode = 0 or OptSpiMode = 2;

    if OptSpiMode = 0 or OptSpiMode = 3 then
        wait until falling_edge(SCLK);
    else
        wait until rising_edge(SCLK);
    end if;

    POCI <= TxData(BitIdx) when OptSpiMode = 1 or OptSpiMode = 3;
    BitIdx := BitIdx - 1;
end loop;

bitIdx  := TxData'high when  bitIdx < 0;
@JimLewis
Copy link
Member

JimLewis commented Jan 3, 2025

I just merged a pull request that purports to add bursting to the SPI VC. It looked like it may address this. I will have to look at it when I get a chance.

There are many things in the VC that do not take advantage of newer OSVVM capabilities.

In the future, can you file these against the submodule directly.

@SkydiverTricky
Copy link
Author

SkydiverTricky commented Jan 3, 2025

I was trying to raise it against the SPI submodule, but it doesnt seem to have an option to raise an issue...

image

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

No branches or pull requests

2 participants