New coding rules

Removal of underscore prefixes for macros

To comply with C coding standards, HAL2 removes all single and double underscore prefixes from macros. This change improves adherence to the standard and prevents conflicts with reserved identifiers in the C language.

Example of prefixes for macros in HAL1 and HAL2

HAL1

HAL2

#define __HAL_ADC_CALC_DATA_TO_VOLTAGE(..) ..
#define HAL_ADC_CALC_DATA_TO_VOLTAGE(..) ..

Replaced TypeDef suffix with _t in type names

In HAL1, C types such as structures and enumerations use the suffix TypeDef. In HAL2, this suffix is replaced with _t for all typedef names.

Example of type naming in HAL1 and HAL2

HAL1

HAL2

typedef struct
{
} ADC_ChannelConfTypeDef;
typedef struct
{
} hal_adc_channel_config_t;

Removal of underscore prefixes in header file guards

Underscore prefixes were removed from header file guards and replaced with #ifndef HAL_PPP_HDR_H, using the _HDR_H suffix for clarity and compliance.

Example of header file guards in HAL1 and HAL2

HAL1

HAL2

#ifndef __STM32U5xx_HAL_DEF
#define __STM32U5xx_HAL_DEF
#ifndef STM32U5XX_HAL_DEF_H
#define STM32U5XX_HAL_DEF_H

Replaced multi-line macros with inline functions

In HAL1, some multi-line macros use a do { ... } while(0) construct for safe usage when calling or nesting a macro. HAL2 replaces these macros with static inline functions to improve debugging, as inline functions are easier to trace and maintain than complex macros.

Example of a multi-line macro replaced with an inline function

HAL1

HAL2

#define __HAL_RCC_TIM1_CLK_ENABLE()
do { \
     __IO uint32_t tmpreg; \
     SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN); \
     /* Delay after an RCC peripheral clock enabling */ \
     tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN); \
     UNUSED(tmpreg); \
   } while(0)
__STATIC_INLINE hal_rcc_clk_status_t HAL_RCC_TIM1_IsEnabledClock(void)
{
  return (hal_rcc_clk_status_t)LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_TIM1);
}

Replaced nonmodifiable pointers with const keywords

To comply with MISRA-C 2012 coding rules, HAL2 applies the const keyword to any pointer function parameter when the function does not modify the data being pointed to.

Example of a nonmodifiable pointer replaced with const keyword

HAL1

HAL2

HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c,
                                             uint16_t DevAddress,
                                             uint8_t *pData,
                                             uint16_t Size);
hal_status_t HAL_I2C_MASTER_Transmit_DMA(hal_i2c_handle_t *hi2c,
                                         uint32_t device_addr,
                                         const void *p_data,
                                         uint32_t size_byte);