Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.

Revision:
12:a8ab6e018422
Parent:
7:60a32302de22
Child:
15:83d4dced2a28
--- a/debug_serial.cpp	Thu May 09 21:24:31 2019 +0000
+++ b/debug_serial.cpp	Mon May 13 08:39:42 2019 +0000
@@ -92,15 +92,22 @@
 // print formatted string to debug serial port
 //------------------------------------------------------------------------------------------------------------------ 
 int Debug_serial::printf(const char* format, ...){
+    
+    int ret = pc.printf(format);
+    return ret;
+}
 
-    int ret = pc.printf(format);
+// read formatted string from debug serial port
+//------------------------------------------------------------------------------------------------------------------ 
+int Debug_serial::scanf(const char* format, ...){
+    
+    int ret = pc.scanf(format);
     return ret;
 }
 
 // print character to debug serial port
 //------------------------------------------------------------------------------------------------------------------ 
 int Debug_serial::putc(int character){
-
     return pc.putc(character);
 }
 
@@ -110,10 +117,14 @@
     return pc.getc();
 }
 
+// check whether there is any character to read
+//------------------------------------------------------------------------------------------------------------------ 
 bool Debug_serial::readable(){
     return pc.readable();
 }
 
+// check whether it is possible to write a sign to debug serial port
+//------------------------------------------------------------------------------------------------------------------ 
 bool Debug_serial::writable(){
     return pc.writable();
 }
@@ -121,32 +132,34 @@
 // clear screen from m line up to n line
 //------------------------------------------------------------------------------------------------------------------
 void Debug_serial::clear_from_n_up_to_m(int m, int n){
-    pc.printf("\033[%d;0H",m);
+    pc.printf("\033[%d;0H",m); //replace cursor to m-th row, 0 column
     wait(0.1);
     while (m > n){ 
         m--;
-        pc.printf("\033[K\033[%d;0H",m);
+        pc.printf("\033[K\033[%d;0H",m); // clear entire line
     }
-    pc.printf("\n\r");
+    pc.printf("\n\r");// go to new line
 
 }
 
-// print 3 last breakpoints
+// print information about 3 last breakpoints
 //------------------------------------------------------------------------------------------------------------------
 void Debug_serial::print_3_breaks(int line_number){
-    pc.printf("\e[s");
+    pc.printf("\e[s"); //save current cursor position
     wait_ms(50);
     breakpoint_count++;
-    break_line[2] = break_line[1];
+    break_line[2] = break_line[1]; //save information about line of breakpoints
     break_line[1] = break_line[0];
     break_line[0] = line_number;
-    clear_from_n_up_to_m(12,3);
-    int i = (breakpoint_count>=3)?3:breakpoint_count;
+    
+    clear_from_n_up_to_m(12,3); // clear screen from 12th to 3rd line
+    
+    int i = (breakpoint_count>=3)?3:breakpoint_count; //print 3 previous breakpoints if possible
     while (i > 0){
         if (i == 1 ){
-            pc.printf("\e[1m\e[96;40m");
+            pc.printf("\e[1m\e[96;40m"); //change color of the last breakpoint
             print_one_break(i);
-            pc.printf("\e[22m\e[97;40m");            
+            pc.printf("\e[22m\e[97;40m"); //return to normal color
         }else{
             print_one_break(i);        
         }
@@ -155,7 +168,7 @@
     pc.printf("\e[32;40mto continue press any button\e[97;40m");
     pc.getc();
     pc.printf("\r\e[2K\e[31;40mprogram is running\e[97;40m\n\r");  
-    pc.printf("\e[u");
+    pc.printf("\e[u"); // return cursor to serial port part
   
 }