2026-02-24 12:48 AM - last edited on 2026-02-24 1:44 AM by mƎALLEm
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)
2026-02-24 12:51 AM
Hello @Gunnar Bohlen and thank you for your contribution.
I will escalate that for analysis and eventual fix.
2026-02-24 5:29 AM - edited 2026-02-24 5:30 AM
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.
2026-04-22 4:21 AM
Hello @Gunnar Bohlen ,
Could you please state on this please?