cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to customize code generated by CubeIDE/MX?

magene
Senior II

STM32CubeIDE is a big help for a relatively inexperienced embedded programmer like me.  However, the program structure it uses isn't ideal for the way I organize my  C++ projects. My projects have to interface with lots of devices, for example a GPS receiver connected to a UART.  In my way of thinking it would be nice to have a UART class and a GPS class. The UART class would have the UART specific IRQs in it. The GPS class would instantiate an instance of the UART class specific to the UART the GPS is connected to.  CubeIDE puts all the IRQs in the stm32h7xx_it.c file.  I've been editing these IRQs with the __weak qualifier so I can override them with an IRQ Handler in my UART class. But I have to re-edit the stm32h7xx_it.c file every time I regenerate the code with CubeIDE/MX. 

The IRQs have /* USER CODE BEGIN ... */ and /* USER CODE END ... */ inside the function but they don't cover the function signature. The generated code looks like this

 

 

 

 void USART1_IRQHandler(void)
{
  /* USER CODE BEGIN USART1_IRQn 0 */

  /* USER CODE END USART1_IRQn 0 */
  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */
}

 

 

 

It would be nice to do something like this

 

 

 

  /* USER CODE BEGIN USART1_IRQn 0 */
__weak void USART1_IRQHandler(void)
{
  /* USER CODE END USART1_IRQn 0 */

  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */
}

 

 

 

I've tried several variations on this without success.  I know I could just put a call to an IRQ handler in my UART class inside the generated code but it would be nice to minimize the number of function calls.  Any suggestions or other ideas about how to do this will be greatly appreciated.  Thanks.

 

 

 

1 REPLY 1
MM..1
Chief III

Maybe here you can off on or simply exclude it file from build and use own.

MM1_0-1688485191987.png