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
nRF SPI CS control: CS set / release delay is longer than configured #33583
Comments
@anangl Any estimation when you will have a look into this? |
@etterli These additional delays are caused by the adaptation of the nrfx_spi driver to the Zephyr API that is done in the spi_nrfx_spi shim, in particular, by handling of the scattered buffers that this API permits. The CS line must stay active for potentially multiple SPI transfers so that one call to
and code like this (after including
If you want to use the Zephyr SPI driver for other instances (and you keep If you would like to use the interrupts, you'll need to define an event handler:
and install the interrupt for it:
or maybe better (since the SPI communication is performance-critical):
then change the driver initialization to:
and after calling
When using the interrupts, it would make more sense to switch from SPI to SPIM (so that there is only one interrupt per transfer). You'll basically need to replace all above occurrences of |
@anangl Thank you for explaining the reason for the additional delay and proposing a solution. I haven't tested your solution but found another way to come along with the delays and therefore close this issue. |
Describe the bug
When executing a spi_transceive() on the nRF52840 DK the delay between CS going low and the start of SPI communication and the delay from the end of the SPI communication till CS is going back high does not match the configured delay at all (see picture below) resulting in a reduced throughput as in my application the CS has to return back to high between two transfers.
Legend to picture:
The SPI communication is working as expected. However, in this case the delay is set to
spi_cs_ctrl.delay = 0
(0us) but resulting is a delay oft_d_start = 3.6us
andt_d_end = 12.9us
, respectively. These delays are pretty constant over multiple measurements (+-0.05us).When setting the
spi_cs_ctrl.delay
to longer delays the effective delays are extended by the configured value. So the mechanism to delay the CS change does work properly but the general SPI overhead is quite "slow".Can someone explain why the SPI implementation is causing these delays and whether the undesired delay can be shortened in any way?
To Reproduce
Steps to reproduce the behavior:
zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
with CS connected to P0.29spi_transceive(spi_dev, spi_cfg, &tx, &rx);
t_d_start
from CS going low to start of SPI communicationt_d_end
from end of SPI communication to CS going highspi_cs_ctrl.delay = 1
or any other valid valueExpected behavior
The delay between CS change and SPI transaction is approximately the configured delay and not off by that much for short delays.
Impact
It's a showstopper because the additional delay reduces the possible SPI throughput significantly as after each access the CS has to return high for at least one clock cycle for the used sensor. The desired data throughput cannot be achieved.
Logs and console output
n/a
Environment (please complete the following information):
Additional context
When configuring two SPI transfer at once (see picture below) there is a similar delay of
t_d_2 = 14us
between them. However, the end delay is reduced tot_d_end = 7.6us
whereas the start delay remains the same (t_d_start = 3.6us
).(Ignore wrong SPI value interpretation, this is because of my oscilloscope is not able to parse it over this duration.)
SPI configuration (only code for tx shown):
The text was updated successfully, but these errors were encountered: