cancel
Showing results for 
Search instead for 
Did you mean: 

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

hiloling
Associate II

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 ?

5 REPLIES 5
Amel NASRI
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

HPATH.1
Associate II

any update on this

hiloling
Associate II

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;

}

Uploaded my workaround.

I do not think it is the same.