cancel
Showing results for 
Search instead for 
Did you mean: 

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

modonga
Associate II

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.

5 REPLIES 5
STTwo-32
ST Employee

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.

modonga
Associate II

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

 

 

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.

modonga
Associate II

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
Guru

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