Skip to content

Commit dc11050

Browse files
erwangonashif
authored andcommitted
drivers/flash: flash_stm32_qspi: Set DMA as optional
In order to ease reuse on other series, set DMA as optional and use IT if no DMA channel is specified in the qspi node. Tested on disco_l475_iot1 Signed-off-by: Erwan Gouriou <[email protected]>
1 parent b711028 commit dc11050

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

drivers/flash/Kconfig.stm32_qspi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
# SPDX-License-Identifier: Apache-2.0
66

77
DT_COMPAT_ST_STM32_QSPI_NOR := st,stm32-qspi-nor
8+
DT_STM32_QUADSPI_HAS_DMA := $(dt_node_has_prop,quadspi,dmas)
89

910
config FLASH_STM32_QSPI
1011
bool "STM32 Quad SPI Flash driver"
1112
depends on SOC_FAMILY_STM32
1213
default $(dt_compat_enabled,$(DT_COMPAT_ST_STM32_QSPI_NOR))
1314
select USE_STM32_HAL_QSPI
14-
select USE_STM32_HAL_DMA
15-
select DMA
1615
select FLASH_HAS_DRIVER_ENABLED
1716
select FLASH_JESD216
1817
select FLASH_PAGE_LAYOUT
1918
select FLASH_HAS_PAGE_LAYOUT
19+
select DMA if $(DT_STM32_QUADSPI_HAS_DMA)
20+
select USE_STM32_HAL_DMA if $(DT_STM32_QUADSPI_HAS_DMA)
2021
help
2122
Enable QSPI-NOR support on the STM32 family of processors.

drivers/flash/flash_stm32_qspi.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ LOG_MODULE_REGISTER(flash_stm32_qspi, CONFIG_FLASH_LOG_LEVEL);
3232
#define STM32_QSPI_FIFO_THRESHOLD 8
3333
#define STM32_QSPI_CLOCK_PRESCALER_MAX 255
3434

35+
#define STM32_QSPI_USE_DMA DT_NODE_HAS_PROP(DT_PARENT(DT_DRV_INST(0)), dmas)
36+
3537
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_qspi_nor)
3638

3739
uint32_t table_m_size[] = {
@@ -151,7 +153,11 @@ static int qspi_read_access(const struct device *dev, QSPI_CommandTypeDef *cmd,
151153
return -EIO;
152154
}
153155

156+
#if STM32_QSPI_USE_DMA
154157
hal_ret = HAL_QSPI_Receive_DMA(&dev_data->hqspi, data);
158+
#else
159+
hal_ret = HAL_QSPI_Receive_IT(&dev_data->hqspi, data);
160+
#endif
155161
if (hal_ret != HAL_OK) {
156162
LOG_ERR("%d: Failed to read data", hal_ret);
157163
return -EIO;
@@ -186,7 +192,11 @@ static int qspi_write_access(const struct device *dev, QSPI_CommandTypeDef *cmd,
186192
return -EIO;
187193
}
188194

195+
#if STM32_QSPI_USE_DMA
189196
hal_ret = HAL_QSPI_Transmit_DMA(&dev_data->hqspi, (uint8_t *)data);
197+
#else
198+
hal_ret = HAL_QSPI_Transmit_IT(&dev_data->hqspi, (uint8_t *)data);
199+
#endif
190200
if (hal_ret != HAL_OK) {
191201
LOG_ERR("%d: Failed to read data", hal_ret);
192202
return -EIO;
@@ -454,6 +464,7 @@ static void flash_stm32_qspi_isr(const struct device *dev)
454464
}
455465

456466
/* This function is executed in the interrupt context */
467+
#if STM32_QSPI_USE_DMA
457468
static void qspi_dma_callback(const struct device *dev, void *arg,
458469
uint32_t channel, int status)
459470
{
@@ -466,6 +477,7 @@ static void qspi_dma_callback(const struct device *dev, void *arg,
466477

467478
HAL_DMA_IRQHandler(hdma);
468479
}
480+
#endif
469481

470482
__weak HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
471483
{
@@ -658,8 +670,6 @@ static int flash_stm32_qspi_init(const struct device *dev)
658670
{
659671
const struct flash_stm32_qspi_config *dev_cfg = DEV_CFG(dev);
660672
struct flash_stm32_qspi_data *dev_data = DEV_DATA(dev);
661-
struct dma_config dma_cfg = dev_data->dma.cfg;
662-
static DMA_HandleTypeDef hdma;
663673
uint32_t ahb_clock_freq;
664674
uint32_t prescaler = 0;
665675
int ret;
@@ -673,6 +683,7 @@ static int flash_stm32_qspi_init(const struct device *dev)
673683
return ret;
674684
}
675685

686+
#if STM32_QSPI_USE_DMA
676687
/*
677688
* DMA configuration
678689
* Due to use of QSPI HAL API in current driver,
@@ -681,7 +692,6 @@ static int flash_stm32_qspi_init(const struct device *dev)
681692
* the minimum information to inform the DMA slot will be in used and
682693
* how to route callbacks.
683694
*/
684-
685695
struct dma_config dma_cfg = dev_data->dma.cfg;
686696
static DMA_HandleTypeDef hdma;
687697

@@ -691,6 +701,8 @@ static int flash_stm32_qspi_init(const struct device *dev)
691701
LOG_ERR("%s device not found", dev_data->dma.name);
692702
return -ENODEV;
693703
}
704+
} else {
705+
return -EINVAL;
694706
}
695707

696708
/* Proceed to the minimum Zephyr DMA driver init */
@@ -738,6 +750,8 @@ static int flash_stm32_qspi_init(const struct device *dev)
738750
__HAL_LINKDMA(&dev_data->hqspi, hdma, hdma);
739751
HAL_DMA_Init(&hdma);
740752

753+
#endif /* STM32_QSPI_USE_DMA */
754+
741755
/* Clock configuration */
742756
__ASSERT_NO_MSG(device_get_binding(STM32_CLOCK_CONTROL_NAME));
743757

@@ -762,7 +776,6 @@ static int flash_stm32_qspi_init(const struct device *dev)
762776
}
763777
}
764778
__ASSERT_NO_MSG(prescaler <= STM32_QSPI_CLOCK_PRESCALER_MAX);
765-
766779
/* Initialize QSPI HAL */
767780
dev_data->hqspi.Init.ClockPrescaler = prescaler;
768781
dev_data->hqspi.Init.FlashSize = find_lsb_set(dev_cfg->flash_size);

dts/bindings/qspi/st,stm32-qspi.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ properties:
3030
required: true
3131

3232
dmas:
33-
required: true
3433
description: |
35-
DMA channel specifier. Specifier will have a phandle
36-
reference to the dma controller, the channel number, the slot number,
37-
channel configuration and finally features.
34+
Optional DMA channel specifier. If DMA should be used, specifier should
35+
hold a phandle reference to the dma controller, the channel number,
36+
the slot number, channel configuration and finally features.
3837
3938
For example dmas for TX/RX on QSPI
4039
dmas = <&dma1 5 5 0x0000 0x03>;
4140
4241
dma-names:
43-
required: true
4442
description: |
45-
DMA channel name. Expected value "tx_rx".
43+
DMA channel name. If DMA should be used, expected value is "tx_rx".
4644
4745
For example
4846
dma-names = "tx_rx";

0 commit comments

Comments
 (0)