cancel
Showing results for 
Search instead for 
Did you mean: 

ADC scan continuous mode with DMA in STM32H7 - all values are 0.

Mdi c
Associate III

Dear all,

I am trying to read 3 ADCs channels using scan continuous mode and DMA with a STM32H7 (ADC3). Below the CubeMx settings + DMA.

0690X00000D9TejQAF.png0690X00000D9TfXQAV.png

In the main, before the While(1) loop I start the ADC with:

HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc_data, 3) ;

Where ADC_Values is uint32_t adc_data[3];

When I run the debugger, adc_data is always 0x0000.

Any hint?

Thanks

8 REPLIES 8

Are you handling the buffer coherency issue for ADC DMA read buffer correctly?

https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices

Mdi c
Associate III

Hello @Yoichi Shinoda​ , thank you for your answer. I came accross that article and I think that's the issue I have. I tried to follow it but I think my knowledge about STM32 MCUs is too limited to really understand it ..

Imen GH
ST Employee

Hello,

You should change the memory address, as shown in Figure (when using IAR)

 Please find attached the RM0433 Rev 6  (page 101, 128) link for more clarification

Regards

0690X00000DXQe5QAH.png

Hi all,

User have to do this update

define symbol __ICFEDIT_region_RAM_start__ = 0x24000000;

define symbol __ICFEDIT_region_RAM_end__ = 0x2407FFFF;

manually (in the stm32h743xx_flash.icf ) since linker file is not managed by STM32CubeMX (copied from the FW package).

Best regards,

Nesrine

Dear @Nesrine.JLASSI​ , is this equivalent to setting the IRAM2 region in the target option in Keil ?

0693W000000VGhrQAG.jpg

Mdi c
Associate III

Hello @Nesrine.JLASSI​  and @Imen GH​ , modifying the IRAM2 in Keil did the trick. Now I can see the data being acquired by the MCU. However, I noticed that despite the ADC resolution is set to 16bits, I can only read 8bits since the the 8 LSBs are always 0, as shown in the debugger view below:

0693W000000VIdXQAW.jpg

where :

uint16_t adc_data[7];

HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_data, 7) ;

ADC initialization code:

static void MX_ADC1_Init(void)

{

 /* USER CODE BEGIN ADC1_Init 0 */

 /* USER CODE END ADC1_Init 0 */

 ADC_MultiModeTypeDef multimode = {0};

 ADC_ChannelConfTypeDef sConfig = {0};

 /* USER CODE BEGIN ADC1_Init 1 */

 /* USER CODE END ADC1_Init 1 */

 /** Common config 

 */

 hadc1.Instance = ADC1;

 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;

 hadc1.Init.Resolution = ADC_RESOLUTION_16B;

 hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;

 hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;

 hadc1.Init.LowPowerAutoWait = DISABLE;

 hadc1.Init.ContinuousConvMode = ENABLE;

 hadc1.Init.NbrOfConversion = 7;

 hadc1.Init.DiscontinuousConvMode = DISABLE;

 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;

 hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;

 hadc1.Init.OversamplingMode = ENABLE;

 hadc1.Init.Oversampling.Ratio = 8;

 hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_3;

 hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;

 hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;

 if (HAL_ADC_Init(&hadc1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the ADC multi-mode 

 */

 multimode.Mode = ADC_MODE_INDEPENDENT;

 if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_3;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_4;

 sConfig.Rank = ADC_REGULAR_RANK_2;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_5;

 sConfig.Rank = ADC_REGULAR_RANK_3;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_9;

 sConfig.Rank = ADC_REGULAR_RANK_4;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_14;

 sConfig.Rank = ADC_REGULAR_RANK_5;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_15;

 sConfig.Rank = ADC_REGULAR_RANK_6;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_19;

 sConfig.Rank = ADC_REGULAR_RANK_7;

 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN ADC1_Init 2 */

 /* USER CODE END ADC1_Init 2 */

}

Hi @Mdi c​ , have you finally solved this issue? In my case, the DMA can only transfer the first byte correctly and leaves the remaining terms to 0.

Thanks

did you forget to change the DMA from byte to word?