2023-11-22 09:06 PM - last edited on 2024-07-08 07:04 AM by Peter BENSCH
Hello everyone!. I'm looking for a way to prevent a function from the "stm32g0xx_it.c" library from being compiled because I'm using it in my MAIN code. The function is "void I2C2_IRQHandler(void)". What I do is to DELETE the function in the library but every time I GENERATE THE CODE it reappears in the library again and again.... Is there a way to prevent this function from compiling?
This is the function.
void I2C2_IRQHandler(void)
{
/* USER CODE BEGIN I2C2_IRQn 0 */
/* USER CODE END I2C2_IRQn 0 */
if (hi2c2.Instance->ISR & (I2C_FLAG_BERR | I2C_FLAG_ARLO | I2C_FLAG_OVR)) {
HAL_I2C_ER_IRQHandler(&hi2c2);
} else {
HAL_I2C_EV_IRQHandler(&hi2c2);
}
/* USER CODE BEGIN I2C2_IRQn 1 */
/* USER CODE END I2C2_IRQn 1 */
}
PD.: The reason why I don't use the HAL library is because of the very long execution times in the HAL library.
2023-11-22 09:27 PM
Hello @modonga
I suggest you Wrap the function definition with an "#ifdef" block and a custom macro, and then control the compilation of that function by defining or not the macro.
Best Regards.
STTwo-32
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.
2023-11-22 09:51 PM
mmmmm. continue the "multiple definition of `I2C2_IRQHandler' error....
I create a file called "specialFuncI2C.h" and include in the "main.c"
specialFuncI2C.h:
#ifndef I2C_IRQ
#define I2C_IRQ
void I2C2_IRQHandler(void) {
bla...
bla...
bla...
}
#endif
2023-11-22 10:51 PM
add an #ifdef block around the function definition to exclude it from the build:
#ifdef I2C2_IRQHandler
void I2C2_IRQHandler(void)
{
/* function code here */
}
#endif
Best Regards
STTwo-32
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.
2023-11-23 05:48 AM
i recently tried but when i run the IOC code generator, the file "stm32g0xx_it.c" its updated and delete the
#ifdef I2C2_IRQHandler
#endif
tags...
2023-11-23 07:16 AM
Within a user code block at the top of the *_it.c file, put:
#define I2C2_IRQHandler unused_I2C2_IRQHandler
This will rename it as something else.