From a60a8db3ae41b77f77406b44b77f9a84cff85792 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Fri, 13 May 2022 11:23:04 +0200 Subject: [PATCH] fix: allow to disable HAL CRC module Thanks to @patricklaf comment. Signed-off-by: Frederic Pillon --- cores/arduino/stm32/stm32yyxx_hal_conf.h | 12 ++++++------ libraries/SrcWrapper/src/stm32/clock.c | 2 ++ libraries/SrcWrapper/src/stm32/hw_config.c | 15 +++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cores/arduino/stm32/stm32yyxx_hal_conf.h b/cores/arduino/stm32/stm32yyxx_hal_conf.h index b3473bdefa..a5bd4abc8e 100644 --- a/cores/arduino/stm32/stm32yyxx_hal_conf.h +++ b/cores/arduino/stm32/stm32yyxx_hal_conf.h @@ -28,6 +28,12 @@ #undef HAL_ADC_MODULE_ENABLED #endif +#if !defined(HAL_CRC_MODULE_DISABLED) + #define HAL_CRC_MODULE_ENABLED +#else + #undef HAL_CRC_MODULE_ENABLED +#endif + #if !defined(HAL_I2C_MODULE_DISABLED) #define HAL_I2C_MODULE_ENABLED #else @@ -70,12 +76,6 @@ #undef HAL_ICACHE_MODULE_ENABLED #endif -#if !defined(HAL_CRC_MODULE_ENABLED) - #define HAL_CRC_MODULE_ENABLED -#else - #undef HAL_CRC_MODULE_ENABLED -#endif - /* * Not defined by default */ diff --git a/libraries/SrcWrapper/src/stm32/clock.c b/libraries/SrcWrapper/src/stm32/clock.c index 500cad05a6..566831e4d7 100644 --- a/libraries/SrcWrapper/src/stm32/clock.c +++ b/libraries/SrcWrapper/src/stm32/clock.c @@ -174,12 +174,14 @@ void configIPClock(void) __HAL_RCC_SYSCFG_CLK_ENABLE(); #endif +#if defined(HAL_CRC_MODULE_ENABLED) /* Enable CRC clock, needed for example: MotionFX Library ... */ #if defined(__HAL_RCC_CRC2_CLK_ENABLE) __HAL_RCC_CRC2_CLK_ENABLE(); #elif defined(__HAL_RCC_CRC_CLK_ENABLE) __HAL_RCC_CRC_CLK_ENABLE(); #endif +#endif } #ifdef __cplusplus diff --git a/libraries/SrcWrapper/src/stm32/hw_config.c b/libraries/SrcWrapper/src/stm32/hw_config.c index 889d124719..d1c0649292 100644 --- a/libraries/SrcWrapper/src/stm32/hw_config.c +++ b/libraries/SrcWrapper/src/stm32/hw_config.c @@ -19,14 +19,17 @@ extern "C" { #endif -#ifdef CRC2_BASE -#define CRC_INSTANCE CRC2 +#if defined(HAL_CRC_MODULE_ENABLED) +CRC_HandleTypeDef hcrc = {.Instance = +#if defined(CRC2_BASE) + CRC2 #elif defined(CRC_BASE) -#define CRC_INSTANCE CRC + CRC #else -#error "No CRC instance available" +#error "No CRC instance available!" +#endif + }; #endif -CRC_HandleTypeDef hcrc = {.Instance = CRC_INSTANCE}; /** * @brief This function performs the global init of the system (HAL, IOs...) @@ -63,7 +66,7 @@ void hw_config_init(void) SystemClock_Config(); /* Initialize the CRC */ -#if defined(CRC_INSTANCE) +#if defined(HAL_CRC_MODULE_ENABLED) HAL_CRC_Init(&hcrc); #endif