The divider was left at its reset value, so with a pll source
the peripheral input exceeds its limit and the first clocked bit
is corrupted on esp32p4. Compute an even divider that respects
the limit and program it when the device is configured.
Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The interrupt path released the context without waiting, so a
synchronous caller could read the rx buffer while the isr was
still filling it. Wait for completion before releasing.
Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
__ASSERT_MSG_INFO() is an internal helper of <zephyr/sys/__assert.h>, not a
public API. A handful of drivers and inline helpers called it directly to
emit a message without an accompanying assertion.
Replace those direct uses with the appropriate mechanism: LOG_ERR() for the
recoverable runtime error paths in the display, RTC, SPI and CRC code, and
__ASSERT(false, ...) for the out-of-range programming errors in the ADC and
DAC inline helpers.
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
Add macros that treat the QMSPI Mode register's three clock bits (idle
state, transmit phase, sample phase) as a single SPI-mode field to
simplify driver code.
The Control and Descriptor registers' TX and RX DMA-enable fields use
the same value encoding, so share one direction-agnostic set of value
macros (DMA_DIS; LDMA_CH0..2 for local-DMA channels; DMAC_U1B/U2B/U4B
for central-DMA access size) while keeping separate TX/RX get/set
macros. This also corrects the 4-byte TX value, which was 4 (out of
range for the 2-bit field) and is now 3, matching RX.
Update the existing spi_xec_qmspi_ldma.c consumer to the new LDMA_CH0
names; identical field values, so no functional change.
Signed-off-by: Scott Worley <scott.worley@microchip.com>
The driver programmed its devicetree-assigned RX/TX DMA channels with
dma_config() without ever reserving them in the DMA controller's
allocation bitmap. A dma_request_channel(dev, NULL) caller on the same
controller (for example a memory-to-memory transfer) could therefore be
handed a channel already owned by SPI, corrupting both transfers.
Reserve each channel at init through dma_request_channel() with a
BIT(channel) filter. This forces exactly the devicetree channel, marks it
allocated in the shared bitmap so it can no longer be handed out, and
fails init if the channel is already in use.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
Valid slave selects are 0 to SPI_CHIP_SELECT_COUNT - 1, but the guard
used '>', letting slave 4 through to
Cy_SCB_SPI_SetActiveSlaveSelect(). Use '>=' and reword the error
message to match.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Update EUSART driver to use new HAL library that supports both
Series 2 and Series 3 SoCs.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Assert CS with zero-byte transaction since BLE HCI SPI(hci_spi_st.c) driver
relies on zero-byte transaction for asserting CS.
It fixes the SPI communication for radio co-processors (RCP).
Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
Updated to complete peripheral transfer on TXC
Fixed dummysize calculation for multi-buffer transfers
Signed-off-by: Mohamed Azhar <mohamed.azhar@microchip.com>
The RTS5817's SPI is based on snps,designware-spi, but it's not
entirely the same, so DW spi drivers cannot be used directly.
The rts5817 spi driver uses some DW spi code:
1. pin_ctrl is handled in the spi_dw.c code initialization.
2. Several APIs defined in spi_dw.h is used by spi_rts5817.c.
Signed-off-by: Darcy Lu <darcy_lu@realsil.com.cn>
This commit adds an API for writing to the RX_SAMPLE_DLY register,
and also adds the `__maybe_unused` attribute to APIs such as
aux_reg_* and reg_*, so that these APIs can be used in other drivers
that based on snps,designware-spi
Signed-off-by: Darcy Lu <darcy_lu@realsil.com.cn>
Remove the unintialized variable from a DBG print to prevent compiler
warnings when the log level is set to debug.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This change corrects sspi clock query for it8xxx2 register
v2. Additionally, the spi clock must be turned on when
setting ssck equal to sspi_clock.
Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
The property was both `boolean` and `required: true` so it was always
present on nodes with the compatible (i.e., STM32WL5 "SUBGHZSPI" node).
The SPI driver serialized this property into field `use_subghzspi_nss`,
but it really acted as `is_subghzspi` instead... which does not require
a specific property: the SUBGHZSPI node can be identified by its special
compatible `st,stm32-spi-subghz` alone!
Drop the `use-subghz-nss` property from the binding since it is useless,
and update the STM32WL SoC DTSI accordingly. In the STM32 SPI driver,
rename the `use_subghzspi_nss` field to `is_subghzspi` and initialize it
to true iff an SPI node has the special compatible. While at it, inline
function spi_stm32_is_subghzspi() into its only caller and add a comment
explaining why the check is needed to slightly simplify the driver.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
The driver stored the devicetree register address in cfg->base and used
it as a virtual address without ever mapping it. That only works where
the boot page tables already cover the peripheral. On the ZynqMP and
Versal NET APUs they do not, so the SPI_CONF write at the top of
spi_cdns_init() faults.
Convert to the DEVICE_MMIO helpers, which map the region in init() and
drop the assumption that the virtual address equals the physical one.
Also fixes a truncation: base was uint32_t, while DT_INST_REG_ADDR() is
pointer-width.
No functional change on non-MMU targets, where DEVICE_MMIO_IS_IN_RAM is
unset: building drivers.spi.build.spi_cdns for qemu_cortex_m3 before and
after gives byte-for-byte identical disassembly.
Signed-off-by: Iustin Stolniceanu <stolniceanuiustin@gmail.com>
Use %zu instead of %d in LOG_DBG for size_t arguments (fill_len,
offset) to fix -Wformat build warnings.
Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
- spi_context_lock: move the ISR assert from function entry to guard the
actual blocking call (inside !already_locked), so the legitimate
SPI_LOCK_ON fast path is not falsely caught.
- spi_context.h comment: clarify that calling from ISR is legal when the
lock is already held via SPI_LOCK_ON.
- spi.h: point to the RTIO submit path as the correct way to chain
asynchronous transactions, per @teburd and @npitre.
Suggested-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Tibor Kiss <kiss.tibor@gmail.com>
Switch the Cadence SPI driver to use the DEVICE_MMIO API instead
of directly accessing the physical base address from the devicetree.
This is required to support platforms with an active MMU (such as the
Cortex-A9 on Zynq 7000), where accessing unmapped physical addresses
causes MMU translation faults.
Closes#113693
Signed-off-by: Simon Maurer <mail@maurer.systems>
The 16-bit branch of spi_gd32_frame_exchange() read the TX buffer
through a uint8_t pointer, copied from the 8-bit branch, so the high
byte of every 16-bit frame was transmitted as zero. Read a full
16-bit word, matching the RX side.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Some SPI devices need the CS pin to be deasserted between multiple
transceive calls (e.g. the Microchip LAN8651). The MCSPI driver didn't do
this until now and kept the CS pin asserted for hardware controlled CS
pins, except if the channel changed.
This has been changed and additionally during init the GPIO pins are now
also being initialized.
Signed-off-by: Mika Braunschweig <mika.braunschweig@siemens.com>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" drivers/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
lpspi_end_xfer() only clears TCR CONT/CONTC when SPI_HOLD_ON_CS is
absent from the transfer's config, so that consecutive
spi_transceive() calls within a HOLD_ON_CS transaction keep native
(non-GPIO) CS asserted between transfers, as intended.
However, once the caller finishes the whole transaction and calls
spi_release(), those bits were never cleared, leaving native CS
asserted indefinitely - spi_context_unlock_unconditionally() already
force-releases GPIO-based CS via _spi_context_cs_control(ctx, false,
true), but has no way to know about the LPSPI-specific TCR bits for
native CS.
Clear TCR CONT/CONTC directly in spi_lpspi_release() so that
spi_release() actually deasserts native CS as its API contract
implies, matching the existing GPIO CS behavior.
Confirmed on real hardware (FRDM-MCXN947, LPSPI1 native PCS0): CS
previously stayed low indefinitely after the first HOLD_ON_CS
transaction (as used by the Arduino SPI API, which always sets
SPI_HOLD_ON_CS to support multiple transfer() calls per transaction);
with this fix CS correctly returns high after each endTransaction().
Signed-off-by: Tedd OKANO <okano.akifumi@gmail.com>
Updated spi_xec_qmspi_ldma driver with low power support.
Add a pm_action handler that clears MODE.ACTV and applies the
pinctrl sleep state on suspend, and reverses both on resume.
Hold a PM_STATE_SUSPEND_TO_IDLE policy lock for the duration of
each transfer (sync and async) so suspend cannot enter mid-
transaction.
Signed-off-by: Manimaran A <manimaran.a@microchip.com>
Let's avoid a build warning/error in the spim interrupt handler mapping,
by being explicit about passing to it as parameter the address of
`nrfx_spim_t spim` data instead of knowing implicitly that it is the first
element of `struct driver_data`.
This avoid the following build warning/error:
nfx_spim.h:472:42: note: expected 'nrfx_spim_t *' but argument is of
type 'struct driver_data *'
Issue introduced in:
6f2829ea0c
Can be reproduced building
tests/arch/arm/arm_irq_vector_table for thingy53/nrf5340/cpuapp
with CONFIG_SPI_RTIO=y
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Let's avoid a build warning/error in the spim interrupt handler mapping,
by being explicit about passing to it as parameter the address of
`nrfx_spim_t spim` data instead of knowing implicitly that it is the first
element of `struct driver_data`.
This avoid the following build warning/error:
nrfx_spim.h:472:42: note: expected 'nrfx_spim_t *' but argument is of
type 'struct driver_data *'
Issue introduced in:
e4d61fc472
Can be reproduced building
tests/arch/arm/arm_irq_vector_table for thingy53/nrf5340/cpuapp
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The last TX word must be written to FIFOWR as a full 32-bit write to
properly set the EOT (end-of-transfer) control bit at bit 20. Commit
7cb3fca changed the DMA block_size for the last word from
sizeof(uint32_t) to data->word_size_bytes, which meant only the lower
data bytes were transferred, missing the EOT flag entirely.
The issue #107484 mentions that this will cause the last
transfer to be incorrect width, but deep down in the NXP dma driver
there is a fix for this. See dma_mcux_lpc.c (line 262-273).
Fixes: #107484
Signed-off-by: Lars Jeppesen <lje@foss.dk>
The async completion path handed the driver data pointer to
spi_smartbond_pm_policy_state_lock_put(), which expects the device and
forwards it to pm_device_runtime_put(). Pass dev, as every other call
site does.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The driver reads the rate of the configured clock source and
calculates the timing divider against it, but never programs
the hardware mux that selects that source. The mux keeps its
reset value, so the peripheral runs from XTAL while the
divider assumes a PLL rate.
On esp32p4 the default source is the 480 MHz SPLL and the
reset value selects the 40 MHz XTAL, making every transfer 12
times slower than requested: a 1 MHz request measures 83 kHz.
Program the mux at init so it matches the rate the divider is
calculated from.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The syscall handler functions forward parameters with identical casts
that are redundant since the variables already have those types. Drop
the casts to let the compiler type-check the arguments unobstructed.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
On USCI the shallow buffer is not SPI FIFO buffers RX words.
The pipelined pattern can't work. So revised spi_numaker_usci_txrx.
More, USCI SPI only supports 4–16 bit words, not accepts 24/32.
Signed-off-by: cyliang tw <cyliang@nuvoton.com>
The siwx91x SPI driver required to wait for a very small amouth of time
(100ns to 50µs).
When CONFIG_PM is enabled, the granularity of k_busy_wait() is not
sufficient (~32µs). So, the driver implement a raw busy loop.
This busy loop depends on the frequency of the CPU. This was wrongly
retrieved from CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC.
DT_PROP(DT_NODELABEL(cpu0), clock_frequency) is more accurate.
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
When the SPI hardware block is use to send data (without receiving any
data), the DMA callback is called when the data are transmitted to the SPI
controller, but before the data are actually sent over the wire.
Then, the chip-select signal could be released while the Tx was still in
progress.
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
The SPI_STM32_BUSY_FLAG_TIMEOUT option had no help text, leaving
users with no explanation of its purpose when browsing menuconfig. Add
a description that documents how long the driver polls for the BSY flag
to clear after a DMA transfer on STM32F7 and STM32L4 devices affected
by the busy-flag errata.
Assisted-by: OpenAI Codex:gpt-5
Signed-off-by: Collins Culbert <coculbert@icloud.com>
Use <> operator to include a Zephyr header file instead of "" that
is intended to local header files, not header files relative to
specifically defined search paths.
This change was made running the sed shell command below:
$ sed -i -E 's/#include "zephyr\/([^"]+)\.h"/#include <zephyr\/\1.h>/g' \
`grep -rsl "#include \"zephyr/" drivers/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
This commit deploys a workaround for errata 2.21.3 from ES0491 (and similar
for other H7 SoCs).
This prevent the SPI interrupt to fire when SPI is disabled, by disabling
the EOT and TXP interrupt before disabling the SPI.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
The NXP ECSPI represents clock polarity with two separate fields:
channelConfig.polarity (SCLK_POL), the active polarity, and
channelConfig.clockInactiveState (SCLK_CTL), the level SCLK idles at
between bursts. spi_mcux_configure() set polarity from the CPOL bit but
left clockInactiveState at the kECSPI_ClockInactiveStateLow default
applied by ECSPI_MasterGetDefaultConfig().
As a result, transfers to CPOL=1 devices (SPI modes 2 and 3) ran with an
inconsistent clock: the active polarity was inverted as requested while
the idle SCLK level stayed low. Drive clockInactiveState from the same
CPOL bit so the idle level matches the configured mode.
Signed-off-by: Marvin Gnad <marvin.gnad@gmail.com>
When a SPI device uses a GPIO chip select, spi_mcux_configure() initialises
the controller on ECSPI channel 0. However spi_mcux_transfer_next_packet()
started every transfer on transfer.channel = ctx->config->slave.
A device with reg != 0 transfers on an ECSPI channel that was never
configured.
Select the transfer channel the same way spi_mcux_configure() already does:
channel 0 when the chip select is a GPIO, and the slave number only for
native chip selects.
Signed-off-by: Marvin Gnad <marvin.gnad@gmail.com>
Check that the buffer length is a multiple of the data size, and return
an error if it's not the case.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Do not store stack-allocated pointers in the SPI data structure.
Set current_tx and current_rx to NULL since they are not used in RTIO
anyway.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Adapt the STM32 SPI driver so that in RTIO, transactions can be done either
in interrupt or in DMA mode, for different instances (until now, once
CONFIG_SPI_STM32_DMA was enabled, all transactions had to be done with
DMA).
Also use the asynchronous DMA callback for RTIO since it shares a lot of
code.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
The transceive and transceive_dma functions had some similar code.
Factorize them to reduce code duplication. transceive_dma is now called
from the transceive function, and only the latter is called from the
.transceive and .transceive_async API functions.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
This commit fixes issues that could arise notably when only the slave was
sending data (and the master was only receiving). By keeping track of bytes
transmitted in both directions (the context may not keep track of a
direction if the associated buffer is NULL or the length is 0), we prevent
the master side to abort the transmission prematurely.
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Fixes the slave mode for st,stm32h7-spi compatibles by setting the
transfer size also for the slave device, and also waiting for SPI to not be
busy before calling the "complete" function (or else the transaction might
end too early in case where only the slave sends data).
Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
The SAM SPI peripheral natively supports 8-16 bit word sizes via
the SPI_CSR.BITS field, but the driver rejects anything other than
8-bit with -ENOTSUP.
Remove the 8-bit-only restriction and map word_size to the BITS
field. Add 16-bit-wide fast-path transfer functions (TX, RX, TXRX)
for word sizes > 8, where each word occupies a uint16_t in the
buffer. The spi_sam_fast_{tx,rx,txrx} wrappers added in the
previous commit now dispatch to the 8-bit or 16-bit variant based
on the configured word size.
This enables MIPI DBI Type C (3-wire 9-bit SPI) displays and other
peripherals that require non-8-bit word sizes on SAM MCUs.
Tested on SAM4S with a 9-bit SPI display (ILI9806 via MIPI DBI).
Signed-off-by: Ričards Poriņš <ricards.porins@gmail.com>
Rename spi_sam_fast_{tx,rx,txrx} to *_8 to make the 8-bit nature
explicit, and introduce thin wrappers with the original names that
take a device handle and delegate to the _8 variant. Update the
callers in spi_sam_{tx,rx,txrx} to pass the device handle through.
This is a pure refactor with no functional change; it sets up the
follow-up patch that adds 9-16 bit word size support by dispatching
to a 16-bit variant inside the wrapper.
Signed-off-by: Ričards Poriņš <ricards.porins@gmail.com>