cancel
Showing results for 
Search instead for 
Did you mean: 

bug in generated code in stm32h5xx_hal_msp.c for ADC3

Gunnar Bohlen
Associate III

Hello,

 

maybe someone can check this,it seems to be incorrectly generated code.

In my application for STM32H5xx I want to use ADC3.

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  if(hadc->Instance==ADC3)
  {
...
.../* Peripheral clock enable */
    __HAL_RCC_ADC_CLK_ENABLE();


This macro does not enable ADC3.

#define __HAL_RCC_ADC_CLK_ENABLE()             do { \
                                                    __IO uint32_t tmpreg; \
                                                    SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_ADCEN); \
                                                    /* Delay after an RCC peripheral clock enabling */ \
                                                    tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2ENR_ADCEN); \
                                                    UNUSED(tmpreg); \
                                                  } while(0)

I think something like this is required:
#define __HAL_RCC_ADC3_CLK_ENABLE()             do { \
                                                    __IO uint32_t tmpreg; \
                                                    SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_ADC3EN); \
                                                    /* Delay after an RCC peripheral clock enabling */ \
                                                    tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2ENR_ADC3EN); \
                                                    UNUSED(tmpreg); \
                                                  } while(0)

 

3 REPLIES 3
mƎALLEm
ST Employee

Hello @Gunnar Bohlen and thank you for your contribution.

I will escalate that for analysis and eventual fix.

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.
mƎALLEm
ST Employee

Hello,

Getting back to you.

I've just generated the code and I got the following generated code:

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  if(hadc->Instance==ADC3)
  {
    /* USER CODE BEGIN ADC3_MspInit 0 */

    /* USER CODE END ADC3_MspInit 0 */

  /** Initializes the peripherals clock
  */
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
    PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
      Error_Handler();
    }

    /* Peripheral clock enable */
    __HAL_RCC_ADC3_CLK_ENABLE();

it calls __HAL_RCC_ADC3_CLK_ENABLE() and not __HAL_RCC_ADC_CLK_ENABLE()

The definition of that macro:

#define __HAL_RCC_ADC3_CLK_ENABLE()            do { \
                                                    __IO uint32_t tmpreg; \
                                                    SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_ADC3EN); \
                                                    /* Delay after an RCC peripheral clock enabling */ \
                                                    tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2ENR_ADC3EN); \
                                                    UNUSED(tmpreg); \
                                                  } while(0)

Could you please tell which CubeMx are you using and which H5 CubeHAL are you using? The latest version is H5 V.1.6.0

And if possible to share your ioc file. 

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.
mƎALLEm
ST Employee

Hello @Gunnar Bohlen ,

Could you please state on this please?

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.