Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.
Debug.h@17:5b0dd2a6b130, 2019-06-03 (annotated)
- Committer:
- bieleluk
- Date:
- Mon Jun 03 19:51:15 2019 +0000
- Revision:
- 17:5b0dd2a6b130
- Parent:
- 16:7fc964b6d127
- Child:
- 18:472b66aeb1f5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bieleluk | 0:e36b454cc2e6 | 1 | #pragma once |
bieleluk | 0:e36b454cc2e6 | 2 | |
bieleluk | 12:a8ab6e018422 | 3 | // include libraries |
bieleluk | 0:e36b454cc2e6 | 4 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 5 | #include "mbed.h" |
bieleluk | 3:3d7837ae4a37 | 6 | #include <stdlib.h> |
bieleluk | 16:7fc964b6d127 | 7 | |
bieleluk | 3:3d7837ae4a37 | 8 | |
bieleluk | 0:e36b454cc2e6 | 9 | |
bieleluk | 0:e36b454cc2e6 | 10 | // macros |
bieleluk | 0:e36b454cc2e6 | 11 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 12 | #define name(var) #var |
bieleluk | 3:3d7837ae4a37 | 13 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
bieleluk | 3:3d7837ae4a37 | 14 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
bieleluk | 0:e36b454cc2e6 | 15 | |
bieleluk | 0:e36b454cc2e6 | 16 | |
bieleluk | 12:a8ab6e018422 | 17 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 18 | /** Debug_serial class. |
bieleluk | 0:e36b454cc2e6 | 19 | * Class for stepping programme and printing actual position of the running programme with optional print of one variable (int, float, char or char*). |
bieleluk | 0:e36b454cc2e6 | 20 | * Functions printf, putc and getc are also defined in the class. |
bieleluk | 0:e36b454cc2e6 | 21 | * |
bieleluk | 0:e36b454cc2e6 | 22 | * Example program: |
bieleluk | 0:e36b454cc2e6 | 23 | * @code |
bieleluk | 0:e36b454cc2e6 | 24 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 25 | * // Author: Lukas Bielesch |
bieleluk | 0:e36b454cc2e6 | 26 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 12:a8ab6e018422 | 27 | * // Date of publication: 13. May 2019 |
bieleluk | 0:e36b454cc2e6 | 28 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 29 | * #include "Debug.h" |
bieleluk | 9:59344a584e18 | 30 | * AnalogIn analog(PA_4); |
bieleluk | 0:e36b454cc2e6 | 31 | * PwmOut pwm(PA_6); |
bieleluk | 9:59344a584e18 | 32 | * DigitalOut out(PA_5); |
bieleluk | 12:a8ab6e018422 | 33 | * Debug_serial pc(PA_2, PA_3, 115200); |
bieleluk | 0:e36b454cc2e6 | 34 | * |
bieleluk | 0:e36b454cc2e6 | 35 | * int main(){ |
bieleluk | 0:e36b454cc2e6 | 36 | * int var = 0; |
bieleluk | 0:e36b454cc2e6 | 37 | * char character; |
bieleluk | 0:e36b454cc2e6 | 38 | * out = 1; |
bieleluk | 0:e36b454cc2e6 | 39 | * float pi = 3.14159265359; |
bieleluk | 0:e36b454cc2e6 | 40 | * pc.breakpoint(__LINE__,name(pi),pi); |
bieleluk | 0:e36b454cc2e6 | 41 | * char* arr = "this is string"; |
bieleluk | 0:e36b454cc2e6 | 42 | * pc.breakpoint(__LINE__,name(arr),arr); |
bieleluk | 0:e36b454cc2e6 | 43 | * pwm = 0.5; |
bieleluk | 0:e36b454cc2e6 | 44 | * pwm.period(1); |
bieleluk | 0:e36b454cc2e6 | 45 | * while(1){ |
bieleluk | 0:e36b454cc2e6 | 46 | * pc.breakpoint(__LINE__,name(var),var); |
bieleluk | 0:e36b454cc2e6 | 47 | * pc.printf("insert character\n\r"); |
bieleluk | 2:478ba8b83e3f | 48 | * while (!pc.readable()){} |
bieleluk | 0:e36b454cc2e6 | 49 | * character = pc.getc(); |
bieleluk | 0:e36b454cc2e6 | 50 | * pc.printf("you have inserted %c\n\r",character); |
bieleluk | 0:e36b454cc2e6 | 51 | * var++; |
bieleluk | 1:dbb9fcc20d07 | 52 | * pc.breakpoint(__LINE__, 0x48000000); |
bieleluk | 0:e36b454cc2e6 | 53 | * wait(1); |
bieleluk | 0:e36b454cc2e6 | 54 | * } |
bieleluk | 0:e36b454cc2e6 | 55 | * } |
bieleluk | 0:e36b454cc2e6 | 56 | * @endcode |
bieleluk | 0:e36b454cc2e6 | 57 | */ |
bieleluk | 0:e36b454cc2e6 | 58 | class Debug_serial { |
bieleluk | 0:e36b454cc2e6 | 59 | public: |
bieleluk | 0:e36b454cc2e6 | 60 | |
bieleluk | 12:a8ab6e018422 | 61 | /** Create object of Debug_serial class |
bieleluk | 12:a8ab6e018422 | 62 | * @param tx_pin TX pin of debug serial port |
bieleluk | 12:a8ab6e018422 | 63 | * @param rx_pin RX pin of debug serial port |
bieleluk | 12:a8ab6e018422 | 64 | * @param baudrate(optional) desired baudrate value of debug serial port, default baudrate is 115200 Bd/s |
bieleluk | 0:e36b454cc2e6 | 65 | */ |
bieleluk | 0:e36b454cc2e6 | 66 | Debug_serial(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 0:e36b454cc2e6 | 67 | |
bieleluk | 0:e36b454cc2e6 | 68 | /** Perform one breakpoint without printing variable |
bieleluk | 12:a8ab6e018422 | 69 | * @param line_number(optional) line number of breakpoint,macro __LINE__ is recommended |
bieleluk | 0:e36b454cc2e6 | 70 | */ |
bieleluk | 0:e36b454cc2e6 | 71 | void breakpoint(int line_number = -1); |
bieleluk | 0:e36b454cc2e6 | 72 | |
bieleluk | 0:e36b454cc2e6 | 73 | /** Perform one breakpoint and print variable of type int |
bieleluk | 12:a8ab6e018422 | 74 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 75 | * @param name name of printed variable(max length is 19) , macro name(variable) is recommended |
bieleluk | 12:a8ab6e018422 | 76 | * @param variable variable of type int |
bieleluk | 0:e36b454cc2e6 | 77 | */ |
bieleluk | 0:e36b454cc2e6 | 78 | void breakpoint(int line_number, char name[20], int variable); |
bieleluk | 0:e36b454cc2e6 | 79 | |
bieleluk | 0:e36b454cc2e6 | 80 | /** Perform one breakpoint and print variable of type char |
bieleluk | 12:a8ab6e018422 | 81 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 82 | * @param name name of printed variable(max length is 19) , macro name(variable) is recommended |
bieleluk | 12:a8ab6e018422 | 83 | * @param variable variable of type int |
bieleluk | 0:e36b454cc2e6 | 84 | */ |
bieleluk | 0:e36b454cc2e6 | 85 | void breakpoint(int line_number, char name[20], char variable); |
bieleluk | 0:e36b454cc2e6 | 86 | |
bieleluk | 12:a8ab6e018422 | 87 | /** Perform one breakpoint and print string variable |
bieleluk | 12:a8ab6e018422 | 88 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 89 | * @param name name of printed variable(max length is 19) , macro name(variable) is recommended |
bieleluk | 12:a8ab6e018422 | 90 | * @param variable variable of type char* |
bieleluk | 0:e36b454cc2e6 | 91 | */ |
bieleluk | 0:e36b454cc2e6 | 92 | void breakpoint(int line_number, char name[20], char * variable); |
bieleluk | 0:e36b454cc2e6 | 93 | |
bieleluk | 0:e36b454cc2e6 | 94 | /** Perform one breakpoint and print variable of type float |
bieleluk | 12:a8ab6e018422 | 95 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 96 | * @param name name of printed variable(max length is 19) , macro name(variable) is recommended |
bieleluk | 12:a8ab6e018422 | 97 | * @param variable variable of type float |
bieleluk | 0:e36b454cc2e6 | 98 | */ |
bieleluk | 0:e36b454cc2e6 | 99 | void breakpoint(int line_number, char name[20], float variable); |
bieleluk | 0:e36b454cc2e6 | 100 | |
bieleluk | 1:dbb9fcc20d07 | 101 | /** Perform one breakpoint and print one register value |
bieleluk | 12:a8ab6e018422 | 102 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 103 | * @param address address of register, must be divisible by 4 |
bieleluk | 1:dbb9fcc20d07 | 104 | */ |
bieleluk | 6:1ee26b7b9c2f | 105 | void breakpoint(int line_number, uint32_t address); |
bieleluk | 1:dbb9fcc20d07 | 106 | |
bieleluk | 0:e36b454cc2e6 | 107 | /** Print formatted string to debug serial port |
bieleluk | 0:e36b454cc2e6 | 108 | * @returns total number of printed characters or negative value if an output error or an encoding error |
bieleluk | 0:e36b454cc2e6 | 109 | */ |
bieleluk | 0:e36b454cc2e6 | 110 | int printf(const char* format, ...); |
bieleluk | 12:a8ab6e018422 | 111 | |
bieleluk | 12:a8ab6e018422 | 112 | /** Read formatted string from debug serial port |
bieleluk | 12:a8ab6e018422 | 113 | * @returns total number of successfully read arguments or negative value if en error occured |
bieleluk | 12:a8ab6e018422 | 114 | */ |
bieleluk | 12:a8ab6e018422 | 115 | int scanf(const char* format, ...); |
bieleluk | 0:e36b454cc2e6 | 116 | |
bieleluk | 0:e36b454cc2e6 | 117 | /** Print one character to debug serial port |
bieleluk | 0:e36b454cc2e6 | 118 | * @param character |
bieleluk | 0:e36b454cc2e6 | 119 | * @returns character written as an unsigned char cast to an int |
bieleluk | 0:e36b454cc2e6 | 120 | */ |
bieleluk | 0:e36b454cc2e6 | 121 | int putc(int character); |
bieleluk | 0:e36b454cc2e6 | 122 | |
bieleluk | 0:e36b454cc2e6 | 123 | /** Read one character from debug serial port |
bieleluk | 0:e36b454cc2e6 | 124 | * @returns character written as an unsigned char cast to an int |
bieleluk | 0:e36b454cc2e6 | 125 | */ |
bieleluk | 0:e36b454cc2e6 | 126 | int getc(); |
bieleluk | 2:478ba8b83e3f | 127 | |
bieleluk | 12:a8ab6e018422 | 128 | /** Check whether there is some character available to read from debug serial port. |
bieleluk | 12:a8ab6e018422 | 129 | * @returns true when there is something available to read |
bieleluk | 12:a8ab6e018422 | 130 | */ |
bieleluk | 2:478ba8b83e3f | 131 | bool readable(); |
bieleluk | 12:a8ab6e018422 | 132 | |
bieleluk | 12:a8ab6e018422 | 133 | /** Check whether it is possible to write a character to debug serial port. |
bieleluk | 12:a8ab6e018422 | 134 | * @returns true when it is possible to write a character to debug serial port |
bieleluk | 12:a8ab6e018422 | 135 | */ |
bieleluk | 2:478ba8b83e3f | 136 | bool writable(); |
bieleluk | 2:478ba8b83e3f | 137 | |
bieleluk | 0:e36b454cc2e6 | 138 | private: |
bieleluk | 0:e36b454cc2e6 | 139 | int break_line[3]; //store number of lines of three previous breakpoints |
bieleluk | 0:e36b454cc2e6 | 140 | char var[3][50]; //store variables of three previous breakpoints |
bieleluk | 0:e36b454cc2e6 | 141 | |
bieleluk | 0:e36b454cc2e6 | 142 | protected: |
bieleluk | 0:e36b454cc2e6 | 143 | // objects: |
bieleluk | 12:a8ab6e018422 | 144 | Serial pc; //debug serial port |
bieleluk | 12:a8ab6e018422 | 145 | // variables |
bieleluk | 0:e36b454cc2e6 | 146 | int breakpoint_count; //stores number of the current breakpoint |
bieleluk | 0:e36b454cc2e6 | 147 | // functions |
bieleluk | 0:e36b454cc2e6 | 148 | // initialization function |
bieleluk | 0:e36b454cc2e6 | 149 | void init(); |
bieleluk | 0:e36b454cc2e6 | 150 | // print 3 last breakpoints |
bieleluk | 0:e36b454cc2e6 | 151 | void print_3_breaks(int line_number); |
bieleluk | 0:e36b454cc2e6 | 152 | // print one breakpoint |
bieleluk | 0:e36b454cc2e6 | 153 | void print_one_break(int n); |
bieleluk | 0:e36b454cc2e6 | 154 | // clear screen from m line up to n line |
bieleluk | 0:e36b454cc2e6 | 155 | void clear_from_n_up_to_m(int m, int n); |
bieleluk | 0:e36b454cc2e6 | 156 | }; |
bieleluk | 0:e36b454cc2e6 | 157 | |
bieleluk | 12:a8ab6e018422 | 158 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 159 | |
bieleluk | 0:e36b454cc2e6 | 160 | /** Debug_led class. |
bieleluk | 0:e36b454cc2e6 | 161 | * Class for stepping the program with debug LED and button, that is connected to GND(default) or VCC. |
bieleluk | 0:e36b454cc2e6 | 162 | * |
bieleluk | 0:e36b454cc2e6 | 163 | * Example program: |
bieleluk | 0:e36b454cc2e6 | 164 | * @code |
bieleluk | 0:e36b454cc2e6 | 165 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 166 | * // Author: Lukas Bielesch |
bieleluk | 0:e36b454cc2e6 | 167 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 12:a8ab6e018422 | 168 | * // Date of publication: 13. May 2019 |
bieleluk | 0:e36b454cc2e6 | 169 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 170 | * #include "Debug.h" |
bieleluk | 8:a5570452154e | 171 | * AnalogIn analog(PA_0); |
bieleluk | 0:e36b454cc2e6 | 172 | * PwmOut pwm(PA_4); |
bieleluk | 8:a5570452154e | 173 | * DigitalOut out(PA_1); |
bieleluk | 0:e36b454cc2e6 | 174 | * Debug_led deb(PA_5, PA_6, "BUTTON_VDD"); //debug led on PA5, debug button connected to VDD on PA6 |
bieleluk | 0:e36b454cc2e6 | 175 | * int main(){ |
bieleluk | 0:e36b454cc2e6 | 176 | * |
bieleluk | 0:e36b454cc2e6 | 177 | * out = 1; |
bieleluk | 0:e36b454cc2e6 | 178 | * deb.breakpoint(1); |
bieleluk | 0:e36b454cc2e6 | 179 | * pwm = 0.5; |
bieleluk | 0:e36b454cc2e6 | 180 | * pwm.period(1); |
bieleluk | 0:e36b454cc2e6 | 181 | * deb.breakpoint(2); |
bieleluk | 0:e36b454cc2e6 | 182 | * |
bieleluk | 0:e36b454cc2e6 | 183 | * while(1){ |
bieleluk | 0:e36b454cc2e6 | 184 | * deb.breakpoint(); |
bieleluk | 17:5b0dd2a6b130 | 185 | * pwm = pwm + 0.1f; |
bieleluk | 0:e36b454cc2e6 | 186 | * wait(2); |
bieleluk | 0:e36b454cc2e6 | 187 | * } |
bieleluk | 0:e36b454cc2e6 | 188 | * } |
bieleluk | 0:e36b454cc2e6 | 189 | * @endcode |
bieleluk | 0:e36b454cc2e6 | 190 | */ |
bieleluk | 0:e36b454cc2e6 | 191 | // class Debug_led |
bieleluk | 0:e36b454cc2e6 | 192 | class Debug_led { |
bieleluk | 0:e36b454cc2e6 | 193 | public: |
bieleluk | 0:e36b454cc2e6 | 194 | |
bieleluk | 0:e36b454cc2e6 | 195 | /** Create object of class Debug_led |
bieleluk | 0:e36b454cc2e6 | 196 | * @param led_pin pin of of debug led |
bieleluk | 0:e36b454cc2e6 | 197 | * @param button_pin pin of of debug button |
bieleluk | 0:e36b454cc2e6 | 198 | * @param mode mode of button connection("BUTTON_GND", "BUTTON_VCC", "BUTTON_VDD") |
bieleluk | 0:e36b454cc2e6 | 199 | */ |
bieleluk | 0:e36b454cc2e6 | 200 | Debug_led(PinName led_pin, PinName button_pin, char mode[11] = "BUTTON_GND"); |
bieleluk | 0:e36b454cc2e6 | 201 | |
bieleluk | 0:e36b454cc2e6 | 202 | /** Perform one breakpoint |
bieleluk | 12:a8ab6e018422 | 203 | * @param number(optional) number of flashes of periodic flashing of LED during the breakpoint, default is constant flashing |
bieleluk | 0:e36b454cc2e6 | 204 | */ |
bieleluk | 0:e36b454cc2e6 | 205 | void breakpoint(int number = -1); |
bieleluk | 0:e36b454cc2e6 | 206 | |
bieleluk | 0:e36b454cc2e6 | 207 | private: |
bieleluk | 0:e36b454cc2e6 | 208 | // objects |
bieleluk | 0:e36b454cc2e6 | 209 | DigitalOut led; //debug led |
bieleluk | 0:e36b454cc2e6 | 210 | InterruptIn button; //debug button |
bieleluk | 0:e36b454cc2e6 | 211 | // variables |
bieleluk | 0:e36b454cc2e6 | 212 | int button_mode; //mode of button 1->pullupt, 0->pulldown |
bieleluk | 12:a8ab6e018422 | 213 | volatile bool end_breakpoint; //true when button was pushed |
bieleluk | 12:a8ab6e018422 | 214 | int number_of_breakpoints; //number of the current breakpoint |
bieleluk | 0:e36b454cc2e6 | 215 | |
bieleluk | 0:e36b454cc2e6 | 216 | /** Initialization */ |
bieleluk | 0:e36b454cc2e6 | 217 | void init(char mode[11]); |
bieleluk | 0:e36b454cc2e6 | 218 | |
bieleluk | 12:a8ab6e018422 | 219 | /** Blink the debug led n-times with blink period wait_time_ms */ |
bieleluk | 0:e36b454cc2e6 | 220 | void flash_n_times(int wait_time_ms, int n); |
bieleluk | 0:e36b454cc2e6 | 221 | |
bieleluk | 12:a8ab6e018422 | 222 | /** IRQ function, end breakpoint after the button is pushed */ |
bieleluk | 0:e36b454cc2e6 | 223 | void end_break(); |
bieleluk | 0:e36b454cc2e6 | 224 | }; |
bieleluk | 0:e36b454cc2e6 | 225 | |
bieleluk | 12:a8ab6e018422 | 226 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 227 | /** Debug_register class. |
bieleluk | 0:e36b454cc2e6 | 228 | * |
bieleluk | 0:e36b454cc2e6 | 229 | * Example program: |
bieleluk | 0:e36b454cc2e6 | 230 | * @code |
bieleluk | 0:e36b454cc2e6 | 231 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 232 | * // Author: Lukas Bielesch |
bieleluk | 0:e36b454cc2e6 | 233 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 0:e36b454cc2e6 | 234 | * // Date of publication: 15. Apr 2019 |
bieleluk | 0:e36b454cc2e6 | 235 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 236 | * #include "Debug.h" |
bieleluk | 9:59344a584e18 | 237 | * AnalogIn analog(PA_4); |
bieleluk | 0:e36b454cc2e6 | 238 | * PwmOut pwm(PA_6); |
bieleluk | 9:59344a584e18 | 239 | * DigitalOut out(PA_5); |
bieleluk | 0:e36b454cc2e6 | 240 | * Debug_register pc(PA_2, PA_3, 115200); |
bieleluk | 0:e36b454cc2e6 | 241 | * |
bieleluk | 0:e36b454cc2e6 | 242 | * int main(){ |
bieleluk | 0:e36b454cc2e6 | 243 | * pc.breakpoint(__LINE__,0x48000000); |
bieleluk | 0:e36b454cc2e6 | 244 | * DigitalOut out2 (PA_0); |
bieleluk | 10:4d5f38d996e2 | 245 | * pc.breakpoint(__LINE__,0x48000001); |
bieleluk | 0:e36b454cc2e6 | 246 | * AnalogIn analog2 (PA_1); |
bieleluk | 6:1ee26b7b9c2f | 247 | * pc.breakpoint(__LINE__,0x4800000C); |
bieleluk | 5:e2e16ef72833 | 248 | * DigitalIn di1(PA_7, PullUp); |
bieleluk | 6:1ee26b7b9c2f | 249 | * pc.breakpoint(__LINE__,0x4800000C); |
bieleluk | 6:1ee26b7b9c2f | 250 | * pc.breakpoint(__LINE__,0x48000004); |
bieleluk | 0:e36b454cc2e6 | 251 | * while(1){ |
bieleluk | 0:e36b454cc2e6 | 252 | * if(pc.readable()){ |
bieleluk | 0:e36b454cc2e6 | 253 | * pc.putc(pc.getc()); |
bieleluk | 0:e36b454cc2e6 | 254 | * } |
bieleluk | 0:e36b454cc2e6 | 255 | * wait(0.1); |
bieleluk | 0:e36b454cc2e6 | 256 | * } |
bieleluk | 0:e36b454cc2e6 | 257 | * } |
bieleluk | 0:e36b454cc2e6 | 258 | * @endcode |
bieleluk | 0:e36b454cc2e6 | 259 | */ |
bieleluk | 0:e36b454cc2e6 | 260 | class Debug_register { |
bieleluk | 0:e36b454cc2e6 | 261 | public: |
bieleluk | 0:e36b454cc2e6 | 262 | |
bieleluk | 12:a8ab6e018422 | 263 | /** Create object of Debug_register class |
bieleluk | 12:a8ab6e018422 | 264 | * @param tx_pin TX pin of debug serial port |
bieleluk | 12:a8ab6e018422 | 265 | * @param rx_pin RX pin of debug serial port |
bieleluk | 12:a8ab6e018422 | 266 | * @param baudrate(optional) desired baudrate value of debug serial port, default baudrate is 115200 Bd/s |
bieleluk | 0:e36b454cc2e6 | 267 | */ |
bieleluk | 0:e36b454cc2e6 | 268 | Debug_register(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 0:e36b454cc2e6 | 269 | |
bieleluk | 0:e36b454cc2e6 | 270 | /** Perform one breakpoint and print one register |
bieleluk | 12:a8ab6e018422 | 271 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 272 | * @param address address of register, must be divisible by 4 |
bieleluk | 0:e36b454cc2e6 | 273 | */ |
bieleluk | 12:a8ab6e018422 | 274 | void breakpoint(int line_number, uint32_t address); |
bieleluk | 0:e36b454cc2e6 | 275 | |
bieleluk | 0:e36b454cc2e6 | 276 | /** Print formatted string to debug serial port |
bieleluk | 0:e36b454cc2e6 | 277 | * @returns total number of printed characters or negative value if an output error or an encoding error |
bieleluk | 0:e36b454cc2e6 | 278 | */ |
bieleluk | 0:e36b454cc2e6 | 279 | int printf(const char* format, ...); |
bieleluk | 12:a8ab6e018422 | 280 | |
bieleluk | 12:a8ab6e018422 | 281 | /** Read formatted string from debug serial port |
bieleluk | 12:a8ab6e018422 | 282 | * @returns total number of successfully read arguments or negative value if en error occured |
bieleluk | 12:a8ab6e018422 | 283 | */ |
bieleluk | 12:a8ab6e018422 | 284 | int scanf(const char* format, ...); |
bieleluk | 0:e36b454cc2e6 | 285 | |
bieleluk | 0:e36b454cc2e6 | 286 | /** Print one character to debug serial port |
bieleluk | 0:e36b454cc2e6 | 287 | * @param character |
bieleluk | 0:e36b454cc2e6 | 288 | * @returns character written as an unsigned char cast to an int |
bieleluk | 0:e36b454cc2e6 | 289 | */ |
bieleluk | 0:e36b454cc2e6 | 290 | int putc(int character); |
bieleluk | 0:e36b454cc2e6 | 291 | |
bieleluk | 0:e36b454cc2e6 | 292 | /** Read one character from debug serial port |
bieleluk | 0:e36b454cc2e6 | 293 | * @returns character written as an unsigned char cast to an int |
bieleluk | 0:e36b454cc2e6 | 294 | */ |
bieleluk | 0:e36b454cc2e6 | 295 | int getc(); |
bieleluk | 0:e36b454cc2e6 | 296 | |
bieleluk | 12:a8ab6e018422 | 297 | /** Check whether there is some character available to read from debug serial port. |
bieleluk | 12:a8ab6e018422 | 298 | * @returns true when there is something available to read |
bieleluk | 12:a8ab6e018422 | 299 | */ |
bieleluk | 0:e36b454cc2e6 | 300 | bool readable(); |
bieleluk | 12:a8ab6e018422 | 301 | |
bieleluk | 12:a8ab6e018422 | 302 | /** Check whether it is possible to write a character to debug serial port. |
bieleluk | 12:a8ab6e018422 | 303 | * @returns true when it is possible to write a character to debug serial port |
bieleluk | 12:a8ab6e018422 | 304 | */ |
bieleluk | 2:478ba8b83e3f | 305 | bool writable(); |
bieleluk | 0:e36b454cc2e6 | 306 | |
bieleluk | 0:e36b454cc2e6 | 307 | protected: |
bieleluk | 0:e36b454cc2e6 | 308 | // objects: |
bieleluk | 0:e36b454cc2e6 | 309 | Serial pc; //debug serial device |
bieleluk | 0:e36b454cc2e6 | 310 | // variables: |
bieleluk | 12:a8ab6e018422 | 311 | int breakpoint_count; //number of the current breakpoint |
bieleluk | 0:e36b454cc2e6 | 312 | // functions |
bieleluk | 0:e36b454cc2e6 | 313 | // initialization function |
bieleluk | 0:e36b454cc2e6 | 314 | void init(); |
bieleluk | 0:e36b454cc2e6 | 315 | // clear screen from m line up to n line |
bieleluk | 0:e36b454cc2e6 | 316 | void clear_from_n_up_to_m(int m, int n); |
bieleluk | 15:83d4dced2a28 | 317 | // modify actual address or register value according to position in terminal |
bieleluk | 3:3d7837ae4a37 | 318 | uint32_t modify_value(uint32_t value, int horizontal); |
bieleluk | 15:83d4dced2a28 | 319 | // print address and register value |
bieleluk | 15:83d4dced2a28 | 320 | void print_break(uint32_t address); |
bieleluk | 15:83d4dced2a28 | 321 | // print number in binary form |
bieleluk | 15:83d4dced2a28 | 322 | void print_binary(uint32_t value); |
bieleluk | 0:e36b454cc2e6 | 323 | }; |
bieleluk | 3:3d7837ae4a37 | 324 | |
bieleluk | 12:a8ab6e018422 | 325 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 326 | /** Debug_register_print class. |
bieleluk | 0:e36b454cc2e6 | 327 | * |
bieleluk | 0:e36b454cc2e6 | 328 | * Example program: |
bieleluk | 0:e36b454cc2e6 | 329 | * @code |
bieleluk | 0:e36b454cc2e6 | 330 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 331 | * // Author: Lukas Bielesch |
bieleluk | 0:e36b454cc2e6 | 332 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 0:e36b454cc2e6 | 333 | * // Date of publication: 15. Apr 2019 |
bieleluk | 0:e36b454cc2e6 | 334 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 335 | * #include "Debug.h" |
bieleluk | 9:59344a584e18 | 336 | * AnalogIn analog(PA_4); |
bieleluk | 0:e36b454cc2e6 | 337 | * PwmOut pwm(PA_6); |
bieleluk | 9:59344a584e18 | 338 | * DigitalOut out(PA_5); |
bieleluk | 0:e36b454cc2e6 | 339 | * Debug_register_print pc(PA_2, PA_3, 115200); |
bieleluk | 0:e36b454cc2e6 | 340 | * |
bieleluk | 0:e36b454cc2e6 | 341 | * int main(){ |
bieleluk | 0:e36b454cc2e6 | 342 | * pc.format(2,2,1,3);//breakpoint count,line number, address, value |
bieleluk | 10:4d5f38d996e2 | 343 | * pc.breakpoint(__LINE__,0x48000001, 2); |
bieleluk | 0:e36b454cc2e6 | 344 | * DigitalOut out2 (PA_0); |
bieleluk | 6:1ee26b7b9c2f | 345 | * pc.breakpoint(__LINE__,0x48000014, -3); |
bieleluk | 0:e36b454cc2e6 | 346 | * AnalogIn analog2 (PA_1); |
bieleluk | 6:1ee26b7b9c2f | 347 | * pc.breakpoint(__LINE__,0x48000008); |
bieleluk | 0:e36b454cc2e6 | 348 | * |
bieleluk | 0:e36b454cc2e6 | 349 | * while(1){ |
bieleluk | 0:e36b454cc2e6 | 350 | * wait(1); |
bieleluk | 0:e36b454cc2e6 | 351 | * } |
bieleluk | 0:e36b454cc2e6 | 352 | * } |
bieleluk | 0:e36b454cc2e6 | 353 | * @endcode |
bieleluk | 0:e36b454cc2e6 | 354 | */ |
bieleluk | 0:e36b454cc2e6 | 355 | class Debug_register_print { |
bieleluk | 0:e36b454cc2e6 | 356 | public: |
bieleluk | 0:e36b454cc2e6 | 357 | |
bieleluk | 12:a8ab6e018422 | 358 | /** Create object of Debug_register_print class |
bieleluk | 12:a8ab6e018422 | 359 | * @param tx_pin TX pin of debug serial port |
bieleluk | 12:a8ab6e018422 | 360 | * @param rx_pin RX pin of debug serial port |
bieleluk | 12:a8ab6e018422 | 361 | * @param baudrate(optional) desired baudrate value of debug serial port, default baudrate is 115200 Bd/s |
bieleluk | 0:e36b454cc2e6 | 362 | */ |
bieleluk | 0:e36b454cc2e6 | 363 | Debug_register_print(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 0:e36b454cc2e6 | 364 | |
bieleluk | 12:a8ab6e018422 | 365 | /** Set format of breakpoint message |
bieleluk | 12:a8ab6e018422 | 366 | * @param break_number format of number of actual breakpoint: 0->not show, 1->show in hexadecimal, 2->show in decimal(default) |
bieleluk | 12:a8ab6e018422 | 367 | * @param line format of line of actual breakpoint: 0->not show, 1->show in hexadecimal, 2->show in decimal(default) |
bieleluk | 12:a8ab6e018422 | 368 | * @param address format of address of register: 0->not show, 1->show in hexadecimal(default), 2->show in decimal |
bieleluk | 12:a8ab6e018422 | 369 | * @param value format of register value: 0->not show, 1->show in hexadecimal, 2->show in decimal, 3->show in binary(default) |
bieleluk | 12:a8ab6e018422 | 370 | */ |
bieleluk | 12:a8ab6e018422 | 371 | void format(int break_number = 2, int line = 2, int address = 1, int value = 3); |
bieleluk | 0:e36b454cc2e6 | 372 | |
bieleluk | 12:a8ab6e018422 | 373 | /** Perform one breakpoint and print one register value |
bieleluk | 12:a8ab6e018422 | 374 | * @param line_number line number of breakpoint, macro __LINE__ is recommended |
bieleluk | 12:a8ab6e018422 | 375 | * @param address address of register , must be divisible by 4 |
bieleluk | 0:e36b454cc2e6 | 376 | */ |
bieleluk | 12:a8ab6e018422 | 377 | void breakpoint(int line_number, uint32_t address, int number_of_words = 1); |
bieleluk | 0:e36b454cc2e6 | 378 | |
bieleluk | 0:e36b454cc2e6 | 379 | |
bieleluk | 0:e36b454cc2e6 | 380 | protected: |
bieleluk | 0:e36b454cc2e6 | 381 | // objects: |
bieleluk | 0:e36b454cc2e6 | 382 | Serial pc; //debug serial device |
bieleluk | 0:e36b454cc2e6 | 383 | // variables: |
bieleluk | 12:a8ab6e018422 | 384 | int breakpoint_count; //number of the current breakpoint |
bieleluk | 12:a8ab6e018422 | 385 | int count_format; // format of breakpoint count, 0->not show, 1->show in hexadecimal, 2->show in decimal |
bieleluk | 12:a8ab6e018422 | 386 | int line_format; // format of lineof breakpoint, 0->not show, 1->show in hexadecimal, 2->show in decimal |
bieleluk | 12:a8ab6e018422 | 387 | int address_format; // format of address of register, 0->not show, 1->show in hexadecimal, 2->show in decimal |
bieleluk | 12:a8ab6e018422 | 388 | int register_format;// format of register value, 0->not show, 1->show in hexadecimal, 2->show in decimal, 3->show in binary |
bieleluk | 0:e36b454cc2e6 | 389 | // functions |
bieleluk | 0:e36b454cc2e6 | 390 | // initialization function |
bieleluk | 0:e36b454cc2e6 | 391 | void init(); |
bieleluk | 0:e36b454cc2e6 | 392 | |
bieleluk | 16:7fc964b6d127 | 393 | }; |
bieleluk | 16:7fc964b6d127 | 394 |