debug tool for STM32F042F6P6
Debug.h@14:5a3b0cabbcd4, 2019-04-18 (annotated)
- Committer:
- bieleluk
- Date:
- Thu Apr 18 10:23:17 2019 +0000
- Revision:
- 14:5a3b0cabbcd4
- Parent:
- 13:3d959f23fd8f
- Child:
- 15:a9db6d4c2a8f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bieleluk | 12:5e618e97cb24 | 1 | #pragma once |
bieleluk | 12:5e618e97cb24 | 2 | |
bieleluk | 12:5e618e97cb24 | 3 | // include files |
bieleluk | 12:5e618e97cb24 | 4 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 5 | #include "mbed.h" |
bieleluk | 12:5e618e97cb24 | 6 | |
bieleluk | 12:5e618e97cb24 | 7 | // macros |
bieleluk | 12:5e618e97cb24 | 8 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 9 | #define name(var) #var |
bieleluk | 12:5e618e97cb24 | 10 | |
bieleluk | 12:5e618e97cb24 | 11 | |
bieleluk | 12:5e618e97cb24 | 12 | // assembly functions |
bieleluk | 12:5e618e97cb24 | 13 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 14 | extern "C" int check_1_bit(uint32_t gpiox, uint32_t offset, uint32_t pin); |
bieleluk | 12:5e618e97cb24 | 15 | extern "C" int check_2_bit(uint32_t gpiox, uint32_t offset, uint32_t pin); |
bieleluk | 12:5e618e97cb24 | 16 | extern "C" int check_alternative_mode(uint32_t gpiox, uint32_t offset, uint32_t pin); |
bieleluk | 12:5e618e97cb24 | 17 | extern "C" int read_word(uint32_t address, uint32_t offset); |
bieleluk | 12:5e618e97cb24 | 18 | |
bieleluk | 12:5e618e97cb24 | 19 | // structs |
bieleluk | 12:5e618e97cb24 | 20 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 21 | typedef struct Pin { |
bieleluk | 12:5e618e97cb24 | 22 | char port; |
bieleluk | 12:5e618e97cb24 | 23 | int number; |
bieleluk | 12:5e618e97cb24 | 24 | } pin_t; |
bieleluk | 12:5e618e97cb24 | 25 | |
bieleluk | 12:5e618e97cb24 | 26 | |
bieleluk | 12:5e618e97cb24 | 27 | /** Debug_complete class. |
bieleluk | 12:5e618e97cb24 | 28 | * Used for printing complete configuration of peripherals |
bieleluk | 12:5e618e97cb24 | 29 | * |
bieleluk | 12:5e618e97cb24 | 30 | * Example: |
bieleluk | 12:5e618e97cb24 | 31 | * @code |
bieleluk | 12:5e618e97cb24 | 32 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 33 | * // "THE BEER-WARE LICENSE" (Revision 42): |
bieleluk | 12:5e618e97cb24 | 34 | * // <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you |
bieleluk | 12:5e618e97cb24 | 35 | * // can do whatever you want with this stuff. If we meet some day, and you think |
bieleluk | 12:5e618e97cb24 | 36 | * // this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp |
bieleluk | 12:5e618e97cb24 | 37 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 38 | * // Author: Lukas Bielesch |
bieleluk | 12:5e618e97cb24 | 39 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 12:5e618e97cb24 | 40 | * // Date of publication: 15. Apr 2019 |
bieleluk | 12:5e618e97cb24 | 41 | * // ---------------------------------------------------------------------------- |
bieleluk | 14:5a3b0cabbcd4 | 42 | * #include "Debug.h" |
bieleluk | 12:5e618e97cb24 | 43 | * AnalogIn analog(PA_5); |
bieleluk | 12:5e618e97cb24 | 44 | * PwmOut pwm(PA_6); |
bieleluk | 12:5e618e97cb24 | 45 | * DigitalOut out(PA_4); |
bieleluk | 12:5e618e97cb24 | 46 | * Debug_complete pc(PA_2, PA_3, 115200); |
bieleluk | 12:5e618e97cb24 | 47 | * |
bieleluk | 12:5e618e97cb24 | 48 | * int main(){ |
bieleluk | 12:5e618e97cb24 | 49 | * out = 1; |
bieleluk | 12:5e618e97cb24 | 50 | * pc.breakpoint(__LINE__); |
bieleluk | 12:5e618e97cb24 | 51 | * pwm = 0.5; |
bieleluk | 12:5e618e97cb24 | 52 | * pwm.period(1); |
bieleluk | 12:5e618e97cb24 | 53 | * while(1){ |
bieleluk | 12:5e618e97cb24 | 54 | * pc.breakpoint(__LINE__); |
bieleluk | 12:5e618e97cb24 | 55 | * wait(1); |
bieleluk | 12:5e618e97cb24 | 56 | * pc.breakpoint(); |
bieleluk | 12:5e618e97cb24 | 57 | * pc.printf("value of adc is %f*VDD\n\r",analog.read()); |
bieleluk | 13:3d959f23fd8f | 58 | * pc.print_reg(0x48000000,0x0); |
bieleluk | 12:5e618e97cb24 | 59 | * } |
bieleluk | 12:5e618e97cb24 | 60 | * } |
bieleluk | 12:5e618e97cb24 | 61 | * @endcode |
bieleluk | 12:5e618e97cb24 | 62 | */ |
bieleluk | 12:5e618e97cb24 | 63 | class Debug_complete { |
bieleluk | 12:5e618e97cb24 | 64 | public: |
bieleluk | 12:5e618e97cb24 | 65 | |
bieleluk | 12:5e618e97cb24 | 66 | /** Create object of class Debug_complete |
bieleluk | 12:5e618e97cb24 | 67 | * @param tx_pin TX pin of serial port of the board |
bieleluk | 12:5e618e97cb24 | 68 | * @param rx_pin RX pin of serial port of the board |
bieleluk | 12:5e618e97cb24 | 69 | * @param baudrate desired baudrate value of serial port |
bieleluk | 12:5e618e97cb24 | 70 | */ |
bieleluk | 12:5e618e97cb24 | 71 | Debug_complete(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 12:5e618e97cb24 | 72 | |
bieleluk | 12:5e618e97cb24 | 73 | /** Perform one breakpoint |
bieleluk | 12:5e618e97cb24 | 74 | * @param line_number line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 75 | */ |
bieleluk | 12:5e618e97cb24 | 76 | void breakpoint(int line_number = -1); |
bieleluk | 12:5e618e97cb24 | 77 | |
bieleluk | 12:5e618e97cb24 | 78 | |
bieleluk | 12:5e618e97cb24 | 79 | /** Print one 32-bit word from memory from address shifted by offset |
bieleluk | 12:5e618e97cb24 | 80 | * @param address |
bieleluk | 12:5e618e97cb24 | 81 | * @param offset |
bieleluk | 12:5e618e97cb24 | 82 | */ |
bieleluk | 12:5e618e97cb24 | 83 | void print_reg(uint32_t address, uint32_t offset = 0); |
bieleluk | 12:5e618e97cb24 | 84 | |
bieleluk | 12:5e618e97cb24 | 85 | /** Print formatted string to debug serial port |
bieleluk | 12:5e618e97cb24 | 86 | * @param string |
bieleluk | 12:5e618e97cb24 | 87 | * @param format (optional) |
bieleluk | 12:5e618e97cb24 | 88 | * @returns total number of printed characters or negative value if an output error or an encoding error |
bieleluk | 12:5e618e97cb24 | 89 | */ |
bieleluk | 12:5e618e97cb24 | 90 | int printf(const char* format, ...); |
bieleluk | 12:5e618e97cb24 | 91 | |
bieleluk | 12:5e618e97cb24 | 92 | /** Print one character to debug serial port |
bieleluk | 12:5e618e97cb24 | 93 | * @param character |
bieleluk | 12:5e618e97cb24 | 94 | * @returns character written as an unsigned char cast to an int |
bieleluk | 12:5e618e97cb24 | 95 | */ |
bieleluk | 12:5e618e97cb24 | 96 | int putc(int character); |
bieleluk | 12:5e618e97cb24 | 97 | |
bieleluk | 12:5e618e97cb24 | 98 | /** Read one character from debug serial port |
bieleluk | 12:5e618e97cb24 | 99 | * @returns character written as an unsigned char cast to an int |
bieleluk | 12:5e618e97cb24 | 100 | */ |
bieleluk | 12:5e618e97cb24 | 101 | int getc(); |
bieleluk | 12:5e618e97cb24 | 102 | |
bieleluk | 12:5e618e97cb24 | 103 | |
bieleluk | 12:5e618e97cb24 | 104 | |
bieleluk | 12:5e618e97cb24 | 105 | private: |
bieleluk | 12:5e618e97cb24 | 106 | // objects |
bieleluk | 12:5e618e97cb24 | 107 | Serial pc; //debug serial device |
bieleluk | 12:5e618e97cb24 | 108 | // variables |
bieleluk | 12:5e618e97cb24 | 109 | int breakpoint_count; //stores number of the current breakpoint |
bieleluk | 12:5e618e97cb24 | 110 | //functions |
bieleluk | 12:5e618e97cb24 | 111 | // print alternate function of pin |
bieleluk | 12:5e618e97cb24 | 112 | void print_af_mode( char portx, int pin_number, int af_mode); |
bieleluk | 12:5e618e97cb24 | 113 | // show configuration of pin |
bieleluk | 12:5e618e97cb24 | 114 | void show_pin_config(pin_t pin); |
bieleluk | 12:5e618e97cb24 | 115 | // print configuration of timer |
bieleluk | 12:5e618e97cb24 | 116 | void show_tim_config(int timer); |
bieleluk | 12:5e618e97cb24 | 117 | // print configuration of pin in pwm output mode |
bieleluk | 12:5e618e97cb24 | 118 | void show_pwm_config(int timer, int channel); |
bieleluk | 12:5e618e97cb24 | 119 | // print configuration of pin in analog input mode |
bieleluk | 12:5e618e97cb24 | 120 | void show_analog_config(int channel); |
bieleluk | 12:5e618e97cb24 | 121 | // print configuration of adc1 converter |
bieleluk | 12:5e618e97cb24 | 122 | void show_adc1_config(); |
bieleluk | 12:5e618e97cb24 | 123 | //print configuration of board's clock |
bieleluk | 12:5e618e97cb24 | 124 | void show_clk_config(); |
bieleluk | 12:5e618e97cb24 | 125 | // clear screen from m line up to n line |
bieleluk | 12:5e618e97cb24 | 126 | void clear_from_n_up_to_m(int m, int n); |
bieleluk | 12:5e618e97cb24 | 127 | //initialization function |
bieleluk | 12:5e618e97cb24 | 128 | void init(); |
bieleluk | 12:5e618e97cb24 | 129 | }; |
bieleluk | 12:5e618e97cb24 | 130 | |
bieleluk | 12:5e618e97cb24 | 131 | /** Debug_serial class. |
bieleluk | 12:5e618e97cb24 | 132 | * Used for printing for actual position of running program and one variable |
bieleluk | 12:5e618e97cb24 | 133 | * |
bieleluk | 12:5e618e97cb24 | 134 | * Example: |
bieleluk | 12:5e618e97cb24 | 135 | * @code |
bieleluk | 12:5e618e97cb24 | 136 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 137 | * // "THE BEER-WARE LICENSE" (Revision 42): |
bieleluk | 12:5e618e97cb24 | 138 | * // <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you |
bieleluk | 12:5e618e97cb24 | 139 | * // can do whatever you want with this stuff. If we meet some day, and you think |
bieleluk | 12:5e618e97cb24 | 140 | * // this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp |
bieleluk | 12:5e618e97cb24 | 141 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 142 | * // Author: Lukas Bielesch |
bieleluk | 12:5e618e97cb24 | 143 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 12:5e618e97cb24 | 144 | * // Date of publication: 15. Apr 2019 |
bieleluk | 12:5e618e97cb24 | 145 | * // ---------------------------------------------------------------------------- |
bieleluk | 14:5a3b0cabbcd4 | 146 | * #include "Debug.h" |
bieleluk | 12:5e618e97cb24 | 147 | * AnalogIn analog(PA_5); |
bieleluk | 12:5e618e97cb24 | 148 | * PwmOut pwm(PA_6); |
bieleluk | 12:5e618e97cb24 | 149 | * DigitalOut out(PA_4); |
bieleluk | 12:5e618e97cb24 | 150 | * Debug_serial pc(PA_2, PA_3, 115200); |
bieleluk | 12:5e618e97cb24 | 151 | * |
bieleluk | 12:5e618e97cb24 | 152 | * int main(){ |
bieleluk | 12:5e618e97cb24 | 153 | * int var = 0; |
bieleluk | 12:5e618e97cb24 | 154 | * char character; |
bieleluk | 12:5e618e97cb24 | 155 | * out = 1; |
bieleluk | 12:5e618e97cb24 | 156 | * float pi = 3.14159265359; |
bieleluk | 12:5e618e97cb24 | 157 | * pc.breakpoint(__LINE__,name(pi),pi); |
bieleluk | 12:5e618e97cb24 | 158 | * char* arr = "this is string"; |
bieleluk | 12:5e618e97cb24 | 159 | * pc.breakpoint(__LINE__,name(arr),arr); |
bieleluk | 12:5e618e97cb24 | 160 | * pwm = 0.5; |
bieleluk | 12:5e618e97cb24 | 161 | * pwm.period(1); |
bieleluk | 12:5e618e97cb24 | 162 | * while(1){ |
bieleluk | 12:5e618e97cb24 | 163 | * pc.breakpoint(__LINE__,name(var),var); |
bieleluk | 12:5e618e97cb24 | 164 | * pc.printf("insert character\n\r"); |
bieleluk | 12:5e618e97cb24 | 165 | * character = pc.getc(); |
bieleluk | 12:5e618e97cb24 | 166 | * pc.printf("you have inserted %c\n\r",character); |
bieleluk | 12:5e618e97cb24 | 167 | * var++; |
bieleluk | 12:5e618e97cb24 | 168 | * wait(1); |
bieleluk | 12:5e618e97cb24 | 169 | * } |
bieleluk | 12:5e618e97cb24 | 170 | * } |
bieleluk | 12:5e618e97cb24 | 171 | * @endcode |
bieleluk | 12:5e618e97cb24 | 172 | */ |
bieleluk | 12:5e618e97cb24 | 173 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 174 | class Debug_serial { |
bieleluk | 12:5e618e97cb24 | 175 | public: |
bieleluk | 12:5e618e97cb24 | 176 | |
bieleluk | 12:5e618e97cb24 | 177 | /** Create object of class Debug_serial |
bieleluk | 12:5e618e97cb24 | 178 | * @param tx_pin TX pin of serial port of the board |
bieleluk | 12:5e618e97cb24 | 179 | * @param rx_pin RX pin of serial port of the board |
bieleluk | 12:5e618e97cb24 | 180 | * @param baudrate desired baudrate value of debug serial port |
bieleluk | 12:5e618e97cb24 | 181 | */ |
bieleluk | 12:5e618e97cb24 | 182 | Debug_serial(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 12:5e618e97cb24 | 183 | |
bieleluk | 12:5e618e97cb24 | 184 | /** Perform one breakpoint without printing variable |
bieleluk | 12:5e618e97cb24 | 185 | * @param line_number line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 186 | */ |
bieleluk | 12:5e618e97cb24 | 187 | void breakpoint(int line_number = -1); |
bieleluk | 12:5e618e97cb24 | 188 | |
bieleluk | 12:5e618e97cb24 | 189 | /** Perform one breakpoint and print variable of type int |
bieleluk | 12:5e618e97cb24 | 190 | * @param line_number Line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 191 | * @param name name of printed variable(max length is 19) |
bieleluk | 12:5e618e97cb24 | 192 | * @param variable |
bieleluk | 12:5e618e97cb24 | 193 | */ |
bieleluk | 12:5e618e97cb24 | 194 | void breakpoint(int line_number, char name[20], int variable); |
bieleluk | 12:5e618e97cb24 | 195 | |
bieleluk | 12:5e618e97cb24 | 196 | /** Perform one breakpoint and print variable of type char |
bieleluk | 12:5e618e97cb24 | 197 | * @param line_number Line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 198 | * @param name name of printed variable(max length is 19) |
bieleluk | 12:5e618e97cb24 | 199 | * @param variable |
bieleluk | 12:5e618e97cb24 | 200 | */ |
bieleluk | 12:5e618e97cb24 | 201 | void breakpoint(int line_number, char name[20], char variable); |
bieleluk | 12:5e618e97cb24 | 202 | |
bieleluk | 12:5e618e97cb24 | 203 | /** Perform one breakpoint and print variable of type string |
bieleluk | 12:5e618e97cb24 | 204 | * @param line_number Line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 205 | * @param name name of printed variable(max length is 19) |
bieleluk | 12:5e618e97cb24 | 206 | * @param variable |
bieleluk | 12:5e618e97cb24 | 207 | */ |
bieleluk | 12:5e618e97cb24 | 208 | void breakpoint(int line_number, char name[20], char * variable); |
bieleluk | 12:5e618e97cb24 | 209 | |
bieleluk | 12:5e618e97cb24 | 210 | /** Perform one breakpoint and print variable of type float |
bieleluk | 12:5e618e97cb24 | 211 | * @param line_number Line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 212 | * @param name name of printed variable(max length is 19) |
bieleluk | 12:5e618e97cb24 | 213 | * @param variable |
bieleluk | 12:5e618e97cb24 | 214 | */ |
bieleluk | 12:5e618e97cb24 | 215 | void breakpoint(int line_number, char name[20], float variable); |
bieleluk | 12:5e618e97cb24 | 216 | |
bieleluk | 12:5e618e97cb24 | 217 | /** Print formatted string to debug serial port |
bieleluk | 12:5e618e97cb24 | 218 | * @param string |
bieleluk | 12:5e618e97cb24 | 219 | * @param format (optional) |
bieleluk | 12:5e618e97cb24 | 220 | * @returns total number of printed characters or negative value if an output error or an encoding error |
bieleluk | 12:5e618e97cb24 | 221 | */ |
bieleluk | 12:5e618e97cb24 | 222 | int printf(const char* format, ...); |
bieleluk | 12:5e618e97cb24 | 223 | |
bieleluk | 12:5e618e97cb24 | 224 | /** Print one character to debug serial port |
bieleluk | 12:5e618e97cb24 | 225 | * @param character |
bieleluk | 12:5e618e97cb24 | 226 | * @returns character written as an unsigned char cast to an int |
bieleluk | 12:5e618e97cb24 | 227 | */ |
bieleluk | 12:5e618e97cb24 | 228 | int putc(int character); |
bieleluk | 12:5e618e97cb24 | 229 | |
bieleluk | 12:5e618e97cb24 | 230 | /** Read one character from debug serial port |
bieleluk | 12:5e618e97cb24 | 231 | * @returns character written as an unsigned char cast to an int |
bieleluk | 12:5e618e97cb24 | 232 | */ |
bieleluk | 12:5e618e97cb24 | 233 | int getc(); |
bieleluk | 12:5e618e97cb24 | 234 | private: |
bieleluk | 12:5e618e97cb24 | 235 | int break_line[3]; //store number of lines of three previous breakpoints |
bieleluk | 12:5e618e97cb24 | 236 | char var[3][50]; //store variables of three previous breakpoints |
bieleluk | 12:5e618e97cb24 | 237 | |
bieleluk | 12:5e618e97cb24 | 238 | protected: |
bieleluk | 12:5e618e97cb24 | 239 | // objects: |
bieleluk | 12:5e618e97cb24 | 240 | Serial pc; //debug serial device |
bieleluk | 12:5e618e97cb24 | 241 | // variables: |
bieleluk | 12:5e618e97cb24 | 242 | int breakpoint_count; //stores number of the current breakpoint |
bieleluk | 12:5e618e97cb24 | 243 | // functions |
bieleluk | 12:5e618e97cb24 | 244 | // initialization function |
bieleluk | 12:5e618e97cb24 | 245 | void init(); |
bieleluk | 12:5e618e97cb24 | 246 | // print 3 last breakpoints |
bieleluk | 12:5e618e97cb24 | 247 | void print_3_breaks(int line_number); |
bieleluk | 12:5e618e97cb24 | 248 | // print one breakpoint |
bieleluk | 12:5e618e97cb24 | 249 | void print_one_break(int n); |
bieleluk | 12:5e618e97cb24 | 250 | // clear screen from m line up to n line |
bieleluk | 12:5e618e97cb24 | 251 | void clear_from_n_up_to_m(int m, int n); |
bieleluk | 12:5e618e97cb24 | 252 | }; |
bieleluk | 12:5e618e97cb24 | 253 | |
bieleluk | 12:5e618e97cb24 | 254 | |
bieleluk | 12:5e618e97cb24 | 255 | |
bieleluk | 12:5e618e97cb24 | 256 | |
bieleluk | 12:5e618e97cb24 | 257 | /** Debug_led class. |
bieleluk | 12:5e618e97cb24 | 258 | * Used for stepping the program |
bieleluk | 12:5e618e97cb24 | 259 | * |
bieleluk | 12:5e618e97cb24 | 260 | * Example: |
bieleluk | 12:5e618e97cb24 | 261 | * @code |
bieleluk | 12:5e618e97cb24 | 262 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 263 | * // "THE BEER-WARE LICENSE" (Revision 42): |
bieleluk | 12:5e618e97cb24 | 264 | * // <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you |
bieleluk | 12:5e618e97cb24 | 265 | * // can do whatever you want with this stuff. If we meet some day, and you think |
bieleluk | 12:5e618e97cb24 | 266 | * // this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp |
bieleluk | 12:5e618e97cb24 | 267 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 268 | * // Author: Lukas Bielesch |
bieleluk | 12:5e618e97cb24 | 269 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 12:5e618e97cb24 | 270 | * // Date of publication: 15. Apr 2019 |
bieleluk | 12:5e618e97cb24 | 271 | * // ---------------------------------------------------------------------------- |
bieleluk | 14:5a3b0cabbcd4 | 272 | * #include "Debug.h" |
bieleluk | 12:5e618e97cb24 | 273 | * AnalogIn analog(PA_5); |
bieleluk | 12:5e618e97cb24 | 274 | * PwmOut pwm(PA_6); |
bieleluk | 12:5e618e97cb24 | 275 | * DigitalOut out(PA_4); |
bieleluk | 12:5e618e97cb24 | 276 | * |
bieleluk | 12:5e618e97cb24 | 277 | * Debug_led deb(PA_5, PA_6, "BUTTON_VDD"); |
bieleluk | 12:5e618e97cb24 | 278 | * int main(){ |
bieleluk | 12:5e618e97cb24 | 279 | * |
bieleluk | 12:5e618e97cb24 | 280 | * out = 1; |
bieleluk | 12:5e618e97cb24 | 281 | * deb.breakpoint(1); |
bieleluk | 12:5e618e97cb24 | 282 | * pwm = 0.5; |
bieleluk | 12:5e618e97cb24 | 283 | * pwm.period(1); |
bieleluk | 12:5e618e97cb24 | 284 | * deb.breakpoint(2); |
bieleluk | 12:5e618e97cb24 | 285 | * |
bieleluk | 12:5e618e97cb24 | 286 | * while(1){ |
bieleluk | 12:5e618e97cb24 | 287 | * deb.breakpoint(); |
bieleluk | 12:5e618e97cb24 | 288 | * pwm = pwm + 0.1; |
bieleluk | 12:5e618e97cb24 | 289 | * wait(2); |
bieleluk | 12:5e618e97cb24 | 290 | * } |
bieleluk | 12:5e618e97cb24 | 291 | * } |
bieleluk | 12:5e618e97cb24 | 292 | * @endcode |
bieleluk | 12:5e618e97cb24 | 293 | */ |
bieleluk | 12:5e618e97cb24 | 294 | // class Debug_led |
bieleluk | 12:5e618e97cb24 | 295 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 296 | class Debug_led { |
bieleluk | 12:5e618e97cb24 | 297 | public: |
bieleluk | 12:5e618e97cb24 | 298 | |
bieleluk | 12:5e618e97cb24 | 299 | /** Create object of class Debug_led |
bieleluk | 12:5e618e97cb24 | 300 | * @param led_pin pin of of debug led |
bieleluk | 12:5e618e97cb24 | 301 | * @param button_pin pin of of debug button |
bieleluk | 12:5e618e97cb24 | 302 | * @param mode mode of button connection("BUTTON_GND", "BUTTON_VCC", "BUTTON_VDD") |
bieleluk | 12:5e618e97cb24 | 303 | */ |
bieleluk | 12:5e618e97cb24 | 304 | Debug_led(PinName led_pin, PinName button_pin, char mode[11] = "BUTTON_GND"); |
bieleluk | 12:5e618e97cb24 | 305 | |
bieleluk | 12:5e618e97cb24 | 306 | /** Perform one breakpoint |
bieleluk | 12:5e618e97cb24 | 307 | * @param number number of flashes of LED during the breakpoint(optional) |
bieleluk | 12:5e618e97cb24 | 308 | */ |
bieleluk | 12:5e618e97cb24 | 309 | void breakpoint(int number = -1); |
bieleluk | 12:5e618e97cb24 | 310 | |
bieleluk | 12:5e618e97cb24 | 311 | private: |
bieleluk | 12:5e618e97cb24 | 312 | // objects |
bieleluk | 12:5e618e97cb24 | 313 | DigitalOut led; //debug led |
bieleluk | 12:5e618e97cb24 | 314 | InterruptIn button; //debug button |
bieleluk | 12:5e618e97cb24 | 315 | // variables |
bieleluk | 12:5e618e97cb24 | 316 | int button_mode; //mode of button 1->pullupt, 0->pulldown |
bieleluk | 12:5e618e97cb24 | 317 | volatile bool end_breakpoint; |
bieleluk | 12:5e618e97cb24 | 318 | int number_of_breakpoints; |
bieleluk | 12:5e618e97cb24 | 319 | |
bieleluk | 12:5e618e97cb24 | 320 | /** Initialization */ |
bieleluk | 12:5e618e97cb24 | 321 | void init(char mode[11]); |
bieleluk | 12:5e618e97cb24 | 322 | |
bieleluk | 12:5e618e97cb24 | 323 | /** Blinks the debug led n-times with blink period wait_time_ms */ |
bieleluk | 12:5e618e97cb24 | 324 | void flash_n_times(int wait_time_ms, int n); |
bieleluk | 12:5e618e97cb24 | 325 | |
bieleluk | 12:5e618e97cb24 | 326 | /** end the break after the button is pushed */ |
bieleluk | 12:5e618e97cb24 | 327 | void end_break(); |
bieleluk | 12:5e618e97cb24 | 328 | |
bieleluk | 12:5e618e97cb24 | 329 | |
bieleluk | 12:5e618e97cb24 | 330 | }; |