how to handle cube mx overwriting the hal_conf that has to be modified by devs. this looks like a long standing problem (half a decade) an i see no stable solution
- the stm32lyxxxhal.h includes stm32yxxx_hal_conf.h.
- stm32yxxx_hal_conf.h contains always regenerated code as follows
/* ################## Register callback feature configuration ############### */
/**
* @brief Set below the peripheral configuration to "1U" to add the support
* of HAL callback registration/deregistration feature for the HAL
* driver(s). This allows user application to provide specific callback
* functions thanks to HAL_PPP_RegisterCallback() rather than overwriting
* the default weak callback functions (see each stm32l0xx_hal_ppp.h file
* for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef
* for each PPP peripheral).
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
#define USE_HAL_TSC_REGISTER_CALLBACKS 0U
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0UAs I see it there is a conflict in the instruction "Set below the peripheral configuration to "1U" to add the support of HAL callback registration/deregistration feature for the HAL" and silently overwriting the changes.
As I see it the mentioned workaround of adjusting templates is tedious, complex, error prone.
As I see it the hint to define USE_HAL_xyz_REGISTER_CALLBACKS in Project->Properties dialog is not helping as the problem isn't, that it isn't defined, but it is defined with the wrong value.
My recommendation would be to (as in main.c) introduce
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
before
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_hal_conf.h"
in stm32yxxx_hal.h.
That way developers could add an include of their stm32yxxx_hal_conf-customization.h easily.
To prevent redefines in stm32yxxx_hal_conf.h each define should have a #ifndef
Are there better ways then / reasons against this approach?