cancel
Showing results for 
Search instead for 
Did you mean: 

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

kryczka
Associate II
Posted on October 12, 2014 at 18:31

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 driversto implement the same function. In HAL drivers there is an option to chose the circular mode inDMA_mode ofDMA_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:


serialPortDMAInitStructure.DMA_PeripheralBaseAddr = USART_DR_ADDRESS;

serialPortDMAInitStructure.DMA_MemoryBaseAddr = (uint32_t)serialPortRxBuffer;

serialPortDMAInitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

serialPortDMAInitStructure.DMA_BufferSize = (uint32_t)USART_MAX_RX_BUFFER_LENGTH;

serialPortDMAInitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

serialPortDMAInitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

serialPortDMAInitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

serialPortDMAInitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

serialPortDMAInitStructure.DMA_Mode = DMA_Mode_Circular; 

serialPortDMAInitStructure.DMA_Priority = DMA_Priority_VeryHigh;

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 #uart #hal #stm32
1 REPLY 1
childresss
Associate II
Posted on January 28, 2015 at 05:38

''bumping'' this old thread, hoping for an erudite answer as I too wonder - trying to use DMA RX to offest the lack of a FIFO in the UART hardware.