How to use the Understand software to view the function call relationship of the STM32 microcontroller HAL library

  When using the HAL library function programming of the STM32 microcontroller, you will find that there are various callback functions in many interrupt functions, and many functions have a deep call depth. When writing code, sometimes you want to check how a certain function is called. Called, it is very troublesome to check. At this time, you can use the Understand software to view the function call diagram.

  How to use this software can be viewed Embedded code view analysis tool - Understand this article.
  When using the Understand software to view the MCU code written by the keil project, there will be a situation that many library functions cannot jump.
insert image description here
  For example, to view HAL_CAN_IRQHandlerthis function, when you press and hold the ctrl key and click the mouse, you find that you have not jumped to HAL_CAN_IRQHandlerthe inside of this function.
insert image description here
  After directly opening the file where the function is located, it is found that this function has not been compiled, and all the interfaces are gray. Why is this? Obviously, it can be used normally in the keil project, but it is not compiled in Understand. This is a setting in the keil software to declare header files.
insert image description here
  Click the magic wand tool in the keil software, open the option setting interface, and switch to the C/C++ option. At this time, the two USE_HAL_DRIVER,STM32F407xxvalues ​​​​filled in after the Difine option are the declarations of the macro definition. When the keil software is compiled, these two values ​​will be automatically added. A statement is compiled into it. However, the Understand software cannot find these two macro definitions in the project code, so it defaults that these two macro definitions are not defined, and the related code will not be compiled. If you want the Understand software to compile the relevant code, you need to manually add these two macro definition declarations to the code. Since the code of the HAL library includes stm32f4xx.hthis header file, the macro definition is written in this header file. The name of this header file is related to the model of the single-chip microcomputer I use. The single-chip microcomputer I use is STM32F407, so the name of the header file is stm32f4xx.h.
insert image description here

  Open stm32f4xx.hthis header file in Understand and add the macro definition statement at the very beginning

#ifndef USE_HAL_DRIVER
 #define USE_HAL_DRIVER
 #endif

 #ifndef STM32F407xx
 #define STM32F407xx
 #endif

insert image description here

  Then select Project — Analyze All Files in the toolbar to recompile all files.
insert image description here
  At this time, open stm32f4xx_hal_can.cthe file
insert image description here
  again. At this time, the interrupt function will be compiled. HAL_CAN_IRQHandlerHold down the ctrl key and click the mouse on the function name, and then you can jump to the inside of this function normally.
insert image description here
  At this time, if you want to view the callback function of can interrupt, select HAL_CAN_RxFifo0MsgPendingCallbackthe function, and then select Called By in the calling relationship.
insert image description here
  At this time, you can clearly see that the function is called from the can.c file HAL_CAN_IRQHandler, and this function calls can. HAL_CAN_RxFifo0MsgPendingCallbackfunction in the c file . insert image description here
  You can also check HAL_CAN_IRQHandlerwhich callback functions are called in the function, double-click to select HAL_CAN_IRQHandlerthe function name, and then select Calls in the tool blue call relationship diagram.
insert image description here

  You can see that HAL_CAN_IRQHandlerthere are many callback functions in the function.
insert image description here
  Through this method of manually adding macro definitions, you can view the calling relationship of HAL library functions in the Understand software, and the graphical interface helps us to be more efficient when writing programs.

Guess you like

Origin blog.csdn.net/qq_20222919/article/details/130733999