cancel
Showing results for 
Search instead for 
Did you mean: 

how do you set the DMABufferAddress and Size when you enable the circular buffer in CubeMX ?

T J
Lead
Posted on December 29, 2016 at 04:33

I have an '091

I enabled the Usart1 TX DMA as circular, but how can I set the Source address and size ?

<<code>>

    hdma_usart1_tx.Instance = DMA1_Channel4;

    hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

    hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;

    hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

    hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

    hdma_usart1_tx.Init.Mode = DMA_CIRCULAR;

    hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;

    if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)

    {

      Error_Handler();

    }

    __HAL_DMA1_REMAP(HAL_DMA1_CH4_USART1_TX);

    __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx);

    /* Peripheral interrupt init */

    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(USART1_IRQn);

<</code>>

#dma-source-memory-settings
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 02, 2017 at 10:51

HI,

I have solved all the issues now thanks, it works out the circular buffer seems only relevant to the RX side.

I initialized the Rx DMA system to a circular buffer of 2 bytes. in the 2 call backs, I move the byte into the Rx-buffer.

there is no need to update the UartRxDMA pointers, since it is circular of 2 bytes. This way, I get an interrupt on each byte received.

Works very well.at 460800. I didn't test any other speed.

View solution in original post

5 REPLIES 5
Khouloud GARSI
Lead II
Posted on December 29, 2016 at 10:02

Hi

Marsh.Nick

,

In the main loop, you should call thisfunction: 'HAL_USART_Transmit_DMA() '; As parameters, this function needs:

  • the USART handler
  • pointer to the data buffer : source
  • the amount of data to be send : the size

You may use those functions if you need also to

receive

datas :

  • HAL_USART_Receive_DMA() in full duplex receive only
  • HAL_USART_TransmitReceive_DMA() in full duplex mode

I advise you to refer to the examples providedby ST.

If this solves your issue, please click on correct

:)

.

Khouloud.

T J
Lead
Posted on December 30, 2016 at 01:43

Hi, thanks for the look in;

however, I checked these two examples;

In both examples;

 Uart two boards_COMDMA

 EvalUartHyperterminalDMA

In;

stm32f0xx_hal_msp.C

Under Line 70:

void HAL_UART_MspInit(UART_HandleTypeDef *huart)

Line 113

hdma_tx.Init.Mode                = DMA_NORMAL;

I modified the Hyper terminal example it works.

I made a new CubeMX file, but there are no parameters for using a circular buffer.

I imagine there is a base address, a buffer length and a pointer_in and a pointer_out.

but I cannot find any implementation or detailed description of it.

Khouloud GARSI
Lead II
Posted on January 02, 2017 at 10:31

Hi

Marsh.Nick

,

After configuring the DMA to work on a circular mode, have you called the '

HAL_USART_Transmit_DMA()' in the main?

Since you're using the USART to transfer data, then you have a buffer where the data you want to transfer are loaded;

Those data will be transmitted to the USARTx_TDR register whenever the TXE bit is set.

Have a look at section 'Continuous communication using DMA' in the reference manual.This will give you more clarification.

Khouloud.

Khouloud GARSI
Lead II
Posted on January 02, 2017 at 11:14

Hi

Marsh.Nick

,

Glad to hear that your problem is solved.

Happy new year

Khouloud.

Posted on January 02, 2017 at 10:51

HI,

I have solved all the issues now thanks, it works out the circular buffer seems only relevant to the RX side.

I initialized the Rx DMA system to a circular buffer of 2 bytes. in the 2 call backs, I move the byte into the Rx-buffer.

there is no need to update the UartRxDMA pointers, since it is circular of 2 bytes. This way, I get an interrupt on each byte received.

Works very well.at 460800. I didn't test any other speed.