zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.49k stars 6.42k forks source link

drivers:led_strip Sample not working for MIMXRT1050 with DMA en DCACHE enabled #71305

Open allemanm opened 5 months ago

allemanm commented 5 months ago

Describe the bug I build and run samples/drivers/led_strip/ on the MIMXRT1050_EVK with DMA enabled for LPSPI. However, no data is put on MOSI pin. When I disable DCACHE, the data is put on the bus properly. I checked out Zephyr on commit f86f390baf27a48768b6bd3cd1285b54970c537c

To Reproduce Steps to reproduce the behavior:

  1. Edit prj.conf by adding CONFIG_SPI_MCUX_LPSPI_DMA=y
  2. Edit mimxrt1050_evk.overlay by changing &lpspi3 to &lpspi1
  3. Run west build -p -b mimxrt1050_evk samples/drivers/led_strip/
  4. west flash -r jlink
  5. No signal on the MOSI pin
  6. Edit prj.conf by adding CONFIG_DCACHE=n
  7. Build and flash
  8. Signal is visible on MOSI pin

prj.conf

CONFIG_LOG=y
CONFIG_LED_STRIP=y
CONFIG_LED_STRIP_LOG_LEVEL_DBG=y
CONFIG_SPI_MCUX_LPSPI_DMA=y

mimxrt1050_evk.overlay

#include <zephyr/dt-bindings/led/led.h>

&lpspi1 {
    led_strip: ws2812@0 {
        compatible = "worldsemi,ws2812-spi";

        /* SPI */
        reg = <0>; /* ignored, but necessary for SPI bindings */
        spi-max-frequency = <6400000>;

        /* WS2812 */
        chain-length = <2>; /* arbitrary; change at will */
        spi-cpha;
        spi-one-frame = <0xf0>; /* 11110000: 625 ns high and 625 ns low */
        spi-zero-frame = <0xc0>; /* 11000000: 312.5 ns high and 937.5 ns low */
        color-mapping = <LED_COLOR_ID_GREEN
                 LED_COLOR_ID_RED
                 LED_COLOR_ID_BLUE>;
    };
};

/ {
    aliases {
        led-strip = &led_strip;
    };
};

Expected behavior I would expect the lpspi driver to work properly when both CONFIG_SPI_MCUX_LPSPI_DMA and CONFIG_DCACHE are enabled.

Logs and console output With DCACHE disabled there is a signal on the MOSI pin image

Environment (please complete the following information):

dleach02 commented 3 months ago

@EmilioCBen, take a look at this when we get to feature freeze

DerekSnell commented 3 months ago

Hi @allemanm ,

Since this issue depends on the DMA and is affected by the cache, I suspect the cause of this issue is that the buffer used by the SPI driver is cached. On the RT1050, by default the linker places data in the external SDRAM, which is all cached. The cache is only for the M7 CPU. So it seems likely the issue here is that when the app writes to the pixels buffer, it is written to the cache. But that buffer in SDRAM is not updated, and therefore the DMA does not read the same data.

If using the DMA on a platform like this, the app should place the DMA buffers in non-cacheable memory. The spi_loopback test does this by placing the buffers in the .nocache region.

Best regards

github-actions[bot] commented 1 month ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.