cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX 6.3: ADC Injected Rank Code Generation not working?

Framet
Associate III

Edit 2: CubeMX 6.2.1 is working aswell. Will use this version for now.

Edit 1: CubeMX 6.0.0 and 6.2.0 are working

After Code Generation, the 3 injected Channels (0,1,2) would be all initialized with ADC_INJECTED_RANK_1 despite other setting in CubeMX.

With older Version this was working. Did something change with the setup which I don't understand or is this a possible bug?

0693W00000FBJukQAH.png 

0693W00000FBK7YQAX.png

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Framet​ ,

First let me apologize for the inconvenience that this regression may cause . You're right, CubeMX doesn't correctly generate MX_ADC1_Init() function: ADC_INJECTED_RANK_x is generated only for Rank 1.

This is reported internally to be reviewed. I'll keep you posted with the updates.

Internal ticket number: 115118  (This is an internal tracking number and is not accessible or usable by customers).

Even though this reply doesn’t directly solve the issue, I’m marking it as Best, since it will help clarify the current situation for other customers with the same question. I will post an update here once the issue has been fixed.

Khouloud.

View solution in original post

6 REPLIES 6
Framet
Associate III

I've tested the same with CubeMX 6.0.0 and there it is working again.

/**
  * @brief ADC1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC1_Init(void)
{
 
  /* USER CODE BEGIN ADC1_Init 0 */
 
  /* USER CODE END ADC1_Init 0 */
 
  ADC_ChannelConfTypeDef sConfig = {0};
  ADC_InjectionConfTypeDef sConfigInjected = {0};
 
  /* USER CODE BEGIN ADC1_Init 1 */
 
  /* USER CODE END ADC1_Init 1 */
  /** Common config
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_3;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_0;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
  sConfigInjected.InjectedNbrOfConversion = 3;
  sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfigInjected.ExternalTrigInjecConv = ADC_INJECTED_SOFTWARE_START;
  sConfigInjected.AutoInjectedConv = DISABLE;
  sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
  sConfigInjected.InjectedOffset = 0;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_1;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Injected Channel
  */
  sConfigInjected.InjectedChannel = ADC_CHANNEL_2;
  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
  if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */
 
  /* USER CODE END ADC1_Init 2 */
 
}

TDK
Guru

CubeMX just generates code, and the code you posted definitely shows different ADC_INJECTED_RANK_x for each. Could be a problem in the HAL library, but doesn't appear to be.

If you feel a post has answered your question, please click "Accept as Solution".
Framet
Associate III

I'm confused. How does the code show different ADC_INJECTED_RANK's? It does show for version below CubeMX 6.3 but in 6.3 for me at least, it does not show.

In below picture at 1) and 2) there should be

sConfigInjected.InjectedRank = ADC_INJECTED_RANK_x;

Or do I miss something here?

0693W00000FBNLnQAP.png

No, that's my mistake for reading too quickly. Your first reply has the correct code.
If you feel a post has answered your question, please click "Accept as Solution".
Amel NASRI
ST Employee

Hi @Framet​ ,

Thanks for bringing this issue to our attention.

I added relevant topic (STM32CubeMX) to this question and mention our STM32CubeMX expert @Khouloud OTHMAN​  here so that she can take care to review this.

-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.

Hello @Framet​ ,

First let me apologize for the inconvenience that this regression may cause . You're right, CubeMX doesn't correctly generate MX_ADC1_Init() function: ADC_INJECTED_RANK_x is generated only for Rank 1.

This is reported internally to be reviewed. I'll keep you posted with the updates.

Internal ticket number: 115118  (This is an internal tracking number and is not accessible or usable by customers).

Even though this reply doesn’t directly solve the issue, I’m marking it as Best, since it will help clarify the current situation for other customers with the same question. I will post an update here once the issue has been fixed.

Khouloud.