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

driver:s spi: MAX32 add RTIO support and tests: drivers: spi: spi_loopback: Add support for RTIO tests for APARD32690 board #78346

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dimitrije-lilic
Copy link

Implements the SPIO RTIO API. Refactors internal transcive
fucntios to work with both existing SPI API and RTIO functions.

When SPI_RTIO is enabled the spi_transcieve call translates
the request into an RTIO transaction placed in the queue
that device will execute.

Add overlay for APARD32690 board and add a new test case to
test RTIO functionalities of SPI MAX32 driver.

Signed-off-by: Dimitrije Lilic dimitrije.lilic@orioninc.com

Copy link

Hello @dimitrije-lilic, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@teburd
Copy link
Collaborator

teburd commented Sep 12, 2024

Will take a look, thanks!

I know @ubieda was looking at creating a spi rtio context similar to the i2c rtio context to encompass a lot of the common functionality in #77190 which would likely help avoid some code duplication across drivers

Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

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

Thanks @dimitrije-lilic !

Please have a look at the compliance check, there are some long lines and tabs/spaces issues that need to be fixed.

drivers/spi/spi_max32.c Outdated Show resolved Hide resolved
drivers/spi/spi_max32.c Outdated Show resolved Hide resolved
drivers/spi/spi_max32.c Outdated Show resolved Hide resolved
drivers/spi/spi_max32.c Outdated Show resolved Hide resolved
tests/drivers/spi/spi_loopback/testcase.yaml Outdated Show resolved Hide resolved
@dimitrije-lilic dimitrije-lilic force-pushed the spi_max32_rtio_driver_support branch 3 times, most recently from 3375387 to 83a268d Compare September 16, 2024 17:44
@ubieda
Copy link
Member

ubieda commented Sep 16, 2024

FYI - #77136 has been merged and can now be incorporated into this PR!

@ubieda ubieda self-requested a review September 16, 2024 18:42
@dimitrije-lilic
Copy link
Author

Hi @ubieda, thanks for the update, I'll add those changes to align my PR with your refactors

@@ -287,7 +344,7 @@ static int spi_max32_transceive(const struct device *dev)
spi_context_update_rx(ctx, 1, len);
}
#endif

spi_spin_unlock(dev, key);
Copy link
Member

Choose a reason for hiding this comment

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

Unlocking a second time?

Copy link
Author

Choose a reason for hiding this comment

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

This was moved before line 346, to not cause issues when interrupt drive

Comment on lines 787 to 969
#define DEFINE_SPI_MAX32(_num) \
PINCTRL_DT_INST_DEFINE(_num); \
SPI_MAX32_IRQ_CONFIG_FUNC(_num) \
static const struct max32_spi_config max32_spi_config_##_num = { \
#define DEFINE_SPI_MAX32_RTIO(_num) SPI_RTIO_DEFINE(max32_spi_rtio_##_num, \
CONFIG_SPI_MAX32_RTIO_SQ_SIZE, \
CONFIG_SPI_MAX32_RTIO_CQ_SIZE)

#define DEFINE_SPI_MAX32(_num) \
PINCTRL_DT_INST_DEFINE(_num); \
SPI_MAX32_IRQ_CONFIG_FUNC(_num) \
COND_CODE_1(CONFIG_SPI_RTIO, (DEFINE_SPI_MAX32_RTIO(_num)), ()); \
static const struct max32_spi_config max32_spi_config_##_num = { \
.regs = (mxc_spi_regs_t *)DT_INST_REG_ADDR(_num), \
.pctrl = PINCTRL_DT_INST_DEV_CONFIG_GET(_num), \
.clock = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(_num)), \
.perclk.bus = DT_INST_CLOCKS_CELL(_num, offset), \
.perclk.bit = DT_INST_CLOCKS_CELL(_num, bit), \
MAX32_SPI_DMA_INIT(_num) SPI_MAX32_CONFIG_IRQ_FUNC(_num)}; \
static struct max32_spi_data max32_spi_data_##_num = { \
static struct max32_spi_data max32_spi_data_##_num = { \
SPI_CONTEXT_INIT_LOCK(max32_spi_data_##_num, ctx), \
SPI_CONTEXT_INIT_SYNC(max32_spi_data_##_num, ctx), \
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(_num), ctx)}; \
DEVICE_DT_INST_DEFINE(_num, spi_max32_init, NULL, &max32_spi_data_##_num, \
&max32_spi_config_##_num, PRE_KERNEL_2, CONFIG_SPI_INIT_PRIORITY, \
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(_num), ctx) \
IF_ENABLED(CONFIG_SPI_RTIO, (.rtio_ctx = &max32_spi_rtio_##_num))}; \
DEVICE_DT_INST_DEFINE(_num, spi_max32_init, NULL, &max32_spi_data_##_num, \
&max32_spi_config_##_num, PRE_KERNEL_2, CONFIG_SPI_INIT_PRIORITY, \
Copy link
Member

Choose a reason for hiding this comment

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

Some spurious whitespace changes are adding noise to the diff. Can you revert those please?

Copy link
Author

Choose a reason for hiding this comment

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

Should be reverted now

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.

Driver looks pretty good, maybe missing some coverage for some ops here, and at least to me having a single start transceive function that takes the buffer pointers and a size to transceive would make the most sense to cover both the blocking/non-blocking cases. But this is your driver and you will be maintaining it, so what makes best sense to you is the best option.

@@ -242,19 +272,45 @@ static int spi_max32_transceive(const struct device *dev)
dfs_shift = spi_max32_get_dfs_shift(ctx);

len = spi_context_max_continuous_chunk(ctx);
#ifdef CONFIG_SPI_RTIO
if (sqe->op == RTIO_OP_TINY_TX) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing a switch/case here perhaps to cover RX/TX/TINY_TX/TXRX?

Copy link
Author

Choose a reason for hiding this comment

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

Hi Tom, I agree on this part, its now split to have switch when using RTIO config and old code. I think now its more readable, if you can take a look and let me know if this is ok?

case RTIO_OP_TX:
case RTIO_OP_TINY_TX:
case RTIO_OP_TXRX:
ret = spi_max32_transceive(dev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

transceive might be a bit cleaner if given the buffer pair to work on, given NULL for tx or rx if unidirection perhaps.

Copy link
Author

Choose a reason for hiding this comment

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

Since initially transceive is able to handle all the cases, i didn't want to change core functionality of the drive, but i think now this is covered with previous comment code update

teburd
teburd previously approved these changes Sep 26, 2024
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 good to me!

tbursztyka
tbursztyka previously approved these changes Sep 26, 2024
Copy link
Member

@ubieda ubieda left a comment

Choose a reason for hiding this comment

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

I may be missing something, but I'm under the impression the SPI RTIO is working with sync transfers only?

Please push back if you disagree.

Comment on lines +669 to +689
if (ret == 0) {
spi_max32_iodev_complete(dev, 0);
}
Copy link
Member

@ubieda ubieda Sep 26, 2024

Choose a reason for hiding this comment

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

Shouldn't this be handled asynchronously, otherwise this is a blocking context?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch

Copy link
Author

Choose a reason for hiding this comment

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

Hi @ubieda,
I've reviewed what you said here and took another look at spi_mcux_lpspi. I've modified code to do the async part using Interrupts can you please take a look and see if this is ok?

@@ -23,4 +23,22 @@ config SPI_MAX32_DMA
help
Enable DMA support for MAX32 MCU SPI driver.

if SPI_RTIO
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we rely on CONFIG_SPI_MAX32_INTERRUPT?

data->req.rxData = sqe->txrx.rx_buf;
data->req.txLen = len >> dfs_shift;
data->req.rxLen = len >> dfs_shift;
if (!data->req.rxData) {
Copy link
Collaborator

@teburd teburd Sep 26, 2024

Choose a reason for hiding this comment

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

This shouldn't be needed actually, op_txrx should guarantee both a tx and rx buffer of equivalent length.

Implements the SPIO RTIO API. Refactors internal transcive
fucntios to work with both existing SPI API and RTIO functions.

When SPI_RTIO is enabled the spi_transcieve call translates
the request into an RTIO transaction placed in the queue
that device will execute.

Include the latest refacor changes of RTIO.

Signed-off-by: Dimitrije Lilic <dimitrije.lilic@orioninc.com>
Add overlay for APARD32690 board and add a new test case to
test RTIO functionalities of SPI MAX32 driver.

Signed-off-by: Dimitrije Lilic <dimitrije.lilic@orioninc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: ADI Analog Devices, Inc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants