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

LPSPI Fix Timeout waiting for transfer complete #87548

Merged
merged 3 commits into from
Mar 26, 2025

Conversation

PetervdPerk-NXP
Copy link
Collaborator

In certain usecases SPI tranceive would trigger the following error and would be blocking the bus as well.

[00:00:00.222,000] <err> spi_mcux_lpspi: Timeout waiting for transfer complete

This PR fixes that by changing the ISR logic to ensure that on TX a NOP will be transmitted fixing this timeout race condition.
Also it checks now the output spi_context_wait_for_completion so when a timeout occurs it will release spi lock fixing a locking issue as well.

Also we reset the LPSPI peripheral now on startup to ensure the LPSPI in POR state when starting zephyr.

Tested on

  • VMU_RT1170
  • IMX95_EVK

Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

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

This does cause #87144 to fail, but since it's not merged yet I can't complain, I'll debug that

The unlock code seems right, should work for slave mode since rv would be >=0 if success also.

As for the main change here which is to the isr, I think it seems right to me and I think I prefer it to the old code. It seems logically more robust because maybe there could have been a case before where there was 1 more RX left and also TX fifo was empty, so before it would not have filled a NOP due to the code to do so was conditional on the RX len not being 1, which was probably wrong. So I think this handles that case and I can't think of a problem this would cause, I think in all cases we want to handle sending TX nops if there is ever any RX left, no matter if it is 1 or otherwise. (1 being the special case due to RT stalling behavior, but you said you tested on there, so probably fine). I will probably test on RT1050 before this merges in case it has a different LPSPI version.

@@ -153,6 +154,8 @@ int spi_nxp_init_common(const struct device *dev)
return err;
}

LPSPI_Reset(base);
Copy link
Member

Choose a reason for hiding this comment

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

why was this needed ? just wondering.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the IMX95 we load code into ITCM and execute from there due to that there's no POR.
Thus we can't guarantee that the LPSPI in the right state on startup, so I prefer to reset a peripheral on initialization.

Copy link
Member

Choose a reason for hiding this comment

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

ok, just FYI, I was planning to hardware reset peripheral at module level, in the PR I linked above, but we can do software peripheral reset also

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well not every chip has a RESET_ReleasePeripheralReset interface whereas each LPSPI has a LPSPI_Reset.
So if you really want to use RESET_ReleasePeripheralReset you would have to implement a fallback anyhow.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I know, but actually the hardware signal reset is required on some platforms anyways before interfacing to the peripheral, even to do a software reset. But like I said I have no issue with this

Fixes wait for completion problems where the ISR was not sending
out TX NOP's when needed causing the transfer to timeout

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
Ensure that LPSPI is in POR state when initializing

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
When spi_mcux_dma_next_fill failed it return without releasing
the lock

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
@kartben kartben merged commit c09a4ba into zephyrproject-rtos:main Mar 26, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: NXP Drivers NXP Semiconductors, drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants