AnsweredAssumed Answered

How to set the max buffer size for DMA in STM32L4?

Question asked by Hailing SKY on Nov 21, 2017
Latest reply on Nov 22, 2017 by Hailing SKY

I am trying to collect data using ADC + DMA continuous mode. I aim to get 2400 data points using DMA. The code is based on the one generated using STM32CubeMx. The data I got from my PC using UART were just 2048 points. I guess I need to change the max buffer size of the DMA. I try to set the CNDTR register in the initialization, but it was not successful. I guess the location could be wrong, or there are other codes required.


I am new to the STM32 family. I hope someone can help me address it. I also attached all my codes.


// partial codes.

//This is the function in main.c.



//DMA initialization (Partial):

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)


/* ADC1 DMA Init */
/* ADC1 Init */
hdma_adc1.Instance = DMA1_Channel1;
hdma_adc1.Init.Request = DMA_REQUEST_0;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_adc1.Init.Mode = DMA_CIRCULAR;
hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
hdma_adc1.Instance->CNDTR = DataLength;     // I was trying to change the buffer size here, but it did work.
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
_Error_Handler(__FILE__, __LINE__);




Thanks in advance.