Skip to main content
hiloling
Associate
June 10, 2022
Question

Tell me the workaround of STM32F0x0 HAL, multi channel ADC with DMA.

  • June 10, 2022
  • 5 replies
  • 2173 views

STM32CubeIDE Version: 1.9.0

 Multi channel ADC with DMA cannot use on HAL library.

The HAL does not set DMA CCR prorery. MINC, PSIZE and MSIZE are not set any value, (Their all value 0).

Can I set them at application program ?

This topic has been closed for replies.

5 replies

Amel NASRI
ST Technical Moderator
June 16, 2022

Hi @裕嗣 山田​ ,

This looks like the same issue as the one reported in Nucleo-F072RB Multi-channel ADC Problem.

@Sara BEN HADJ YAHYA​  could you please confirm if this issue is already tracked internally?

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
hiloling
hilolingAuthor
Associate
June 24, 2022

I do not think it is the same.

HPATH.1
Associate III
June 24, 2022

any update on this

hiloling
hilolingAuthor
Associate
June 24, 2022

Uploaded my workaround.

hiloling
hilolingAuthor
Associate
June 24, 2022

Now, My workaround is as follows.

Add DMA initialize routine( for example, HAL_ADCDMA_SetRegs(&hadc)) after  MX_DMA_Init()

Then "STM32CubeIDE basics - 10 ADC DMA TIM HAL lab" video sample can works well.

code sample (1) (2)

By the way, I finally used ADC sequential discontinuous mode for each 1ms ADC start by (3) in sysclock interrupt service routine after HAL_ADC_Start_DMA.

---------------------------------------- 

(1)

/* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_ADC_Init();

 MX_DMA_Init();

 /* USER CODE BEGIN 2 */

 HAL_ADCDMA_SetRegs(&hadc);

---------------------------------------

(2)

---- Somewhere in user program ------------------------------------

HAL_StatusTypeDef HAL_ADCDMA_SetRegs(ADC_HandleTypeDef *hadc)

{

uint32_t tmp = 0U;

/* Check the handle allocation */

if(NULL == hadc)

{

return HAL_ERROR;

}

if(NULL == hadc->DMA_Handle)

{

return HAL_ERROR;

}

tmp = hadc->DMA_Handle->Instance->CCR;

tmp |= ((uint32_t) ( DMA_CCR_MINC | DMA_CCR_PSIZE_0 | DMA_CCR_MSIZE_1)); /* half word peripheral and full word memory( DMA_CCR_MSIZE_1 depends on destination memory size) */

hadc->DMA_Handle->Instance->CCR = tmp;

return HAL_OK;

}

-----------------------------------------

(3) use HAL_ADC_SWTrig, if you want to trigger ADC in discontinuous mode.

HAL_StatusTypeDef HAL_ADC_SWTrig(ADC_HandleTypeDef *hadc)

{

/* Check the handle allocation */

if(NULL == hadc)

{

return HAL_ERROR;

}

  hadc->Instance->CR |= ADC_CR_ADSTART;

  return HAL_OK;

}