cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4xx_it.c overwirtten if I update the configuration

JHanc.1
Associate

I'm new to STM32 and am trying to get a couple of simple things working at this point. I am trying to generate and handle a GPIO interrupt on PA0 using FreeRTOS and I have no trouble with that. All the examples I've seen say to modify the ISR at stm32f4xx_it.c.

The problem is that anytime I make a change to the STM32 configuration and generate the code again, it overwrites my stm32f4xx_it.c file and the changes I made to the ISR are lost.

Surely I'm missing something simple. Any tips are appreciated! Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
joemccarr
Senior

You have to put the code you want to add in between these comments. Then CubeMX will not over write what you have

in there. Just an example

/* USER CODE END SysTick_IRQn 0 */

code here will not be overwritten

 /* USER CODE BEGIN SysTick_IRQn 1 */

View solution in original post

3 REPLIES 3
joemccarr
Senior

You have to put the code you want to add in between these comments. Then CubeMX will not over write what you have

in there. Just an example

/* USER CODE END SysTick_IRQn 0 */

code here will not be overwritten

 /* USER CODE BEGIN SysTick_IRQn 1 */

KnarfB
Principal III

The code within the USER CODE BEGIB/END "brackets" should not be overwritten by the tools.

When you generate the code, the native IRQ Handler will already contain a call like

void EXTI15_10_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI15_10_IRQn 0 */
 
  /* USER CODE END EXTI15_10_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
  /* USER CODE BEGIN EXTI15_10_IRQn 1 */
 
  /* USER CODE END EXTI15_10_IRQn 1 */
}

HAL_GPIO_EXTI_IRQHandle finally dispatches to a callback HAL_GPIO_EXTI_Callback. If you stick to HAL (not everybody likes that), you don't modify stm32f4xx_it.c at all but implement your own callback anywhere, e.g. in a main.c USER CODE section:

/* USER CODE BEGIN 0 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
   // do what you want
}
/* USER CODE END 0 */

Thanks for both of these replies. It's perfectly obvious now that I see it.