The original published blog.csdn.net/Eterlove/ar here…
Keil5 debugging tips
Debugging can’t be taught, it’s something you do. So what is the point of writing this article? A person’s development will always be limited by their own vision, will be extremely ling, take a look at the small mountains, the author would like to take you to see the mountain scenery, as for the final climb depends on your ability and perseverance, this article only play a role of a brick to attract jade.
In the author’s experience, the use of Keil5 debugging board should be STM32 microcontroller, of course, Ti chip integrated debugging environment CCS this aspect is also good, then quickly view the function definition and display function call level than Keil5. This article mainly combines Keil5 tools to talk about debugging skills. At the beginning of learning a certain stage, I had trouble finding out the problem and how to verify my ideas. Later, I got the chance, thanks to the guidance of a good teacher, overnight debugging and the day after tomorrow’s practice to have some of my own talking skills, and then I had the idea to write this blog.
1. The comment / /
This method is simple and obvious effect, very easy to use. When you don’t know the function of this code, don’t rush to see the source code, it is better to annotate it, compile and download it to the development board to see the effect, this trick annotation // I tried again and again, although not sophisticated, but in practical.
/ / Gui_DrawFont_GBK16 (9, 5, BLUE, GRAY0, "AD TEST:"); Gui_DrawFont_GBK16 (10, 25, BLACK, GRAY0, "Light:"); Gui_DrawFont_GBK16 (115, 25, BLUE GRAY0, "%"); DisplayButtonUp,25,80,45 (5); / / the x1, y1, x2, y2 DisplayButtonUp,27,125,45 (85); //x1,y1,x2,y2Copy the code
2. Since the board is in hand, it is better to combine soft and hard
As far as the author is concerned, debugging is simply divided into software debugging and hardware debugging and the combination of soft and hard debugging
- Hardware debugging: simply download the program, observe the board phenomenon, often used in conjunction with the first skill notes, if the program is written this phenomenon, download board is also this phenomenon, the program is correct.
- Software debugging: in the case of no development board, the use of simulation environment (Keil5,CCS have) for debugging results, imagine the board phenomenon. For example, if the board LED is switched on at high level, we can know that this value is 1 in the software, then we assume (imagine) that the LED light is switched on.
- Software and hardware debugging: the program is run in an integrated environment (such as Keil5/CCS), and the development board is tested synchronously, often through single step debugging, “step by step, corresponding step by step phenomenon”. Now the author is commonly used is this kind of delicate method, in the final analysis, this method can be simple to use, can also join a variety of debugging means into it, so that it is very debugging, quickly find the problem. — > Since the board in hand, as soft hard combination
- And one more thing, as I like to do when I’m working on other people’s projects,Look at the source code, always like to use a single step in the main function debugging to quickly clarify the context of the program. After all, “watching without moving” is prone to dozing off and distraction. It is better to “see the source code as a debugging program”, see the program step by step to move up, eyes also follow, slowly “drilled”, focus on.
3. Use debugging gadgets
Keil5 integrated development environment gives a lot of debugging tools and view Windows, in fact, debugging this aspect has a lot of attention, but it is not directly taught, any teaching method is not as good as your own practice, take me to learn embedded university teachers, gave me advice is “more trouble”.
3.1 These eight basic debugging buttons should be very familiar with it, how do not know how to enter the debugging and the meaning of these buttons please baidu, debugging how can not start it.
3.2 Breakpoint Settings to learn, set the breakpoint to where you think the current problem, run the program to verify
/* PA1 of the core board is connected to A2 of the WIFI module :PC8 indicator blinks to indicate the illumination percentage on the operating screen of the system GND power ground VCC 5V or 3.3v SCL PA5 (SCL) SDA PA7 (SDA) RES PB0 DC PB1 CS PA4 BL PB10 */ #include "stm32f10x.h" #include "main.h" #include "delay.h" #include "usart1.h" #include "timer2.h" #include "led.h" #include "global.h" #include "stdio.h" #include "math.h" #include "string.h" #include "LCD_calculate.h" #include "Lcd_Driver.h" #include "usart1.h" #include "adc.h" int main(void) { u8 adcx=0; char txt[20]; Delay_Init(); Usart1_Init(9600); // Serial port 1 function initialization, baud rate 9600 LED_Init(); // TIM2_Init(); // timing 10mm Lcd_Init(); Lcd_Clear(RED); / / screen clearing LCD_LED_SET; Adc3_Init(); Lsens_Init(); Gui_DrawFont_GBK16 (9, 5, and BLUE, GRAY0, "AD TEST:"); Gui_DrawFont_GBK16 (10, 25, BLACK, GRAY0, "Light:"); Gui_DrawFont_GBK16 (115, 25, BLUE GRAY0, "%"); DisplayButtonUp,25,80,45 (5); / / the x1, y1, x2, y2 DisplayButtonUp,27,125,45 (85); //x1,y1,x2,y2 //TO while(1) {if(timecount>30) {timecount=0; adcx=Lsens_Get_Val(); sprintf(txt, "%d", adcx); Gui_DrawFont_GBK16 (90, 25, BLUE GRAY0, TXT); LED1=! LED1; }}}Copy the code
3.3 Will use Windows to observe the value changes of variables (as shown in ADCX), and even observe the value changes of each element of the array. The combination of soft and hard debugging will find that the value of variables is constantly changing. The position of the window can be moved and scaled as you like
3.4 There are also some serial Windows that we often debug programs. We often use the printf function to print information to help with debugging. When writing C language, the printed information is directly displayed in the PC command line window, but note that it is not possible in the microcontroller debugging, the need for serial redirection, the principle is the same, the specific code please Baidu (STM32 and MSP432 serial redirection code is different)
4. Take a break, walk outside, and clear your mind
When the above method did not find the problem, first do not worry, if the mood becomes more and more agitated, it is recommended to stop working immediately, go out for a walk, let your brain calm down —-> head is very confused, you find and solve the problem of ability will be serious decline, it is better to go out to see the scenery!
This article is original, please indicate the source and author