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