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

fixed cdc.py bug #261

Closed
wants to merge 1 commit into from
Closed

Conversation

hstarmans
Copy link

@hstarmans hstarmans commented Jun 5, 2024

fixes #101.
You can test the issue by making the following on a fpga. This basically makes sdo equal to sdi.

from amaranth import Elaboratable, Module
from luna.gateware.interface.spi import SPIDeviceInterface
from luna.gateware.utils.cdc import synchronize

from hexastorm.platforms import Firestarter


class DebugSPIExample(Elaboratable):
    """Hardware meant to demonstrate use of
    the Debug Controller's SPI interface copied from Luna"""

    def __init__(self):
        # Base ourselves around an SPI command interface.
        self.interface = SPIDeviceInterface(clock_phase=1)

    def elaborate(self, platform):
        m = Module()
        board_spi = platform.request("debug_spi")

        # Use command interface.
        m.submodules.interface = self.interface

        # Synchronize and connect SPI.
        spi = synchronize(m, board_spi)
        m.d.comb += self.interface.spi.connect(spi)

        # Turn on a single LED, to show something's running.
        led = platform.request("led", 0)
        m.d.comb += led.eq(1)

        # Echo back the last received data.
        m.d.comb += self.interface.word_out.eq(self.interface.word_in)

        return m

You then write bytes and see if you get them back. This is not the case with amaranth at the moment.

import spidev
from gpiozero import LED

spi = spidev.SpiDev()
spi.open(0, 0)
spi.mode = 1
chip_select = LED(select_pin)
chip_select.on()
spi.max_speed_hz = round(1e6)
bts = [210, 222, 230]
previous_byte = None
for idx, byte in enumerate(bts):
    chip_select.off()
    byte_received = spi.xfer([byte])[0]
    chip_select.on()
    if idx != 0:
        try:
            assert previous_byte == byte_received
        except AssertionError:
            print(previous_byte)
            print(byte_received)
            raise Exception("Test failed: not equal")
    previous_byte = byte

@antoinevg antoinevg mentioned this pull request Jun 6, 2024
@antoinevg antoinevg self-requested a review June 6, 2024 06:31
@antoinevg antoinevg self-assigned this Jun 6, 2024
@antoinevg
Copy link
Member

Thank you for submitting this PR!

The changes you made does resolve the compilation problem for your case but unfortunately it also does away with the recursive operation on elements of type Pin.

I'm going to close this PR in favour of an alternative PR that fixes the underlying problem: #263

@antoinevg antoinevg closed this Jun 6, 2024
@hstarmans
Copy link
Author

@antoinevg thanks for your feedback and fix... I will try that one..

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.

debug_spi.py build broken
2 participants