AnsweredAssumed Answered

Use of DMA circular buffers in HAL drivers (UART RX, STM32F3)

Question asked by krprzemo on Oct 12, 2014
Latest reply on Jan 28, 2015 by childress.steve
Hello everyone, 

I am trying to port my software to HAL drivers and came across a problem with use of circular buffer. I use it on the RX of UART to continuously receive data. It works as it should on the Standard Peripheral Drivers, but I can't find my way around the new drivers to implement the same function. 

In HAL drivers there is an option to chose the circular mode in DMA_mode of DMA_HandleTypeDef. However I have no idea how to pass the address and size of a memory space where I want DMA to write my received data. I am also not sure how to initiate the transmission and how to get the current index inside the memory space?

In old version I used the following code to initialize the DMA: 
01.serialPortDMAInitStructure.DMA_PeripheralBaseAddr = USART_DR_ADDRESS;
02.serialPortDMAInitStructure.DMA_MemoryBaseAddr = (uint32_t)serialPortRxBuffer;
03.serialPortDMAInitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
04.serialPortDMAInitStructure.DMA_BufferSize = (uint32_t)USART_MAX_RX_BUFFER_LENGTH;
05.serialPortDMAInitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
06.serialPortDMAInitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
07.serialPortDMAInitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
08.serialPortDMAInitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
09.serialPortDMAInitStructure.DMA_Mode = DMA_Mode_Circular;   
10.serialPortDMAInitStructure.DMA_Priority = DMA_Priority_VeryHigh;
11.DMA_Init(USART_RX_DMA_CHANNEL, &serialPortDMAInitStructure);

Also to get the current memory index I was using:
1.DMA_GetCurrDataCounter(USART_RX_DMA_CHANNEL)

Of course I already checked out the examples, but unfortunately ST seems to miss out this use scenario. 

I will appreciate any help.

Kind regards,
 krprzemo 

Outcomes