cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 DMA request per channel + multple peripherals

r2s
Associate II
Posted on November 23, 2015 at 16:16

Hi,

I would like to use the DMA with diferent peripherals of a stmHere are the resuming points.

target MCU: STM32L0 purpose : Dma + uart1+uart2+uart3 +spi+i2c For instance i succeded configuring the uart2 with the dma with the following configuration:

//UART2
hdma_tx.Instance = DMA1_Channel4;
hdma_tx.Init.Request = DMA_REQUEST_4;
__HAL_LINKDMA(UartObject_tS, hdmatx, hdma_tx);
//(...)
HAL_DMA_Init(&hdma_tx);
hdma_rx.Instance = DMA1_Channel5;
hdma_rx.Init.Request = DMA_REQUEST_4;
__HAL_LINKDMA(UartObject_tS, hdmarx, hdma_rx);
//(...)

if i change the configuration to uart1 it would give something like this:

//UART1 
hdma_tx.Instance = DMA1_Channel2;
hdma_tx.Init.Request = DMA_REQUEST_3;
__HAL_LINKDMA(UartObject_tS, hdmatx, hdma_tx);
//(...)
HAL_DMA_Init(&hdma_tx);
hdma_rx.Instance = DMA1_Channel3;
hdma_rx.Init.Request = DMA_REQUEST_3;
__HAL_LINKDMA(UartObject_tS, hdmarx, hdma_rx);
//(...)

I tested each one separately and the corresponfding IRQ handler is triggered.

Now if i would like to use the UART1, UART2 and LPUART1 (aka UART3). I would apply the same reasoning.

//UART3 aka LPUART1 
hdma_tx.Instance = DMA1_Channel7;
hdma_tx.Init.Request = DMA_REQUEST_5;
__HAL_LINKDMA(UartObject_tS, hdmatx, hdma_tx);
//(...)
hdma_rx.Instance = DMA1_Channel6;
hdma_rx.Init.Request = DMA_REQUEST_5;
__HAL_LINKDMA(UartObject_tS, hdmarx, hdma_rx);
//(...)

At this point i think all is ok as each DMA channel has individual peripheral request signals. But what happens if i need to use the spi2 in the same way knowing that all dma channel request are used? According the datasheet ( ''only one request shall be enabled at a time'' (p240)) and the dma request mapping (p241) , how can I achieve this ? is it possible ? Shall another strategy be followed? Can other peripheral request signals be mapped in the same dma channel ??

If yes, how are they handdled ?

Thanks in advance. #stm32 #uart #spi #dma
3 REPLIES 3
Posted on November 23, 2015 at 17:38

I'm not using the F0 or HAL,

The DMA resources are finite, consider if it's worth using for I2C and USART RX applications, as these would be the least efficient uses.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
r2s
Associate II
Posted on November 23, 2015 at 18:35

Hi Clive,

I'll follow your recommendation. I don't undestand when you mean that you don't use ''HAL''. Does that mean that you adapt your own ST drivers? Why? The ST hal drivers are not reliable ?

Posted on November 23, 2015 at 19:18

I'm not using Cortex-M0 (F0/L0) parts in any of the work I'm doing, I also use the SPL (Standard Peripheral Library) that predates the HAL. I have long standing opinions on the HAL/Cube mess that I'm not going to get into in this thread.

So I gave general direction has to how to use the resources. The STM32 is a general purpose design, so basically you aren't likely to be able to run all peripherals and have them all escape the pins, or have DMA service every peripheral. You have to balance them. DMA is best suited to TX tasks where the length of the transfer is known in advance. For short RX tasks, where there is less, intermittent, or variable length data, DMA will be very difficult to manage efficiently. The HAL layers a pretty thick abstraction on the hardware.

You'll need to look a the DMA matrix and pick a function from each column.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..