In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you STM32 in the Keil environment how to use Cm_Backtrace for error tracking, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Introduction
When we usually use the STM32 single chip microcomputer, we often encounter the situation that the program runs away and there are errors such as hard_fulat. When we locate the error, we often use the method of connecting the simulator, debugging step by step, locating the specific error code, and then guessing, eliminating and deliberating the cause of the error. This process is very painful, and in the actual situation. Many products have to disconnect the simulator when debugging, that is to say, the problem does exist, but it is extremely difficult to occur, so under the background of such a problem, RTT's boss armink has developed a MCU error tracking library based on ARM Cortex-M series to help developers solve the above problems.
The function and applicable platform of CmBacktrace first of all, CmBacktrace is an open source library for automatic tracking, positioning and automatic analysis of error codes of ARM Cortex-M series MCU. The errors it supports include:
Assertion (assert)
Malfunction
Hard Fault, Memory Management Fault, Bus Fault, Usage Fault, Debug Fault
Bare metal and the following operating system platforms are supported:
RT-Thread
UCOS
FreeRTOS
Adapting to Cortex-M0/M3/M7 MCU, supporting IAR, KEIL and GCC compilers, the results can be achieved: automatic diagnosis of fault causes, automatic analysis of fault causes, location of fault codes, and output of the function call stack at the error site.
Transplant
At present, the platform used by the author is keil 5, and the controller used is STM32F103. We are preparing a project with serial port function. The structure of the project is as follows:
Image-20210306101326283
Next, let's take a look at the cm_backtrace source code:
Image-20210306101659128
In the above, the source code is stored in the cm_backtrace folder, and we need to copy all of it to our project directory. Demos is an example of use, which is divided into two types: operating system and non-operating system. Then tools stores tools that analyze code errors in the form of command line. After copying the relevant files to the project directory, the files in the project directory are as follows:
Image-20210306102410525
Then, we add the relevant files to the project, and the following is the project file after the addition:
Image-20210306102815766
At the same time, you should add the relevant header file path, as shown below:
Image-20210306102919999
At this point, the source code for cm_backtrace has been added, let's compile it. The compilation results are as follows:
Image-20210306103031890
You can find many errors because our relevant macros have not been opened yet. We open the corresponding macros in turn in cmb_def.h according to a table in the instructions document in the source code, as shown below:
Configure the name function Note cmb_println (…) The output of error and diagnostic information must be configured whether CMB_USING_BARE_METAL_PLATFORM is used on bare metal platform, then define whether the macro CMB_USING_OS_PLATFORM uses the function of CMB_OS_PLATFORM_TYPE operating system platform RTT/UCOSII/UCOSIII/FREERTOSCMB_CPU_PLATFORM_TYPECPU platform M0/M3/M4/M7CMB_USING_DUMP_STACK_INFO using Dump stack on operating system platform and bare metal platform. The language CHINESE/ENGLISH that can be used to define the output information of the macro CMB_PRINT_LANGUAGE
The code after the change is as follows:
Image-20210306103649154
After changing the macro, let's compile the code, and the result is as follows:
Image-20210306103729814
To enable the c99 compilation mode, we set it in keil as follows:
Image-20210306103831859
Continue the compilation and see that there is another error message, and the compilation result is as follows:
Image-20210306104005145
This is because the HardFault_Handler function is defined in cmb_fault.S using assembly, while in the original project, HardFault_Handler has been defined in stm32f10x_it.c. We commented out the HardFault_Handler in stm32f10x_it.c. The code is as follows:
Image-20210306104326301
Now the compilation is ready to pass.
test
After the migration, let's now test how to detect the error caused by dividing 0 in the single-chip microcomputer, and we add the following code to the main function:
# include "stm32f10x.h" # include "bsp_usart.h" # include # define HARDWARE_VERSION "V1.0.0" # define SOFTWARE_VERSION "V0.1.0" extern void fault_test_by_div0 (void) / * * @ brief main function * @ param none * @ retval none * / int main (void) {/ * initialize USART configuration mode to 115200 8-N-1, interrupt receiving * / USART_Config (); / * CmBacktrace initialize * / cm_backtrace_init ("CmBacktrace", HARDWARE_VERSION, SOFTWARE_VERSION); fault_test_by_div0 () While (1) {}}
Burn the program to the single-chip microcomputer, and observe the output information through the serial port debugging assistant:
Image-20210306105316179
We can see that the output shows that the current usage error is: an attempt to divide by 0, and the relevant register information is given, but we do not know which line of the code in which the error occurred. At this time, we need to use the tool under the tools folder mentioned earlier, the addr2line tool. When using this tool, you need to know the name of the executable output of the current tool. We open keil and the information is as follows:
Image-20210306105719377
Then, we find the tools tool under the cm_backtrace folder and copy it to the same directory as USART.axf. The copied folder directory is as follows:
Image-20210306110017993
Open the cmd window under the current folder, and then run addr2line-e USART.axf-a-f 08001844 0800189a, here mention how to open cmd, hold down the shift key, and then right, open Powershell
Image-20210306110527928
Open the Powershell as shown below, enter start cmd in Powershell to open the cmd window, and then enter addr2line-e USART.axf-a-f 08001844 0800189a in the cmd window. The results are as follows:
Image-20210306110839097
You can see that the error message is line 38 of fault_test.c. Let's open the source code to see:
Image-20210306111229605
You can see that it is indeed line 38, and the problem analysis is correct.
The above is all the content of the article "how to use Cm_Backtrace for error tracking in STM32 in Keil environment". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 219
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.