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