-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
base: main
Are you sure you want to change the base?
Conversation
Hello @dimitrije-lilic, and thank you very much for your first pull request to the Zephyr project! |
5507933
to
f2cdf27
Compare
There was a problem hiding this 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.
tests/drivers/spi/spi_loopback/boards/apard32690_max32690_m4.overlay
Outdated
Show resolved
Hide resolved
tests/drivers/spi/spi_loopback/boards/apard32690_max32690_m4.overlay
Outdated
Show resolved
Hide resolved
3375387
to
83a268d
Compare
FYI - #77136 has been merged and can now be incorporated into this PR! |
Hi @ubieda, thanks for the update, I'll add those changes to align my PR with your refactors |
83a268d
to
f006c69
Compare
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlocking a second time?
There was a problem hiding this comment.
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
drivers/spi/spi_max32.c
Outdated
#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, \ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be reverted now
There was a problem hiding this 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.
drivers/spi/spi_max32.c
Outdated
@@ -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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
f006c69
to
37844f8
Compare
There was a problem hiding this 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!
There was a problem hiding this 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.
if (ret == 0) { | ||
spi_max32_iodev_complete(dev, 0); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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>
1f1335c
37844f8
to
1f1335c
Compare
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