Skip to main content
Hailing SKY
Associate III
November 21, 2017
Question

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

  • November 21, 2017
  • 1 reply
  • 2611 views
Posted on November 21, 2017 at 23:24

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.

HAL_ADC_Start_DMA(&hadc1,(uint32_t*)adcValue,2400);

//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__);

}

__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);

}

Thanks in advance.

Hailing

#buffer-size #stm32l4-hal #dma-stm32
This topic has been closed for replies.

1 reply

waclawek.jan
Super User
November 21, 2017
Posted on November 22, 2017 at 00:40

What is BUFSIZ and where is it defined?

JW

Hailing SKY
Associate III
November 22, 2017
Posted on November 22, 2017 at 01:05

Hi JW,

By saying 'Buffer Size', I mean the 'DMA channel x number of data register (DMA_CNDTRx) (x = 1..7,

where x = channel number)'. This is mentioned in the reference manual for STM32L4. I guess this register controls the number of data transmitted using ADC+DMA.

I also have a macro called 'BUF_SIZE' defined in the beginning of main.c. It sets the number of data points from each adc channel.

Thanks for your reply. Regards,

Hailing 

waclawek.jan
Super User
November 22, 2017
Posted on November 22, 2017 at 01:26

By BUFSIZ I mean BUFSIZ, as in HAL_UART_Transmit(&huart1,(uint8_t*)datastore1,BUFSIZ,2000) etc.

JW