Skip to content

[RFC] Spi controller#134

Closed
DM777-ms wants to merge 2 commits into
OpenDevicePartnership:mainfrom
DM777-ms:spi
Closed

[RFC] Spi controller#134
DM777-ms wants to merge 2 commits into
OpenDevicePartnership:mainfrom
DM777-ms:spi

Conversation

@DM777-ms
Copy link
Copy Markdown

@DM777-ms DM777-ms commented Oct 22, 2024

DM777-ms
DM777-ms commented last week
SPI controller wip.

Currently implementation level: Blocking "transfer()" api can tx and rx on FC5 and EVK board, and forcing chip select 1. With an external loop back, rx matches tx.

Dependent on #235 for fc14 support.

RT685 - SPI (Master) · Issue OpenDevicePartnership/embassy-imxrt#41 · OpenDevicePartnership/embassy-imxrt

REMAINING WORK TODO

SpiBus (master):
Remove chip selects from all SpiBus (SpiController) apis, move to SpiDevice HAL implementation.
Fully support clock speed request. Select source clock that will best match requested SPI CLK, and configure SPI CLK to match the requested frequency in new().

Config options:
(Related Issue #511 Add Support for SetConfig trait · Issue OpenDevicePartnership/embassy-imxrt#511 · OpenDevicePartnership/embassy-imxrt)
-msb/lsb first
-frame delay, pre delay, post delay, transfer delay

Implement apis:
blocking_read()
blocking_write()
Blocking_tranfer() - Mostly done, but needs more testing
blocking_transfer_in_place()
blocking_flush()

async_read()
async_write()
async_transfer()
async_transfer_in_place()
async_flush()

Implement SpiDevice HAL with chip selects:
blocking_read()
blocking_write()
blocking_transfer()
blocking_transfer_in_place()
blocking_flush()

async_read()
async_write()
async_transfer()
async_transfer_in_place()
async_flush()
Dma for async apis

Related work:
Implement FC14/FC15 support.
See issue #79
Add support for flexcomm 14 and 15 · Issue OpenDevicePartnership/embassy-imxrt#79 · OpenDevicePartnership/embassy-imxrt
and PR #235
[RFC] Add support for flexcomm14 and 15 by DM777-ms · Pull Request OpenDevicePartnership/embassy-imxrt#235 · OpenDevicePartnership/embassy-imxrt

Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
@DM777-ms DM777-ms self-assigned this Oct 22, 2024
Comment thread examples/rt685s-evk/src/bin/spi.rs Outdated
Comment thread src/flexcomm.rs Outdated
Comment thread src/flexcomm.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Copy link
Copy Markdown
Contributor

@jerrysxie jerrysxie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface looks good. Instead of focusing on the interface for now, can we focus on getting blocking spi hal up and running. While implementing, we will find quirks in the design and hardware that might feed backs into the design as well.

Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/flexcomm.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
@felipebalbi
Copy link
Copy Markdown
Contributor

Please, make sure to fix the errors and warnings reported by the workflow checkers.

@DM777-ms DM777-ms changed the title [RFC] Spi master [RFC] Spi controller Nov 12, 2024
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment on lines 202 to 205
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be optional, no?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can change them to Option<>, but not sure yet how to handle the later into_ref ...
into_ref!(ssel0);

image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at SpiBus (this WIP), compared to SpiDevice hal apis, it is SpiDevice that includes chip select. So, these actually need to move to a SpiDevice api implementation.

Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment on lines 303 to 309
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl Peripheral<P = impl *Pin<T>> + 'd, also chip selects should be optional

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at SpiBus (this WIP), compared to SpiDevice hal apis, it is SpiDevice that includes chip select. So, these actually need to move to a SpiDevice api implementation.

Comment thread src/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment on lines 259 to 276
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about updating your macro such that you can use like so:

impl_miso!(FLEXCOMM0, PIO0_1, F1, PIO3_0, F5);

(and similarly for other pins)

Comment thread src/spi.rs Outdated
Comment on lines 349 to 360
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, user can decide how many chip selects to use, right? How about taking a slice of chip selects?

    fn new_inner<T: Instance>(
        _bus: impl Peripheral<P = T> + 'd,
        configuration: Config,
        sclk: impl Peripheral<P = impl SclkPin<T>> + 'd,
        mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
        miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
        ssel: &mut [impl Peripheral<P = impl SselPin<T>> + 'd],
        dma_ch_rx: Option<dma::channel::ChannelAndRequest<'d>>,
        dma_ch_tx: Option<dma::channel::ChannelAndRequest<'d>>,
    ) -> Result<Self> {
        // ...
    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at SpiBus (this WIP), compared to SpiDevice hal apis, it is SpiDevice that includes chip select. So, these actually need to move to a SpiDevice api implementation.

Comment thread src/spi.rs Outdated
Comment on lines 443 to 490
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... then this would be carried out with a loop:

for ssel in ssel.iter_mut() {
    into_ref!(ssel);
    ssel.as_ssel();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: I spent some time reading the embedded-hal documentation for SPI. I don't think we can use the embedded SSEL pins. According to the HAL docs, chip selects must implement OutputPin which comes from the GPIO stuff.

https://docs.rs/embedded-hal/latest/embedded_hal/spi/index.html#for-hal-authors

We could, potentially, implement OutputPin for the ssel pins and have that implementation assert the correct SSEL bit in the Spi registers, but the user should be able to instantiate SpiBus and SpiDevice according to what they're trying to achieve.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for finding that. Looks like there will be some additional architectural work to fully support the chip select options. I am going to wait on that until I have the first level of tx/rx data working.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looking at SpiBus (this WIP), compared to SpiDevice hal apis, it is SpiDevice that includes chip select. So, chip select behavior needs to move to a SpiDevice api implementation.

Comment thread src/spi.rs Outdated
@DM777-ms DM777-ms force-pushed the spi branch 6 times, most recently from 0eb424f to d8d745b Compare December 7, 2024 05:32
Comment thread examples/rt685s-evk/src/bin/spi.rs Outdated
Comment thread src/spi.rs Outdated
Comment thread examples/rt685s-evk/src/bin/spi.rs Outdated
Comment thread examples/rt685s-evk/src/bin/spi.rs Outdated
Comment thread examples/rt685s-evk/src/bin/spi.rs Outdated
@DM777-ms DM777-ms force-pushed the spi branch 2 times, most recently from 29c40cf to fe10709 Compare January 7, 2025 19:06
@DM777-ms DM777-ms force-pushed the spi branch 3 times, most recently from 368328b to afa6b38 Compare January 16, 2025 21:05
Comment thread src/spi.rs
info: Info,
_phantom: PhantomData<M>,
config: Config,
//ssel0: Option<PeripheralRef<'d, AnyPin>>,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: remove sseln from SpiBus hal apis, move to SpiDevice hal apis

Comment thread src/spi.rs
spi_instance.info.regs.fifocfg().write(|w|
w.enablerx().enabled().enabletx().enabled().emptyrx().set_bit().emptytx().set_bit());

// spi is disabled, so this just clears the chip selects, and does not initiate fifo transfers
Copy link
Copy Markdown
Author

@DM777-ms DM777-ms Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: delete

Comment thread src/spi.rs
miso.as_miso();
mosi.as_mosi();
// only enable required chip selects
if ssel0.is_some() {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ssel. Implement SpiDevice hal, move ssel to SpiDevice

@jerrysxie jerrysxie closed this Feb 28, 2025
@github-project-automation github-project-automation Bot moved this from In review to Done in ODP Backlog Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants