Skip to main content
YWang.15
Associate II
June 30, 2022
Solved

stm32g4xx_mc_it.c and stm32g4xx_it.c

Hi, I am using CubeMX generates the application that contains MCSDK, The generated code has both stmg4xx_mc_it.c and stm32g4xx_it.c. I noticed that all the motor control related ISR code are coded in stm32g4xx_mc_it.c and I am confused with 2 issues:

  1. The generated ISR function prototype can not be found in startup_stm32g474xx.s. I am wondering how the ISR can be referenced in vector table.
  2. If I need to add more ISRs, where shall I put the ISR functions? Under stm32g4xx_it.c or stm32g4xx_mc_it.c

Your kindly help is greatly appreciated.

This topic has been closed for replies.
Fred V.
Fred V.Best answer
ST Employee
June 30, 2022

Hello,

About the prototypes of ISR functions defined in stmg4xx_mc_it.c, there are #defines that change these names into the ones defined in startup_stm32g474xx.s. These defines can be found in file parameters_conversion_g4xx.h and in file mcp_config.h. Here are the defines for STM32G4:

#define TIMx_UP_M1_IRQHandler TIM1_UP_TIM16_IRQHandler

#define TIMx_BRK_M1_IRQHandler TIM1_BRK_TIM15_IRQHandler

#define USARTA_IRQHandler USART2_IRQHandler

#define MCP_RX_IRQHandler_A DMA2_Channel2_IRQHandler

It is probably best to add your own ISR handlers in file stm32g4xx_it.c. But beware: if you configure additional ISR, you should probably configure the related peripherals in STM32CubeMx. Then, the ISR Handlers would be generated for you by STM32CubeMx in file stm32g4xx_it.c. Then, you can fill the USER SECTIONS with your own code if/where needed. For all details on that, please have a look at the STM32CubeMx documentation.

I hope it will help.

Best Regards

Fred

1 reply

Fred V.
Fred V.Best answer
ST Employee
June 30, 2022

Hello,

About the prototypes of ISR functions defined in stmg4xx_mc_it.c, there are #defines that change these names into the ones defined in startup_stm32g474xx.s. These defines can be found in file parameters_conversion_g4xx.h and in file mcp_config.h. Here are the defines for STM32G4:

#define TIMx_UP_M1_IRQHandler TIM1_UP_TIM16_IRQHandler

#define TIMx_BRK_M1_IRQHandler TIM1_BRK_TIM15_IRQHandler

#define USARTA_IRQHandler USART2_IRQHandler

#define MCP_RX_IRQHandler_A DMA2_Channel2_IRQHandler

It is probably best to add your own ISR handlers in file stm32g4xx_it.c. But beware: if you configure additional ISR, you should probably configure the related peripherals in STM32CubeMx. Then, the ISR Handlers would be generated for you by STM32CubeMx in file stm32g4xx_it.c. Then, you can fill the USER SECTIONS with your own code if/where needed. For all details on that, please have a look at the STM32CubeMx documentation.

I hope it will help.

Best Regards

Fred