spi shell does not allow for device reconfiguration when spi_context_configured is used #81782
Labels
area: SPI
SPI bus
bug
The issue is a bug, or the PR is fixing a bug
priority: low
Low impact/importance bug
When using
spi conf <device> <frequency> [<settings>]
followed byspi transceive
from the shell, SPI controller drivers that are usingspi_context_configured
(such asspi_ll_stm32.c
) do not allow for subsequent reconfiguration withspi conf
. This means that it is not possible to change clock frequencies, polarity, phase, etc. without a reboot and there is no indication that the new settings did not take effect (besides verifying with a logic analyzer). Found on a STM32 Nucleo board, but appears to be applicable to other platforms as well.This issue is due to
spi_shell.c
using a staticstruct spi_config
whose address never changes, and thespi_context_configured
API is simply checking to see if the address of the last usedstruct spi_config
changed. Since the address never changes, even if the contents change,spi_context_configured
returnstrue
and the new configuration is never applied.I have not investigated the best way of fixing this, but here are a few ideas:
spi_shell.c
perform a dummy / 0 byte SPI transaction with a differentstruct spi_config
structure whenspi conf
is called. This will forcespi_context_configured
to returnfalse
since the address is different and force a reconfiguration on the next transaction. However, this may not work properly with all SPI controller drivers and would require testing.SPI_OP_RECONFIG
flag tospi_operation_t
(used inside ofstruct spi_config
) to forcespi_context_configured
to return false and always force reconfiguration when set. This would be set byspi conf
and optionally cleared afterspi transceive
.spi_context_configured
to perform a better (albeit slower) check, such as hashing the structure.struct spi_config
structure, and swap which structure is used on aspi conf
. This would be fairly complicated to implement correctly though, as the last used config would need to be tracked on a per-controller basis.spi_release
to clear the cachedstruct spi_config
pointer in the context. This is not supported by all controller drivers, would change the semantics ofspi_release
, and would unnecessarily force reconfiguration in some cases.struct spi_config
,To Reproduce
spi conf spi@44002000 80000000
spi transceive aa
<- transceives at ~80MHz, mode 0, MSB first as requestedspi conf spi@44002000 100000 ol
spi transceive aa
<- transceives at ~80MHz, mode 0, MSB first; should be ~100kHz, mode 2, LSB firstExpected behavior
SPI transaction with
spi transceive
is made with requested settings fromspi conf
.Impact
Since the spi shell is mainly for debugging and hardware bringup, this is minor. Given that there is no indication of a potential issue to the user though, they may be inclined to believe that their SPI peripheral is not working instead of the controller settings being incorrect.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: