STM32_DMA_GETCHANNEL doesn't work for DMA2?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
szego
Posts: 20
Joined: Wed Sep 02, 2015 7:51 pm

STM32_DMA_GETCHANNEL doesn't work for DMA2?

Post by szego »

The macro is defined as:

Code: Select all

/**
 * @brief   Returns the request line associated to the specified stream.
 * @note    In some STM32 manuals the request line is named confusingly
 *          channel.
 *
 * @param[in] id        the unique numeric stream identifier
 * @param[in] c         a stream/request association word, one request per
 *                      nibble
 * @return              Returns the request associated to the stream.
 */
#define STM32_DMA_GETCHANNEL(id, c) (((c) >> (((id) & 7U) * 4U)) & 15U)


This seems reasonable for DMA1 channels, where the least-significant nibble is DMA1,Channel1. The next is DMA1,Channel2, etc.

However for DMA2 it looks like in the picture (attached). So for example this set of definitions for SPI3 won't work:

Code: Select all

#define STM32_SPI3_RX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(2, 1))
#define STM32_SPI3_RX_DMA_CHN               0x00000003
#define STM32_SPI3_TX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(2, 2))
#define STM32_SPI3_TX_DMA_CHN               0x00000030


The "slot" for DMA2,Channel1 is NOT the least-significant nibble. So the code to extract the value:

Code: Select all

#define SPI3_RX_DMA_CHANNEL                                                 \
  STM32_DMA_GETCHANNEL(STM32_SPI_SPI3_RX_DMA_STREAM,                        \
                       STM32_SPI3_RX_DMA_CHN)

...actually returns a zero, and not 3.

Or am I missing something?

Paul.
Attachments
DMA2
DMA2
OmniGraffleScreenSnapz032.jpg (15.48 KiB) Viewed 2032 times
szego
Posts: 20
Joined: Wed Sep 02, 2015 7:51 pm

Re: STM32_DMA_GETCHANNEL doesn't work for DMA2?

Post by szego »

This seemed to work for me, but since I don't know exactly what the intent was I'm not going to claim it's a fix:

Code: Select all

#define STM32_DMA_GETCHANNEL(id, c) (((c) >> (((id) % 7U) * 4U)) & 15U)


Paul.
Post Reply