Skip to content

NXP LPSPI: Fix native CS on non-DMA driver #82877

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

Merged

Conversation

decsny
Copy link
Member

@decsny decsny commented Dec 11, 2024

Have to rework this driver completely to fix the CS because the SDK handle is based on the idea of a transfer being a single buffer, so we can't use the SDK transfer function

depends on:

Fixes #16544
Fixes #63280

tbursztyka
tbursztyka previously approved these changes Jan 27, 2025
bperseghetti
bperseghetti previously approved these changes Jan 27, 2025
@decsny decsny requested a review from ithinuel January 27, 2025 19:12
@decsny decsny dismissed stale reviews from bperseghetti and tbursztyka via 5643ad4 January 27, 2025 19:15
@decsny decsny force-pushed the feature/lpspi_enhancements_3 branch from e606d19 to 5643ad4 Compare January 27, 2025 19:15
@decsny
Copy link
Member Author

decsny commented Jan 27, 2025

rebased to fix conflicts

bperseghetti
bperseghetti previously approved these changes Jan 27, 2025
@mmahadevan108
Copy link
Collaborator

@wearyzen, can you help look at the IRQ additions.

@mmahadevan108
Copy link
Collaborator

@tbursztyka @teburd , can you help look at the changes to the SPI code.


if (!spi_context_tx_on(ctx) && lpspi_is_rx_done(dev)) {
spi_context_complete(ctx, dev, 0);
arch_irq_clear_pending(config->irqn);
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency I think you should use irq_* macros as we have here and use that here instead of calling arch_irq_*

Copy link
Member Author

@decsny decsny Jan 28, 2025

Choose a reason for hiding this comment

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

those macros don't exist for clearing pending, I added this arch_irq_clear_pending one in this PR, and didn't want to fiddle with adding generic APIs supported by all architectures just for one driver's use case

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for not making that clear, what I meant if we are adding an arch_irq_* () apis then we should also add a new irq_clear_pending() macro in generic layer to be consistent with how arch_* apis are used.
Also, I see some other code in drivers using NVIC_ClearPendingIRQ and NVIC_SetPendingIRQ so this is not the only use case.
You can chose to use the NVIC apis directly as others have used but if we add arch_irq_* apis then just defining these 3 seems incomplete. Ideally you would also need to define the arch_irq_* () to z_soc_irq_* () here so things don't break when there is a custom interrupt controller defined with CONFIG_ARM_CUSTOM_INTERRUPT_CONTROLLER.

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, in this case, I will just directly use those CMSIS functions without any zephyr wrapper, because I don't want to address the arch irq code really in this PR, thanks

@decsny
Copy link
Member Author

decsny commented Jan 28, 2025

updated to remove the commit touching the cortex m irq file, and use cmsis function directly instead, and rebased

bperseghetti
bperseghetti previously approved these changes Jan 28, 2025
@jeppenodgaard
Copy link
Collaborator

Looks like this PR also fixes #63280.

Add properties for describing RX and TX fifo sizes.

Also reformat some descriptions and fix the description of the
transfer-delay property which was incorrect. Since zephyr spi bufs are
not continuous, every possible Zephyr LPSPI driver must use
continuous transfer mode, for which the meaning of this delay has
nothing to do with the chip select.

Signed-off-by: Declan Snyder <[email protected]>
Add functions to get remaining length in the transfer. Refactor a bit to
avoid duplicate code for the for loop that is the same as in the total
length function.

The difference between the total length and left length function is that
the current buffer total length is counted in the former and the current
buffer remaining length is counted in the latter.

Signed-off-by: Declan Snyder <[email protected]>
To fix the native hardware chip select, we need to rewrite this driver
to not use the MCUX SDK handle abstraction, which does not fit the
zephyr use case.

Signed-off-by: Declan Snyder <[email protected]>
@decsny
Copy link
Member Author

decsny commented Jan 29, 2025

rebased to fix conflict with recently-enabled lpspi on mcxa156, and added a fix to an incorrect description of the transfer-delay property in the binding

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

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

Looks fine to me. I wouldn't bother implementing the transcieve_async API though as its not actually async (can block at any time, not usable from any context). To support rtio natively with this driver doesn't seem that far off, it requires using a different context with different functions to get the next read/write/transcieve and inform when the task is complete slightly different.

@kartben kartben merged commit 62b911f into zephyrproject-rtos:main Jan 30, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM ARM (32-bit) Architecture area: SPI SPI bus platform: NXP Drivers NXP Semiconductors, drivers platform: NXP MPU platform: NXP S32 NXP Semiconductors, S32 platform: NXP NXP
Projects
None yet