Skip to content

Conversation

@trns1997
Copy link
Contributor

@trns1997 trns1997 commented Oct 2, 2025

Note: Please adhere to Contributing Guidelines.

Summary

This patch fixes a minor SPI transfer issue in the Kinetis DSPI driver when operating with the transmit and receive FIFOs disabled (MCR[DIS_TXF]=1, MCR[DIS_RXF]=1).

In non-FIFO mode, the DSPI module operates as a simplified double-buffered SPI interface without internal TX staging.

When FIFOs are disabled, PUSHR acts as a single 32-bit command/data block [PUSHR = [command bits | data bits]
]. Partial (16-bit) writes to its upper and lower halves are not guaranteed to combine coherently and can lead to incomplete or corrupted transfers. So the idea is to prepare the 32 bit packet and put with 1 function call instead of doing it in 2 steps, as done when FIFO is enabled.

References:

  • 50.4.2.1 – Master mode
  • 50.4.2.3 – FIFO disable operation
  • 50.4.2.4 – Transmit FIFO buffering mechanism

This change resolves problematic SPI transactions observed with the LAN9252 EtherCAT slave [EasyCAT].

Impact

  • Fixes broken transfers on Kinetis SPI when FIFOs are disabled.
  • Improves compatibility with peripherals that require precise SPI framing (e.g., LAN9252, EasyCAT).
  • No impact on existing DMA or FIFO-enabled configurations.

Testing

Testing was performed on a Kinetis K64F board connected to an EasyCAT (LAN9252-based) EtherCAT slave.

@trns1997 trns1997 marked this pull request as draft October 2, 2025 16:19
@github-actions github-actions bot added Arch: arm Issues related to ARM (32-bit) architecture Board: arm Size: S The size of the change in this PR is small labels Oct 2, 2025
@trns1997 trns1997 changed the title map spi 0 freedom-k64f map and configure spi 0 driver Oct 2, 2025
@acassis
Copy link
Contributor

acassis commented Oct 28, 2025

@trns1997 please fix the coding style issues and add message log in the commits explaining why this patch is necessary, basically to explain which problem are you fixing. Is it necessary to communicate with some SPI device?

@trns1997 trns1997 force-pushed the frdm_k64f_map_spi0 branch 2 times, most recently from e2c689d to 1b62267 Compare November 10, 2025 09:45
@trns1997 trns1997 marked this pull request as ready for review November 10, 2025 09:46
@acassis
Copy link
Contributor

acassis commented Nov 10, 2025

@trns1997 please fix these errors:

nothing to commit, working tree clean
  Configuring...
  Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Building NuttX...
chip/kinetis_spi.c: In function 'kinetis_spibus_initialize':
Error: chip/kinetis_spi.c:1637:3: error: implicit declaration of function 'spi_run' [-Werror=implicit-function-declaration]
 1637 |   spi_run(priv, false);
      |   ^~~~~~~
Error: chip/kinetis_spi.c:1644:13: error: implicit declaration of function 'spi_getreg' [-Werror=implicit-function-declaration]
 1644 |   regval  = spi_getreg(priv, KINETIS_SPI_MCR_OFFSET);
      |             ^~~~~~~~~~
Error: chip/kinetis_spi.c:1646:3: error: implicit declaration of function 'spi_putreg' [-Werror=implicit-function-declaration]
 1646 |   spi_putreg(priv, KINETIS_SPI_MCR_OFFSET, regval);
      |   ^~~~~~~~~~
Error: chip/kinetis_spi.c:1674:24: error: invalid use of undefined type 'struct kinetis_spidev_s'
 1674 |   spi_putreg(priv, priv->ctarsel, 0);
      |                        ^~
Error: chip/kinetis_spi.c:1678:7: error: invalid use of undefined type 'struct kinetis_spidev_s'
 1678 |   priv->nbits = 0;
      |       ^~
Error: chip/kinetis_spi.c:1679:3: error: implicit declaration of function 'spi_setbits' [-Werror=implicit-function-declaration]
 1679 |   spi_setbits(&priv->spidev, 8);

...

nothing to commit, working tree clean
  Configuring...
  Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Building NuttX...
make[1]: *** No rule to make target '/github/workspace/sources/nuttx/arch/arm/src/chip/hardware/kinetis_memorymap.h', needed by 'arm_exception.o'.
make[1]: *** No rule to make target '/github/workspace/sources/nuttx/arch/arm/src/chip/hardware/kinetis_k28memorymap.h', needed by 'arm_exception.o'.
make[1]: *** No rule to make target '/github/workspace/sources/nuttx/include/arch/chip/kinetis_mcg.h', needed by 'arm_allocateheap.o'.
make[1]: Target 'libarch.a' not remade because of errors.
make: *** [tools/LibTargets.mk:170: arch/arm/src/libarch.a] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 385: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory
  [1/1] Normalize freedom-kl25z/nsh

@github-actions github-actions bot added the Size: M The size of the change in this PR is medium label Nov 10, 2025
@simbit18
Copy link
Contributor

simbit18 commented Nov 10, 2025

Hi @trns1997, I have added this PR #17307 for CMake build of NXP Kinetis MCUs. Could you please try it on your board?

Fix a transfer issue in the Kinetis DSPI driver when operating
with transmit and receive FIFOs disabled (`MCR[DIS_TXF]=1`,
`MCR[DIS_RXF]=1`). In this mode, the DSPI module behaves as a
simple double-buffered SPI interface without TX staging.

When FIFOs are disabled, `PUSHR` acts as a single 32-bit
command/data register. Partial (16-bit) writes to its upper or
lower halves can result in incomplete or corrupted transfers.
This patch ensures the full 32-bit packet is prepared and
written in a single operation.

* Resolves broken SPI transactions with LAN9252 (EasyCAT).
* Improves reliability in non-FIFO DSPI configurations.
* No impact on DMA or FIFO-enabled modes.

Signed-off-by: trns1997 <[email protected]>
@trns1997
Copy link
Contributor Author

ping @leducp, this should help us complete the kickcat example :)

@simbit18 simbit18 merged commit 22bc630 into apache:master Nov 12, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Board: arm Size: M The size of the change in this PR is medium Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants