Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.
Debug.h@3:3d7837ae4a37, 2019-05-06 (annotated)
- Committer:
- bieleluk
- Date:
- Mon May 06 21:16:37 2019 +0000
- Revision:
- 3:3d7837ae4a37
- Parent:
- 2:478ba8b83e3f
- Child:
- 4:0e22212d2d7e
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 | * @param offset |
bieleluk | 1:dbb9fcc20d07 | 118 | */ |
bieleluk | 1:dbb9fcc20d07 | 119 | void breakpoint(int line_number, uint32_t address, uint32_t offset = 0); |
bieleluk | 1:dbb9fcc20d07 | 120 | |
bieleluk | 0:e36b454cc2e6 | 121 | /** Print formatted string to debug serial port |
bieleluk | 0:e36b454cc2e6 | 122 | * @param string |
bieleluk | 0:e36b454cc2e6 | 123 | * @param format (optional) |
bieleluk | 0:e36b454cc2e6 | 124 | * @returns total number of printed characters or negative value if an output error or an encoding error |
bieleluk | 0:e36b454cc2e6 | 125 | */ |
bieleluk | 0:e36b454cc2e6 | 126 | int printf(const char* format, ...); |
bieleluk | 0:e36b454cc2e6 | 127 | |
bieleluk | 0:e36b454cc2e6 | 128 | /** Print one character to debug serial port |
bieleluk | 0:e36b454cc2e6 | 129 | * @param character |
bieleluk | 0:e36b454cc2e6 | 130 | * @returns character written as an unsigned char cast to an int |
bieleluk | 0:e36b454cc2e6 | 131 | */ |
bieleluk | 0:e36b454cc2e6 | 132 | int putc(int character); |
bieleluk | 0:e36b454cc2e6 | 133 | |
bieleluk | 0:e36b454cc2e6 | 134 | /** Read one character from debug serial port |
bieleluk | 0:e36b454cc2e6 | 135 | * @returns character written as an unsigned char cast to an int |
bieleluk | 0:e36b454cc2e6 | 136 | */ |
bieleluk | 0:e36b454cc2e6 | 137 | int getc(); |
bieleluk | 2:478ba8b83e3f | 138 | |
bieleluk | 2:478ba8b83e3f | 139 | bool readable(); |
bieleluk | 2:478ba8b83e3f | 140 | bool writable(); |
bieleluk | 2:478ba8b83e3f | 141 | |
bieleluk | 0:e36b454cc2e6 | 142 | private: |
bieleluk | 0:e36b454cc2e6 | 143 | int break_line[3]; //store number of lines of three previous breakpoints |
bieleluk | 0:e36b454cc2e6 | 144 | char var[3][50]; //store variables of three previous breakpoints |
bieleluk | 0:e36b454cc2e6 | 145 | |
bieleluk | 0:e36b454cc2e6 | 146 | protected: |
bieleluk | 0:e36b454cc2e6 | 147 | // objects: |
bieleluk | 0:e36b454cc2e6 | 148 | Serial pc; //debug serial device |
bieleluk | 0:e36b454cc2e6 | 149 | // variables: |
bieleluk | 0:e36b454cc2e6 | 150 | int breakpoint_count; //stores number of the current breakpoint |
bieleluk | 0:e36b454cc2e6 | 151 | // functions |
bieleluk | 0:e36b454cc2e6 | 152 | // initialization function |
bieleluk | 0:e36b454cc2e6 | 153 | void init(); |
bieleluk | 0:e36b454cc2e6 | 154 | // print 3 last breakpoints |
bieleluk | 0:e36b454cc2e6 | 155 | void print_3_breaks(int line_number); |
bieleluk | 0:e36b454cc2e6 | 156 | // print one breakpoint |
bieleluk | 0:e36b454cc2e6 | 157 | void print_one_break(int n); |
bieleluk | 0:e36b454cc2e6 | 158 | // clear screen from m line up to n line |
bieleluk | 0:e36b454cc2e6 | 159 | void clear_from_n_up_to_m(int m, int n); |
bieleluk | 0:e36b454cc2e6 | 160 | }; |
bieleluk | 0:e36b454cc2e6 | 161 | |
bieleluk | 0:e36b454cc2e6 | 162 | |
bieleluk | 0:e36b454cc2e6 | 163 | |
bieleluk | 0:e36b454cc2e6 | 164 | |
bieleluk | 0:e36b454cc2e6 | 165 | /** Debug_led class. |
bieleluk | 0:e36b454cc2e6 | 166 | * Class for stepping the program with debug LED and button, that is connected to GND(default) or VCC. |
bieleluk | 0:e36b454cc2e6 | 167 | * |
bieleluk | 0:e36b454cc2e6 | 168 | * Example program: |
bieleluk | 0:e36b454cc2e6 | 169 | * @code |
bieleluk | 0:e36b454cc2e6 | 170 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 171 | * // Author: Lukas Bielesch |
bieleluk | 0:e36b454cc2e6 | 172 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 0:e36b454cc2e6 | 173 | * // Date of publication: 15. Apr 2019 |
bieleluk | 0:e36b454cc2e6 | 174 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 175 | * #include "Debug.h" |
bieleluk | 0:e36b454cc2e6 | 176 | * AnalogIn analog(PA_3); |
bieleluk | 0:e36b454cc2e6 | 177 | * PwmOut pwm(PA_4); |
bieleluk | 0:e36b454cc2e6 | 178 | * DigitalOut out(PA_2); |
bieleluk | 0:e36b454cc2e6 | 179 | * Debug_led deb(PA_5, PA_6, "BUTTON_VDD"); //debug led on PA5, debug button connected to VDD on PA6 |
bieleluk | 0:e36b454cc2e6 | 180 | * int main(){ |
bieleluk | 0:e36b454cc2e6 | 181 | * |
bieleluk | 0:e36b454cc2e6 | 182 | * out = 1; |
bieleluk | 0:e36b454cc2e6 | 183 | * deb.breakpoint(1); |
bieleluk | 0:e36b454cc2e6 | 184 | * pwm = 0.5; |
bieleluk | 0:e36b454cc2e6 | 185 | * pwm.period(1); |
bieleluk | 0:e36b454cc2e6 | 186 | * deb.breakpoint(2); |
bieleluk | 0:e36b454cc2e6 | 187 | * |
bieleluk | 0:e36b454cc2e6 | 188 | * while(1){ |
bieleluk | 0:e36b454cc2e6 | 189 | * deb.breakpoint(); |
bieleluk | 0:e36b454cc2e6 | 190 | * pwm = pwm + 0.1; |
bieleluk | 0:e36b454cc2e6 | 191 | * wait(2); |
bieleluk | 0:e36b454cc2e6 | 192 | * } |
bieleluk | 0:e36b454cc2e6 | 193 | * } |
bieleluk | 0:e36b454cc2e6 | 194 | * @endcode |
bieleluk | 0:e36b454cc2e6 | 195 | */ |
bieleluk | 0:e36b454cc2e6 | 196 | // class Debug_led |
bieleluk | 0:e36b454cc2e6 | 197 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 198 | class Debug_led { |
bieleluk | 0:e36b454cc2e6 | 199 | public: |
bieleluk | 0:e36b454cc2e6 | 200 | |
bieleluk | 0:e36b454cc2e6 | 201 | /** Create object of class Debug_led |
bieleluk | 0:e36b454cc2e6 | 202 | * @param led_pin pin of of debug led |
bieleluk | 0:e36b454cc2e6 | 203 | * @param button_pin pin of of debug button |
bieleluk | 0:e36b454cc2e6 | 204 | * @param mode mode of button connection("BUTTON_GND", "BUTTON_VCC", "BUTTON_VDD") |
bieleluk | 0:e36b454cc2e6 | 205 | */ |
bieleluk | 0:e36b454cc2e6 | 206 | Debug_led(PinName led_pin, PinName button_pin, char mode[11] = "BUTTON_GND"); |
bieleluk | 0:e36b454cc2e6 | 207 | |
bieleluk | 0:e36b454cc2e6 | 208 | /** Perform one breakpoint |
bieleluk | 0:e36b454cc2e6 | 209 | * @param number number of flashes of LED during the breakpoint(optional) |
bieleluk | 0:e36b454cc2e6 | 210 | */ |
bieleluk | 0:e36b454cc2e6 | 211 | void breakpoint(int number = -1); |
bieleluk | 0:e36b454cc2e6 | 212 | |
bieleluk | 0:e36b454cc2e6 | 213 | private: |
bieleluk | 0:e36b454cc2e6 | 214 | // objects |
bieleluk | 0:e36b454cc2e6 | 215 | DigitalOut led; //debug led |
bieleluk | 0:e36b454cc2e6 | 216 | InterruptIn button; //debug button |
bieleluk | 0:e36b454cc2e6 | 217 | // variables |
bieleluk | 0:e36b454cc2e6 | 218 | int button_mode; //mode of button 1->pullupt, 0->pulldown |
bieleluk | 0:e36b454cc2e6 | 219 | volatile bool end_breakpoint; |
bieleluk | 0:e36b454cc2e6 | 220 | int number_of_breakpoints; |
bieleluk | 0:e36b454cc2e6 | 221 | |
bieleluk | 0:e36b454cc2e6 | 222 | /** Initialization */ |
bieleluk | 0:e36b454cc2e6 | 223 | void init(char mode[11]); |
bieleluk | 0:e36b454cc2e6 | 224 | |
bieleluk | 0:e36b454cc2e6 | 225 | /** Blinks the debug led n-times with blink period wait_time_ms */ |
bieleluk | 0:e36b454cc2e6 | 226 | void flash_n_times(int wait_time_ms, int n); |
bieleluk | 0:e36b454cc2e6 | 227 | |
bieleluk | 0:e36b454cc2e6 | 228 | /** end the break after the button is pushed */ |
bieleluk | 0:e36b454cc2e6 | 229 | void end_break(); |
bieleluk | 0:e36b454cc2e6 | 230 | |
bieleluk | 0:e36b454cc2e6 | 231 | |
bieleluk | 0:e36b454cc2e6 | 232 | }; |
bieleluk | 0:e36b454cc2e6 | 233 | |
bieleluk | 0:e36b454cc2e6 | 234 | |
bieleluk | 0:e36b454cc2e6 | 235 | /** Debug_register class. |
bieleluk | 0:e36b454cc2e6 | 236 | * |
bieleluk | 0:e36b454cc2e6 | 237 | * Example program: |
bieleluk | 0:e36b454cc2e6 | 238 | * @code |
bieleluk | 0:e36b454cc2e6 | 239 | * //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 240 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 241 | * // Author: Lukas Bielesch |
bieleluk | 0:e36b454cc2e6 | 242 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 0:e36b454cc2e6 | 243 | * // Date of publication: 15. Apr 2019 |
bieleluk | 0:e36b454cc2e6 | 244 | * // ---------------------------------------------------------------------------- |
bieleluk | 0:e36b454cc2e6 | 245 | * #include "Debug.h" |
bieleluk | 0:e36b454cc2e6 | 246 | * AnalogIn analog(PA_5); |
bieleluk | 0:e36b454cc2e6 | 247 | * PwmOut pwm(PA_6); |
bieleluk | 0:e36b454cc2e6 | 248 | * DigitalOut out(PA_4); |
bieleluk | 0:e36b454cc2e6 | 249 | * Debug_register pc(PA_2, PA_3, 115200); |
bieleluk | 0:e36b454cc2e6 | 250 | * |
bieleluk | 0:e36b454cc2e6 | 251 | * int main(){ |
bieleluk | 0:e36b454cc2e6 | 252 | * pc.breakpoint(__LINE__,0x48000000); |
bieleluk | 0:e36b454cc2e6 | 253 | * DigitalOut out2 (PA_0); |
bieleluk | 0:e36b454cc2e6 | 254 | * pc.breakpoint(__LINE__,0x48000000); |
bieleluk | 0:e36b454cc2e6 | 255 | * AnalogIn analog2 (PA_1); |
bieleluk | 0:e36b454cc2e6 | 256 | * pc.breakpoint(__LINE__,0x48000000); |
bieleluk | 0:e36b454cc2e6 | 257 | * |
bieleluk | 0:e36b454cc2e6 | 258 | * while(1){ |
bieleluk | 0:e36b454cc2e6 | 259 | * if(pc.readable()){ |
bieleluk | 0:e36b454cc2e6 | 260 | * pc.putc(pc.getc()); |
bieleluk | 0:e36b454cc2e6 | 261 | * } |
bieleluk | 0:e36b454cc2e6 | 262 | * wait(0.1); |
bieleluk | 0:e36b454cc2e6 | 263 | * } |
bieleluk | 0:e36b454cc2e6 | 264 | * } |
bieleluk | 0:e36b454cc2e6 | 265 | * @endcode |
bieleluk | 0:e36b454cc2e6 | 266 | */ |
bieleluk | 0:e36b454cc2e6 | 267 | class Debug_register { |
bieleluk | 0:e36b454cc2e6 | 268 | public: |
bieleluk | 0:e36b454cc2e6 | 269 | |
bieleluk | 0:e36b454cc2e6 | 270 | /** Create object of class Debug_serial |
bieleluk | 0:e36b454cc2e6 | 271 | * @param tx_pin TX pin of serial port of the board |
bieleluk | 0:e36b454cc2e6 | 272 | * @param rx_pin RX pin of serial port of the board |
bieleluk | 0:e36b454cc2e6 | 273 | * @param baudrate desired baudrate value of debug serial port |
bieleluk | 0:e36b454cc2e6 | 274 | */ |
bieleluk | 0:e36b454cc2e6 | 275 | Debug_register(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 0:e36b454cc2e6 | 276 | |
bieleluk | 0:e36b454cc2e6 | 277 | /** Perform one breakpoint and print one register |
bieleluk | 0:e36b454cc2e6 | 278 | * @param line_number line number of the breakpoint |
bieleluk | 0:e36b454cc2e6 | 279 | * @param address |
bieleluk | 0:e36b454cc2e6 | 280 | * @param offset |
bieleluk | 0:e36b454cc2e6 | 281 | */ |
bieleluk | 0:e36b454cc2e6 | 282 | void breakpoint(int line_number = -1, uint32_t address = 0, uint32_t offset = 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 | 3:3d7837ae4a37 | 342 | * pc.breakpoint(__LINE__,0x48000000, 0, 2); |
bieleluk | 0:e36b454cc2e6 | 343 | * DigitalOut out2 (PA_0); |
bieleluk | 3:3d7837ae4a37 | 344 | * pc.breakpoint(__LINE__,0x48000000, 0x14, -3); |
bieleluk | 0:e36b454cc2e6 | 345 | * AnalogIn analog2 (PA_1); |
bieleluk | 3:3d7837ae4a37 | 346 | * pc.breakpoint(__LINE__,0x48000000, 0x8); |
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 | 3:3d7837ae4a37 | 372 | void breakpoint(int line_number = -1, uint32_t address = 0, uint32_t offset = 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 | }; |