Skip to content

Commit d61c6e6

Browse files
committed
drivers: stm32: SPI: SPI nocache buffers can be in CONFIG_NOCACHE_MEMORY
CONFIG_NOCACHE_MEMORY is a valid way of declaring buffers in nocache regions. Consider them valid in the stm32 SPI driver nocache check. Also, don't check NULL buffers as the SPI interface states that such buffers will result in sending zeroes. Signed-off-by: Daniel Gaston Ochoa <[email protected]>
1 parent 488fd89 commit d61c6e6

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

drivers/spi/spi_ll_stm32.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ LOG_MODULE_REGISTER(spi_ll_stm32);
2626
#include <zephyr/drivers/clock_control.h>
2727
#include <zephyr/irq.h>
2828

29+
#ifdef CONFIG_NOCACHE_MEMORY
30+
#include <zephyr/linker/linker-defs.h>
31+
#endif /* CONFIG_NOCACHE_MEMORY */
32+
2933
#include "spi_ll_stm32.h"
3034

3135
#define WAIT_1US 1U
@@ -756,24 +760,40 @@ static int wait_dma_rx_tx_done(const struct device *dev)
756760
#ifdef CONFIG_SOC_SERIES_STM32H7X
757761
static bool buf_in_nocache(uintptr_t buf, size_t len_bytes)
758762
{
763+
bool buf_within_nocache = false;
764+
765+
#ifdef CONFIG_NOCACHE_MEMORY
766+
buf_within_nocache = (buf >= ((uintptr_t)_nocache_ram_start)) &&
767+
((buf + len_bytes - 1) <= ((uintptr_t)_nocache_ram_end));
768+
if (buf_within_nocache) {
769+
return true;
770+
}
771+
#endif /* CONFIG_NOCACHE_MEMORY */
772+
759773
for (size_t i = 0; i < ARRAY_SIZE(nocache_mem_regions); i++) {
760774
const struct mem_region *mem_reg = &nocache_mem_regions[i];
761775

762-
const bool buf_within_bounds =
776+
buf_within_nocache =
763777
(buf >= mem_reg->start) && ((buf + len_bytes - 1) <= mem_reg->end);
764-
if (buf_within_bounds) {
778+
if (buf_within_nocache) {
765779
return true;
766780
}
767781
}
768782
return false;
769783
}
770784

785+
static bool is_dummy_buffer(const struct spi_buf *buf)
786+
{
787+
return buf->buf == NULL;
788+
}
789+
771790
static bool spi_buf_set_in_nocache(const struct spi_buf_set *bufs)
772791
{
773792
for (size_t i = 0; i < bufs->count; i++) {
774793
const struct spi_buf *buf = &bufs->buffers[i];
775794

776-
if (!buf_in_nocache((uintptr_t)buf->buf, buf->len)) {
795+
if (!is_dummy_buffer(buf) &&
796+
!buf_in_nocache((uintptr_t)buf->buf, buf->len)) {
777797
return false;
778798
}
779799
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright (c) 2023 Graphcore Ltd, All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
CONFIG_NOCACHE_MEMORY=y
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2023 Graphcore Ltd, All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&spi1 {
8+
dmas = <&dmamux1 0 38 (STM32_DMA_PERIPH_TX | STM32_DMA_PRIORITY_HIGH)
9+
&dmamux1 1 37 (STM32_DMA_PERIPH_RX | STM32_DMA_PRIORITY_HIGH)>;
10+
dma-names = "tx", "rx";
11+
slow@0 {
12+
compatible = "test-spi-loopback-slow";
13+
reg = <0>;
14+
spi-max-frequency = <500000>;
15+
};
16+
fast@0 {
17+
compatible = "test-spi-loopback-fast";
18+
reg = <0>;
19+
spi-max-frequency = <16000000>;
20+
};
21+
};
22+
23+
&dma1 {
24+
status = "okay";
25+
};
26+
27+
&dma2 {
28+
status = "okay";
29+
};
30+
31+
&dmamux1 {
32+
status = "okay";
33+
};

0 commit comments

Comments
 (0)