Skip to content

Commit

Permalink
drivers: dma: stm32 driver is using the STM32_DMA_STREAM_OFFSET
Browse files Browse the repository at this point in the history
Includes the definition of the STM32_DMA_STREAM_OFFSET
depending on the peripheral to adjust the first DMA channel
in the list of streams.

Signed-off-by: Francois Ramu <[email protected]>
  • Loading branch information
FRASTM authored and carlescufi committed May 2, 2022
1 parent 23ea7ef commit 005968a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
19 changes: 9 additions & 10 deletions drivers/dma/dma_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
#ifdef CONFIG_DMAMUX_STM32
callback_arg = stream->mux_channel;
#else
callback_arg = id + STREAM_OFFSET;
callback_arg = id + STM32_DMA_STREAM_OFFSET;
#endif /* CONFIG_DMAMUX_STM32 */

if (!IS_ENABLED(CONFIG_DMAMUX_STM32)) {
stream->busy = false;
}

/* the dma stream id is in range from STREAM_OFFSET..<dma-requests> */
/* the dma stream id is in range from STM32_DMA_STREAM_OFFSET..<dma-requests> */
if (stm32_dma_is_ht_irq_active(dma, id)) {
/* Let HAL DMA handle flags on its own */
if (!stream->hal_override) {
Expand Down Expand Up @@ -263,15 +262,15 @@ DMA_STM32_EXPORT_API int dma_stm32_configure(const struct device *dev,
{
const struct dma_stm32_config *dev_config = dev->config;
struct dma_stm32_stream *stream =
&dev_config->streams[id - STREAM_OFFSET];
&dev_config->streams[id - STM32_DMA_STREAM_OFFSET];
DMA_TypeDef *dma = (DMA_TypeDef *)dev_config->base;
LL_DMA_InitTypeDef DMA_InitStruct;
int ret;

LL_DMA_StructInit(&DMA_InitStruct);

/* give channel from index 0 */
id = id - STREAM_OFFSET;
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= dev_config->max_streams) {
LOG_ERR("cannot configure the dma stream %d.", id);
Expand Down Expand Up @@ -503,7 +502,7 @@ DMA_STM32_EXPORT_API int dma_stm32_reload(const struct device *dev, uint32_t id,
struct dma_stm32_stream *stream;

/* give channel from index 0 */
id = id - STREAM_OFFSET;
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= config->max_streams) {
return -EINVAL;
Expand Down Expand Up @@ -548,7 +547,7 @@ DMA_STM32_EXPORT_API int dma_stm32_start(const struct device *dev, uint32_t id)
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);

/* give channel from index 0 */
id = id - STREAM_OFFSET;
id = id - STM32_DMA_STREAM_OFFSET;

/* Only M2P or M2M mode can be started manually. */
if (id >= config->max_streams) {
Expand All @@ -565,11 +564,11 @@ DMA_STM32_EXPORT_API int dma_stm32_start(const struct device *dev, uint32_t id)
DMA_STM32_EXPORT_API int dma_stm32_stop(const struct device *dev, uint32_t id)
{
const struct dma_stm32_config *config = dev->config;
struct dma_stm32_stream *stream = &config->streams[id - STREAM_OFFSET];
struct dma_stm32_stream *stream = &config->streams[id - STM32_DMA_STREAM_OFFSET];
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);

/* give channel from index 0 */
id = id - STREAM_OFFSET;
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= config->max_streams) {
return -EINVAL;
Expand Down Expand Up @@ -627,7 +626,7 @@ DMA_STM32_EXPORT_API int dma_stm32_get_status(const struct device *dev,
struct dma_stm32_stream *stream;

/* give channel from index 0 */
id = id - STREAM_OFFSET;
id = id - STM32_DMA_STREAM_OFFSET;
if (id >= config->max_streams) {
return -EINVAL;
}
Expand Down
12 changes: 0 additions & 12 deletions drivers/dma/dma_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ struct dma_stm32_config {
struct dma_stm32_stream *streams;
};

#if !defined(CONFIG_DMA_STM32_V1)
/* from DTS the dma stream id is in range 1..<dma-requests> */
/* so decrease to set range from 0 from now on */
#define STREAM_OFFSET 1
#elif defined(CONFIG_DMA_STM32_V1) && defined(CONFIG_DMAMUX_STM32)
/* typically on the stm32H7 serie, DMA V1 with mux */
#define STREAM_OFFSET 1
#else
/* from DTS the dma stream id is in range 0..<dma-requests>-1 */
#define STREAM_OFFSET 0
#endif /* ! CONFIG_DMA_STM32_V1 */

uint32_t dma_stm32_id_to_stream(uint32_t id);
#if !defined(CONFIG_DMAMUX_STM32)
uint32_t dma_stm32_slot_to_channel(uint32_t id);
Expand Down

0 comments on commit 005968a

Please sign in to comment.