Skip to main content
Associate II
November 23, 2023
Question

Avoid To Include some HAL function of "stm32g0xx_it.c"

  • November 23, 2023
  • 5 replies
  • 2211 views

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.

This topic has been closed for replies.

5 replies

STTwo-32
ST Technical Moderator
November 23, 2023

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.
modongaAuthor
Associate II
November 23, 2023

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

 

 

STTwo-32
ST Technical Moderator
November 23, 2023

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.
modongaAuthor
Associate II
November 23, 2023

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...

 

TDK
November 23, 2023

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."