cancel
Showing results for 
Search instead for 
Did you mean: 

DMA - Normal vs Circular

skon.1
Senior

Hello, what's the difference between the "Normal" and "Circular" modes of the STM32 DMA ?

As far as I understand - "Circular" will write to the first address, auto increment the address to the next one until the last address is reached and then return to the first address.

Is this is correct ?

If yes, how will "Normal" mode behave ?

5 REPLIES 5

> Is this is correct ?

Roughly yes, For details read the DMA chapter in RM.

> If yes, how will "Normal" mode behave ?

After last transfer, it disables itself.

JW

skon.1
Senior

So normal it will issue a single interrupt every time the function is called ?

And circular has to be called only once and it will remain on ?

> So normal it will issue a single interrupt every time the function is called ?

Depending on how you enable it in the control register, there will be one Half-Complete and one Transfer-Complete interrupt.

> And circular has to be called only once and it will remain on ?

I'd say *enabled* rather than *called*, but basically yes, unless you disable it or a Transfer Error occurs.

JW

skon.1
Senior

The Tx and Rx pins of UART 4 in my code are shorted. 

I want to send a incrementing array from the Tx pin and receive it back from the Rx pin.

For this I wrote a for loop that increments every element of the array. The for loop is run from the callback function of HAL_UART_Receive_DMA. 

By I get "uart4_rx_buffer" only once.

What's wrong with my code ?

uint8_t uart4_tx_buffer [ 8 ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 } ;
uint8_t uart4_rx_buffer [ 8 ] = { 0 } ;
 
int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_DMA_Init();
  MX_UART4_Init();
 
  HAL_UART_Receive_DMA ( & huart4 , uart4_rx_buffer , 8 ) ;
  HAL_UART_Transmit_DMA ( & huart4 , uart4_tx_buffer , 8 ) ;
  while ( 1 ) ;
}
 
void HAL_UART_RxCpltCallback ( UART_HandleTypeDef * huart )
{
  for ( int index = 0 ; uart4_tx_buffer < 8 ; index ++ )
  {
    uart4_tx_buffer [ index ] = uart4_tx_buffer [ index ] + 8 ;
    HAL_UART_Transmit_DMA ( & huart4 , uart4_tx_buffer , 8 ) ;
  }
}  

A..1
Associate II

maybe you need to add HAL_UART_Receive_DMA ( & huart4 , uart4_rx_buffer , 8 )

after HAL_UART_Transmit_DMA() inside the for loop