Skip to content

Commit d43200e

Browse files
erwangonashif
authored andcommitted
drivers/dma: stm32: Preparation for QSPI DMA mode support
In preparation for QSPI DMA mode: -Add a possibility to override driver by the HAL DMA. In that case stream is set as busy and no configuration nor treatment is done. In case of interrupt, flags clearing is let to HAL. -Treat Half Transfer interrupt prior to Transfer Complete for the cases were both IRQ are both raised at the time IRQ handler is called Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 93ced15 commit d43200e

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

drivers/dma/dma_stm32.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <init.h>
1717
#include <drivers/clock_control.h>
18+
#include <drivers/dma/dma_stm32.h>
1819

1920
#include <logging/log.h>
2021
LOG_MODULE_REGISTER(dma_stm32, CONFIG_DMA_LOG_LEVEL);
@@ -101,14 +102,21 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
101102
}
102103

103104
/* the dma stream id is in range from STREAM_OFFSET..<dma-requests> */
104-
if (dma_stm32_is_tc_active(dma, id)) {
105-
dma_stm32_clear_tc(dma, id);
105+
if (dma_stm32_is_ht_active(dma, id)) {
106+
/* Let HAL DMA handle flags on its own */
107+
if (!stream->hal_override) {
108+
dma_stm32_clear_ht(dma, id);
109+
}
110+
stream->dma_callback(dev, stream->user_data, callback_arg, 0);
111+
} else if (dma_stm32_is_tc_active(dma, id)) {
106112
#ifdef CONFIG_DMAMUX_STM32
107113
stream->busy = false;
108114
#endif
115+
/* Let HAL DMA handle flags on its own */
116+
if (!stream->hal_override) {
117+
dma_stm32_clear_tc(dma, id);
118+
}
109119
stream->dma_callback(dev, stream->user_data, callback_arg, 0);
110-
} else if (dma_stm32_is_ht_active(dma, id)) {
111-
dma_stm32_clear_ht(dma, id);
112120
} else if (stm32_dma_is_unexpected_irq_happened(dma, id)) {
113121
LOG_ERR("Unexpected irq happened.");
114122
stream->dma_callback(dev, stream->user_data,
@@ -255,6 +263,19 @@ DMA_STM32_EXPORT_API int dma_stm32_configure(const struct device *dev,
255263
/* give channel from index 0 */
256264
id = id - STREAM_OFFSET;
257265

266+
/* Check potential DMA override */
267+
if (config->linked_channel == STM32_DMA_HAL_OVERRIDE) {
268+
/* DMA channel is overridden by HAL DMA
269+
* Retain that the channel is busy and proceed to the minimal
270+
* configuration to properly route the IRQ
271+
*/
272+
stream->busy = true;
273+
stream->hal_override = true;
274+
stream->dma_callback = config->dma_callback;
275+
stream->user_data = config->user_data;
276+
return 0;
277+
}
278+
258279
if (id >= dev_config->max_streams) {
259280
LOG_ERR("cannot configure the dma stream %d.", id);
260281
return -EINVAL;

drivers/dma/dma_stm32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct dma_stm32_stream {
2121
int mux_channel; /* stores the dmamux channel */
2222
#endif /* CONFIG_DMAMUX_STM32 */
2323
bool source_periph;
24+
bool hal_override;
2425
volatile bool busy;
2526
uint32_t src_size;
2627
uint32_t dst_size;

include/drivers/dma/dma_stm32.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DRIVERS_DMA_STM32_H_
8+
#define ZEPHYR_INCLUDE_DRIVERS_DMA_STM32_H_
9+
10+
/* @brief linked_channel value to inform zephyr dma driver that
11+
* DMA channel will be handled by HAL
12+
*/
13+
#define STM32_DMA_HAL_OVERRIDE 0x7F
14+
15+
#endif /* ZEPHYR_INCLUDE_DRIVERS_DMA_STM32_H_ */

0 commit comments

Comments
 (0)