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

Revision:
12:a8ab6e018422
Parent:
10:4d5f38d996e2
Child:
15:83d4dced2a28
--- a/Debug.h	Thu May 09 21:24:31 2019 +0000
+++ b/Debug.h	Mon May 13 08:39:42 2019 +0000
@@ -1,6 +1,6 @@
 #pragma once
 
-// include files
+// include libraries
 //------------------------------------------------------------------------------------------------------------------
 #include "mbed.h"
 #include <stdlib.h>
@@ -26,7 +26,7 @@
     int number;
 } pin_t;
 
-
+//------------------------------------------------------------------------------------------------------------------
 /** Debug_serial class.
  *  Class for stepping programme and printing actual position of the running programme with optional print of one variable (int, float, char or char*).
  *  Functions printf, putc and getc are also defined in the class.
@@ -36,13 +36,13 @@
  * // ----------------------------------------------------------------------------
  * // Author: Lukas Bielesch 
  * // Department of Measurement, Czech technical university in Prague, Czech Republic 
- * // Date of publication: 15. Apr 2019
+ * // Date of publication: 13. May 2019
  * // ----------------------------------------------------------------------------
  * #include "Debug.h"
  * AnalogIn analog(PA_4);
  * PwmOut pwm(PA_6);
  * DigitalOut out(PA_5);
- * Debug_serial pc(PA_2, PA_3, 115200); //
+ * Debug_serial pc(PA_2, PA_3, 115200);
  * 
  * int main(){
  *     int var = 0;
@@ -67,62 +67,64 @@
  * }
  * @endcode
  */
-//------------------------------------------------------------------------------------------------------------------
 class Debug_serial {
 public:
 
-    /** Create object of class Debug_serial
-     * @param tx_pin TX pin of serial port of the board
-     * @param rx_pin RX pin of serial port of the board
-     * @param baudrate desired baudrate value of debug serial port
+    /** Create object of Debug_serial class
+     * @param tx_pin TX pin of debug serial port
+     * @param rx_pin RX pin of debug serial port
+     * @param baudrate(optional) desired baudrate value of debug serial port, default baudrate is 115200 Bd/s
      */
     Debug_serial(PinName tx_pin, PinName rx_pin, int baudrate = 115200);
     
     /** Perform one breakpoint without printing variable
-     * @param line_number line number of the breakpoint
+     * @param line_number(optional) line number of breakpoint,macro __LINE__ is recommended
      */ 
     void breakpoint(int line_number = -1);
 
     /** Perform one breakpoint and print variable of type int
-     * @param line_number Line number of the breakpoint
-     * @param name name of printed variable(max length is 19) 
-     * @param variable
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param name name of printed variable(max length is 19) , macro name(variable) is recommended
+     * @param variable variable of type int
      */     
     void breakpoint(int line_number, char name[20], int variable);
     
     /** Perform one breakpoint and print variable of type char
-     * @param line_number Line number of the breakpoint
-     * @param name name of printed variable(max length is 19) 
-     * @param variable
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param name name of printed variable(max length is 19) , macro name(variable) is recommended
+     * @param variable variable of type int
      */     
     void breakpoint(int line_number, char name[20], char variable);
     
-    /** Perform one breakpoint and print variable of type string
-     * @param line_number Line number of the breakpoint
-     * @param name name of printed variable(max length is 19) 
-     * @param variable
+    /** Perform one breakpoint and print string variable
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param name name of printed variable(max length is 19) , macro name(variable) is recommended
+     * @param variable variable of type char*
      */     
     void breakpoint(int line_number, char name[20], char * variable);
     
     /** Perform one breakpoint and print variable of type float
-     * @param line_number Line number of the breakpoint
-     * @param name name of printed variable(max length is 19) 
-     * @param variable
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param name name of printed variable(max length is 19) , macro name(variable) is recommended
+     * @param variable variable of type float
      */ 
     void breakpoint(int line_number, char name[20], float variable);
     
     /** Perform one breakpoint and print one register value
-     * @param line_number Line number of the breakpoint
-     * @param address
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param address address of register, must be divisible by 4
      */ 
     void breakpoint(int line_number, uint32_t address);
     
    /** Print formatted string to debug serial port
-     * @param string
-     * @param format (optional)
      * @returns total number of printed characters or negative value if an output error or an encoding error
      */
     int printf(const char* format, ...);
+
+   /** Read formatted string from debug serial port
+     * @returns total number of successfully read arguments or negative value if en error occured
+     */   
+    int scanf(const char* format, ...);
     
     /** Print one character to debug serial port 
      * @param character
@@ -135,7 +137,14 @@
     */
     int getc();
     
+    /** Check whether there is some character available to read from debug serial port.
+    * @returns true when there is something available to read
+    */    
     bool readable();
+    
+    /** Check whether it is possible to write a character to debug serial port.
+    * @returns true when it is possible to write a character to debug serial port
+    */ 
     bool writable();
     
 private:
@@ -144,8 +153,8 @@
   
 protected:  
 // objects:
-    Serial pc; //debug serial device
-// variables:
+    Serial pc; //debug serial port
+// variables
     int breakpoint_count; //stores number of the current breakpoint
 // functions
     // initialization function    
@@ -158,8 +167,7 @@
     void clear_from_n_up_to_m(int m, int n);
 };
 
-
-
+//------------------------------------------------------------------------------------------------------------------
 
 /** Debug_led class.
  *  Class for stepping the program with debug LED and button, that is connected to GND(default) or VCC.
@@ -169,7 +177,7 @@
  * // ----------------------------------------------------------------------------
  * // Author: Lukas Bielesch 
  * // Department of Measurement, Czech technical university in Prague, Czech Republic 
- * // Date of publication: 15. Apr 2019
+ * // Date of publication: 13. May 2019
  * // ----------------------------------------------------------------------------
  * #include "Debug.h"
  * AnalogIn analog(PA_0);
@@ -193,7 +201,6 @@
  * @endcode
  */
 // class Debug_led
-//------------------------------------------------------------------------------------------------------------------
 class Debug_led {
 public:
 
@@ -205,7 +212,7 @@
     Debug_led(PinName led_pin, PinName button_pin, char mode[11] = "BUTTON_GND");
     
     /** Perform one breakpoint
-     * @param number number of flashes of LED during the breakpoint(optional)
+     * @param number(optional) number of flashes of periodic flashing of LED during the breakpoint, default is constant flashing
      */
     void breakpoint(int number = -1);
 
@@ -215,27 +222,24 @@
     InterruptIn button; //debug button
 // variables
     int button_mode; //mode of button 1->pullupt, 0->pulldown 
-    volatile bool end_breakpoint;
-    int number_of_breakpoints;
+    volatile bool end_breakpoint; //true when button was pushed
+    int number_of_breakpoints; //number of the current breakpoint
     
     /** Initialization */
     void init(char mode[11]);
     
-    /** Blinks the debug led n-times with blink period  wait_time_ms */
+    /** Blink the debug led n-times with blink period  wait_time_ms */
     void flash_n_times(int wait_time_ms, int n);
     
-    /** end the break after the button is pushed */
+    /** IRQ function, end breakpoint after the button is pushed */
     void end_break();
-
-    
 };
 
-
+//------------------------------------------------------------------------------------------------------------------
 /** Debug_register class.
  *
  * Example program:
  * @code
- * //------------------------------------------------------------------------------------------------------------------
  * // ----------------------------------------------------------------------------
  * // Author: Lukas Bielesch 
  * // Department of Measurement, Czech technical university in Prague, Czech Republic 
@@ -268,27 +272,28 @@
 class Debug_register {
 public:
 
-    /** Create object of class Debug_serial
-     * @param tx_pin TX pin of serial port of the board
-     * @param rx_pin RX pin of serial port of the board
-     * @param baudrate desired baudrate value of debug serial port
+    /** Create object of Debug_register class
+     * @param tx_pin TX pin of debug serial port
+     * @param rx_pin RX pin of debug serial port
+     * @param baudrate(optional) desired baudrate value of debug serial port, default baudrate is 115200 Bd/s
      */
     Debug_register(PinName tx_pin, PinName rx_pin, int baudrate = 115200);
     
     /** Perform one breakpoint and print one register
-     * @param line_number line number of the breakpoint
-     * @param address
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param address address of register, must be divisible by 4
      */ 
-    void breakpoint(int line_number = -1, uint32_t address = 0);
+    void breakpoint(int line_number, uint32_t address);
 
-    
-    
    /** Print formatted string to debug serial port
-     * @param string
-     * @param format (optional)
      * @returns total number of printed characters or negative value if an output error or an encoding error
      */
     int printf(const char* format, ...);
+
+   /** Read formatted string from debug serial port
+     * @returns total number of successfully read arguments or negative value if en error occured
+     */   
+    int scanf(const char* format, ...);
     
     /** Print one character to debug serial port 
      * @param character
@@ -301,31 +306,35 @@
     */
     int getc();
     
+    /** Check whether there is some character available to read from debug serial port.
+    * @returns true when there is something available to read
+    */    
     bool readable();
+    
+    /** Check whether it is possible to write a character to debug serial port.
+    * @returns true when it is possible to write a character to debug serial port
+    */ 
     bool writable();
   
 protected:  
 // objects:
     Serial pc; //debug serial device
 // variables:
-    int breakpoint_count; //stores number of the current breakpoint
+    int breakpoint_count; //number of the current breakpoint
 // functions
     // initialization function    
     void init();
     // clear screen from m line up to n line
     void clear_from_n_up_to_m(int m, int n);
+    //modify actual address or register value according to position in terminal
     uint32_t modify_value(uint32_t value, int horizontal);
-
 };
 
-
-
-
+//------------------------------------------------------------------------------------------------------------------
 /** Debug_register_print class.
  *
  * Example program:
  * @code
- * //------------------------------------------------------------------------------------------------------------------
  * // ----------------------------------------------------------------------------
  * // Author: Lukas Bielesch 
  * // Department of Measurement, Czech technical university in Prague, Czech Republic 
@@ -354,33 +363,37 @@
 class Debug_register_print {
 public:
 
-    /** Create object of class Debug_serial
-     * @param tx_pin TX pin of serial port of the board
-     * @param rx_pin RX pin of serial port of the board
-     * @param baudrate desired baudrate value of debug serial port
+    /** Create object of Debug_register_print class
+     * @param tx_pin TX pin of debug serial port
+     * @param rx_pin RX pin of debug serial port
+     * @param baudrate(optional) desired baudrate value of debug serial port, default baudrate is 115200 Bd/s
      */
     Debug_register_print(PinName tx_pin, PinName rx_pin, int baudrate = 115200);
 
-
-    void format(int break_number = 2, int line = 2, int address = 1, int value = 1);
+    /** Set format of breakpoint message
+     * @param break_number format of number of actual breakpoint: 0->not show, 1->show in hexadecimal, 2->show in decimal(default)
+     * @param line format of line of actual breakpoint: 0->not show, 1->show in hexadecimal, 2->show in decimal(default)
+     * @param address format of address of register: 0->not show, 1->show in hexadecimal(default), 2->show in decimal
+     * @param value format of register value: 0->not show, 1->show in hexadecimal, 2->show in decimal, 3->show in binary(default)
+     */
+    void format(int break_number = 2, int line = 2, int address = 1, int value = 3);
     
-    /** Perform one breakpoint and print one register
-     * @param line_number line number of the breakpoint
-     * @param address
-     * @param offset
+    /** Perform one breakpoint and print one register value
+     * @param line_number line number of breakpoint, macro __LINE__ is recommended
+     * @param address address of register , must be divisible by 4
      */ 
-    void breakpoint(int line_number = -1, uint32_t address = 0, int number_of_words = 1);
+    void breakpoint(int line_number, uint32_t address, int number_of_words = 1);
 
   
 protected:  
 // objects:
     Serial pc; //debug serial device
 // variables:
-    int breakpoint_count; //stores number of the current breakpoint
-    int count_format;
-    int line_format; 
-    int address_format;
-    int register_format;
+    int breakpoint_count; //number of the current breakpoint
+    int count_format; // format of breakpoint count, 0->not show, 1->show in hexadecimal, 2->show in decimal
+    int line_format; // format of lineof breakpoint, 0->not show, 1->show in hexadecimal, 2->show in decimal
+    int address_format; // format of address of register, 0->not show, 1->show in hexadecimal, 2->show in decimal
+    int register_format;// format of register value, 0->not show, 1->show in hexadecimal, 2->show in decimal, 3->show in binary
 // functions
     // initialization function    
     void init();