cancel
Showing results for 
Search instead for 
Did you mean: 

ADC DMA using HRTIM as trigger don't have any values

victagayun
Senior III

I am using NUCLEO-G474RE as my hardware.

STM32CubeIDE V1.3.1 and STM32G4 Fw V1.2.0.

I am using ADC2 with 4 channels triggered by HRTIM CH B Compare 4 Injected.

So these 4 channels are triggered interleaved, meaning that every HRTIM-CH-B Compare 4 only one ADC channel is triggered according to rank.

So for 1st occurrence of Comparewill trigger rank1 then the second compare it will be rank2 so on and so forth until it gets back to rank1 again.

I can see that the S/H is working as shown in the waveform below.

The circuit is similar to HRTIM cookbook section 7.1 Debugging ADC operation.

0693W000001pKu0QAE.jpg

Below is the HTRIM output

0693W000001pKuKQAU.jpg

My setup for ADC2:

static void MX_ADC2_Init(void)
{
 
  /* USER CODE BEGIN ADC2_Init 0 */
 
  /* USER CODE END ADC2_Init 0 */
 
  ADC_InjectionConfTypeDef sConfigInjected = {0};
 
  /* USER CODE BEGIN ADC2_Init 1 */
 
  /* USER CODE END ADC2_Init 1 */
  /** Common config 
  */
  hadc2.Instance = ADC2;
  hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
  hadc2.Init.Resolution = ADC_RESOLUTION_12B;
  hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc2.Init.GainCompensation = 0;
  hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc2.Init.LowPowerAutoWait = DISABLE;
  hadc2.Init.ContinuousConvMode = DISABLE;
  hadc2.Init.NbrOfConversion = 1;
  hadc2.Init.DiscontinuousConvMode = DISABLE;
  hadc2.Init.DMAContinuousRequests = ENABLE;
  hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
  hadc2.Init.OversamplingMode = DISABLE;
  if (HAL_ADC_Init(&hadc2) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel 
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_5;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
  sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_6CYCLES_5;
  sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;
  sConfigInjected.InjectedOffsetNumber = ADC_OFFSET_NONE;
  sConfigInjected.InjectedOffset = 0;
  sConfigInjected.InjectedNbrOfConversion = 4;
  sConfigInjected.InjectedDiscontinuousConvMode = ENABLE;
  sConfigInjected.AutoInjectedConv = DISABLE;
  sConfigInjected.QueueInjectedContext = DISABLE;
  sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJEC_HRTIM_TRG10;
  sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISING;
  sConfigInjected.InjecOversamplingMode = DISABLE;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel 
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_11;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel 
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_3;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel 
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_4;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC2_Init 2 */
 
  /* Run the ADC calibration in single-ended mode */
  HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);
 
  /* Start ADC1 Injected Conversions */
  HAL_ADCEx_InjectedStart(&hadc2);
 
  /* USER CODE END ADC2_Init 2 */
 
}

my HRTIM trigger setup

pADCTriggerCfg.UpdateSource = HRTIM_ADCTRIGGERUPDATE_TIMER_B;
  pADCTriggerCfg.Trigger = HRTIM_ADCTRIGGEREVENT6810_TIMERB_CMP4;
  if (HAL_HRTIM_ADCTriggerConfig(&hhrtim1, HRTIM_ADCTRIGGER_10, &pADCTriggerCfg) != HAL_OK)
  {
    Error_Handler();
  }

in the Main

/* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_LPUART1_UART_Init();
  MX_HRTIM1_Init();
  MX_ADC2_Init();
  MX_ADC1_Init();
  MX_ADC3_Init();
  MX_ADC4_Init();
 
  if (HAL_ADC_Start_DMA(&hadc2, adc_four_ch, 4) != HAL_OK)
  {
	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, SET);
  }
 
  HRTIM1_Start_Output();

LED on the Nucleo seems not to light.

Here are the values I can see from the debug:

0693W000001pKwkQAE.png

Anything I am missing?

1 ACCEPTED SOLUTION
5 REPLIES 5

> LED on the Nucleo seems not to light.

OK so doesn't that mean that there's something wrong with HAL_ADC_Start_DMA()? Did you single-step it or debug it in any other way?

As soon as you start using Cube/HAL functions, they form part of your program, so debug them exactly as you debug your own program.

JW

victagayun
Senior III

It went all the way inside by pressing F5. It went even to

HAL_DMA_Start_IT

what should I be looking for? noob here.

Read the DMAMUX and DMA chapters in RM. Does the software set the DMAMUX/DMA registers as you'd expect?

JW

victagayun
Senior III

So far this what I get from DMA1 and DMAMUX, reading RM now...

after

  if (HAL_ADC_Start_DMA(&hadc2, adc_four_ch, 4) != HAL_OK)
  {
	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, SET);
  }

0693W000001pLASQA2.png 0693W000001pLAXQA2.png

BTW, I forgot to remove one old code:

VoutMeasured = HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_1);

seems to work though, I can get values...

even I comment the above code, still no values for my array..