debug tool for STM32F042F6P6

Committer:
bieleluk
Date:
Thu Apr 18 13:36:36 2019 +0000
Revision:
19:841a5c532145
Parent:
18:4b27f04a54dd
Child:
21:f685c7326727

        

Who changed what in which revision?

UserRevisionLine numberNew 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 15:a9db6d4c2a8f 28 * Class for stepping programme and printing actual position and complete configuration of certain peripherals.
bieleluk 16:e232e16e4f46 29 *
bieleluk 15:a9db6d4c2a8f 30 * Functions printf, putc and getc are also defined in the class.
bieleluk 16:e232e16e4f46 31 *
bieleluk 15:a9db6d4c2a8f 32 * Example program:
bieleluk 12:5e618e97cb24 33 * @code
bieleluk 12:5e618e97cb24 34 * // ----------------------------------------------------------------------------
bieleluk 12:5e618e97cb24 35 * // Author: Lukas Bielesch
bieleluk 12:5e618e97cb24 36 * // Department of Measurement, Czech technical university in Prague, Czech Republic
bieleluk 12:5e618e97cb24 37 * // Date of publication: 15. Apr 2019
bieleluk 12:5e618e97cb24 38 * // ----------------------------------------------------------------------------
bieleluk 14:5a3b0cabbcd4 39 * #include "Debug.h"
bieleluk 12:5e618e97cb24 40 * AnalogIn analog(PA_5);
bieleluk 12:5e618e97cb24 41 * PwmOut pwm(PA_6);
bieleluk 12:5e618e97cb24 42 * DigitalOut out(PA_4);
bieleluk 12:5e618e97cb24 43 * Debug_complete pc(PA_2, PA_3, 115200);
bieleluk 12:5e618e97cb24 44 *
bieleluk 12:5e618e97cb24 45 * int main(){
bieleluk 12:5e618e97cb24 46 * out = 1;
bieleluk 12:5e618e97cb24 47 * pc.breakpoint(__LINE__);
bieleluk 12:5e618e97cb24 48 * pwm = 0.5;
bieleluk 12:5e618e97cb24 49 * pwm.period(1);
bieleluk 12:5e618e97cb24 50 * while(1){
bieleluk 12:5e618e97cb24 51 * pc.breakpoint(__LINE__);
bieleluk 12:5e618e97cb24 52 * wait(1);
bieleluk 12:5e618e97cb24 53 * pc.breakpoint();
bieleluk 12:5e618e97cb24 54 * pc.printf("value of adc is %f*VDD\n\r",analog.read());
bieleluk 13:3d959f23fd8f 55 * pc.print_reg(0x48000000,0x0);
bieleluk 12:5e618e97cb24 56 * }
bieleluk 12:5e618e97cb24 57 * }
bieleluk 12:5e618e97cb24 58 * @endcode
bieleluk 12:5e618e97cb24 59 */
bieleluk 12:5e618e97cb24 60 class Debug_complete {
bieleluk 12:5e618e97cb24 61 public:
bieleluk 12:5e618e97cb24 62
bieleluk 12:5e618e97cb24 63 /** Create object of class Debug_complete
bieleluk 12:5e618e97cb24 64 * @param tx_pin TX pin of serial port of the board
bieleluk 12:5e618e97cb24 65 * @param rx_pin RX pin of serial port of the board
bieleluk 12:5e618e97cb24 66 * @param baudrate desired baudrate value of serial port
bieleluk 12:5e618e97cb24 67 */
bieleluk 12:5e618e97cb24 68 Debug_complete(PinName tx_pin, PinName rx_pin, int baudrate = 115200);
bieleluk 12:5e618e97cb24 69
bieleluk 12:5e618e97cb24 70 /** Perform one breakpoint
bieleluk 12:5e618e97cb24 71 * @param line_number line number of the breakpoint
bieleluk 12:5e618e97cb24 72 */
bieleluk 12:5e618e97cb24 73 void breakpoint(int line_number = -1);
bieleluk 12:5e618e97cb24 74
bieleluk 12:5e618e97cb24 75
bieleluk 12:5e618e97cb24 76
bieleluk 12:5e618e97cb24 77 private:
bieleluk 12:5e618e97cb24 78 // objects
bieleluk 12:5e618e97cb24 79 Serial pc; //debug serial device
bieleluk 12:5e618e97cb24 80 // variables
bieleluk 12:5e618e97cb24 81 int breakpoint_count; //stores number of the current breakpoint
bieleluk 12:5e618e97cb24 82 //functions
bieleluk 12:5e618e97cb24 83 // print alternate function of pin
bieleluk 12:5e618e97cb24 84 void print_af_mode( char portx, int pin_number, int af_mode);
bieleluk 19:841a5c532145 85 // show configuration of all pins
bieleluk 19:841a5c532145 86 void show_all_pins_config();
bieleluk 19:841a5c532145 87 // show configuration of one pin
bieleluk 12:5e618e97cb24 88 void show_pin_config(pin_t pin);
bieleluk 19:841a5c532145 89 // print config of all timers
bieleluk 19:841a5c532145 90 void show_all_timers_config();
bieleluk 12:5e618e97cb24 91 // print configuration of timer
bieleluk 12:5e618e97cb24 92 void show_tim_config(int timer);
bieleluk 12:5e618e97cb24 93 // print configuration of pin in pwm output mode
bieleluk 12:5e618e97cb24 94 void show_pwm_config(int timer, int channel);
bieleluk 12:5e618e97cb24 95 // print configuration of pin in analog input mode
bieleluk 12:5e618e97cb24 96 void show_analog_config(int channel);
bieleluk 12:5e618e97cb24 97 // print configuration of adc1 converter
bieleluk 12:5e618e97cb24 98 void show_adc1_config();
bieleluk 12:5e618e97cb24 99 //print configuration of board's clock
bieleluk 12:5e618e97cb24 100 void show_clk_config();
bieleluk 12:5e618e97cb24 101 // clear screen from m line up to n line
bieleluk 19:841a5c532145 102 //void clear_from_n_up_to_m(int m, int n);
bieleluk 12:5e618e97cb24 103 //initialization function
bieleluk 12:5e618e97cb24 104 void init();
bieleluk 19:841a5c532145 105 void line();
bieleluk 12:5e618e97cb24 106 };
bieleluk 12:5e618e97cb24 107
bieleluk 12:5e618e97cb24 108 /** Debug_serial class.
bieleluk 17:250429530b0c 109 * Class for stepping programme and printing actual position of the running programme with optional print of one variable (int, float, char or char*).
bieleluk 15:a9db6d4c2a8f 110 * Functions printf, putc and getc are also defined in the class.
bieleluk 12:5e618e97cb24 111 *
bieleluk 15:a9db6d4c2a8f 112 * Example program:
bieleluk 12:5e618e97cb24 113 * @code
bieleluk 12:5e618e97cb24 114 * // ----------------------------------------------------------------------------
bieleluk 12:5e618e97cb24 115 * // Author: Lukas Bielesch
bieleluk 12:5e618e97cb24 116 * // Department of Measurement, Czech technical university in Prague, Czech Republic
bieleluk 12:5e618e97cb24 117 * // Date of publication: 15. Apr 2019
bieleluk 12:5e618e97cb24 118 * // ----------------------------------------------------------------------------
bieleluk 14:5a3b0cabbcd4 119 * #include "Debug.h"
bieleluk 12:5e618e97cb24 120 * AnalogIn analog(PA_5);
bieleluk 12:5e618e97cb24 121 * PwmOut pwm(PA_6);
bieleluk 12:5e618e97cb24 122 * DigitalOut out(PA_4);
bieleluk 15:a9db6d4c2a8f 123 * Debug_serial pc(PA_2, PA_3, 115200); //
bieleluk 12:5e618e97cb24 124 *
bieleluk 12:5e618e97cb24 125 * int main(){
bieleluk 12:5e618e97cb24 126 * int var = 0;
bieleluk 12:5e618e97cb24 127 * char character;
bieleluk 12:5e618e97cb24 128 * out = 1;
bieleluk 12:5e618e97cb24 129 * float pi = 3.14159265359;
bieleluk 12:5e618e97cb24 130 * pc.breakpoint(__LINE__,name(pi),pi);
bieleluk 12:5e618e97cb24 131 * char* arr = "this is string";
bieleluk 12:5e618e97cb24 132 * pc.breakpoint(__LINE__,name(arr),arr);
bieleluk 12:5e618e97cb24 133 * pwm = 0.5;
bieleluk 12:5e618e97cb24 134 * pwm.period(1);
bieleluk 12:5e618e97cb24 135 * while(1){
bieleluk 12:5e618e97cb24 136 * pc.breakpoint(__LINE__,name(var),var);
bieleluk 12:5e618e97cb24 137 * pc.printf("insert character\n\r");
bieleluk 12:5e618e97cb24 138 * character = pc.getc();
bieleluk 12:5e618e97cb24 139 * pc.printf("you have inserted %c\n\r",character);
bieleluk 12:5e618e97cb24 140 * var++;
bieleluk 12:5e618e97cb24 141 * wait(1);
bieleluk 12:5e618e97cb24 142 * }
bieleluk 12:5e618e97cb24 143 * }
bieleluk 12:5e618e97cb24 144 * @endcode
bieleluk 12:5e618e97cb24 145 */
bieleluk 12:5e618e97cb24 146 //------------------------------------------------------------------------------------------------------------------
bieleluk 12:5e618e97cb24 147 class Debug_serial {
bieleluk 12:5e618e97cb24 148 public:
bieleluk 12:5e618e97cb24 149
bieleluk 12:5e618e97cb24 150 /** Create object of class Debug_serial
bieleluk 12:5e618e97cb24 151 * @param tx_pin TX pin of serial port of the board
bieleluk 12:5e618e97cb24 152 * @param rx_pin RX pin of serial port of the board
bieleluk 12:5e618e97cb24 153 * @param baudrate desired baudrate value of debug serial port
bieleluk 12:5e618e97cb24 154 */
bieleluk 12:5e618e97cb24 155 Debug_serial(PinName tx_pin, PinName rx_pin, int baudrate = 115200);
bieleluk 12:5e618e97cb24 156
bieleluk 12:5e618e97cb24 157 /** Perform one breakpoint without printing variable
bieleluk 12:5e618e97cb24 158 * @param line_number line number of the breakpoint
bieleluk 12:5e618e97cb24 159 */
bieleluk 12:5e618e97cb24 160 void breakpoint(int line_number = -1);
bieleluk 12:5e618e97cb24 161
bieleluk 12:5e618e97cb24 162 /** Perform one breakpoint and print variable of type int
bieleluk 12:5e618e97cb24 163 * @param line_number Line number of the breakpoint
bieleluk 12:5e618e97cb24 164 * @param name name of printed variable(max length is 19)
bieleluk 12:5e618e97cb24 165 * @param variable
bieleluk 12:5e618e97cb24 166 */
bieleluk 12:5e618e97cb24 167 void breakpoint(int line_number, char name[20], int variable);
bieleluk 12:5e618e97cb24 168
bieleluk 12:5e618e97cb24 169 /** Perform one breakpoint and print variable of type char
bieleluk 12:5e618e97cb24 170 * @param line_number Line number of the breakpoint
bieleluk 12:5e618e97cb24 171 * @param name name of printed variable(max length is 19)
bieleluk 12:5e618e97cb24 172 * @param variable
bieleluk 12:5e618e97cb24 173 */
bieleluk 12:5e618e97cb24 174 void breakpoint(int line_number, char name[20], char variable);
bieleluk 12:5e618e97cb24 175
bieleluk 12:5e618e97cb24 176 /** Perform one breakpoint and print variable of type string
bieleluk 12:5e618e97cb24 177 * @param line_number Line number of the breakpoint
bieleluk 12:5e618e97cb24 178 * @param name name of printed variable(max length is 19)
bieleluk 12:5e618e97cb24 179 * @param variable
bieleluk 12:5e618e97cb24 180 */
bieleluk 12:5e618e97cb24 181 void breakpoint(int line_number, char name[20], char * variable);
bieleluk 12:5e618e97cb24 182
bieleluk 12:5e618e97cb24 183 /** Perform one breakpoint and print variable of type float
bieleluk 12:5e618e97cb24 184 * @param line_number Line number of the breakpoint
bieleluk 12:5e618e97cb24 185 * @param name name of printed variable(max length is 19)
bieleluk 12:5e618e97cb24 186 * @param variable
bieleluk 12:5e618e97cb24 187 */
bieleluk 12:5e618e97cb24 188 void breakpoint(int line_number, char name[20], float variable);
bieleluk 12:5e618e97cb24 189
bieleluk 12:5e618e97cb24 190 /** Print formatted string to debug serial port
bieleluk 12:5e618e97cb24 191 * @param string
bieleluk 12:5e618e97cb24 192 * @param format (optional)
bieleluk 12:5e618e97cb24 193 * @returns total number of printed characters or negative value if an output error or an encoding error
bieleluk 12:5e618e97cb24 194 */
bieleluk 12:5e618e97cb24 195 int printf(const char* format, ...);
bieleluk 12:5e618e97cb24 196
bieleluk 12:5e618e97cb24 197 /** Print one character to debug serial port
bieleluk 12:5e618e97cb24 198 * @param character
bieleluk 12:5e618e97cb24 199 * @returns character written as an unsigned char cast to an int
bieleluk 12:5e618e97cb24 200 */
bieleluk 12:5e618e97cb24 201 int putc(int character);
bieleluk 12:5e618e97cb24 202
bieleluk 12:5e618e97cb24 203 /** Read one character from debug serial port
bieleluk 12:5e618e97cb24 204 * @returns character written as an unsigned char cast to an int
bieleluk 12:5e618e97cb24 205 */
bieleluk 12:5e618e97cb24 206 int getc();
bieleluk 12:5e618e97cb24 207 private:
bieleluk 12:5e618e97cb24 208 int break_line[3]; //store number of lines of three previous breakpoints
bieleluk 12:5e618e97cb24 209 char var[3][50]; //store variables of three previous breakpoints
bieleluk 12:5e618e97cb24 210
bieleluk 12:5e618e97cb24 211 protected:
bieleluk 12:5e618e97cb24 212 // objects:
bieleluk 12:5e618e97cb24 213 Serial pc; //debug serial device
bieleluk 12:5e618e97cb24 214 // variables:
bieleluk 12:5e618e97cb24 215 int breakpoint_count; //stores number of the current breakpoint
bieleluk 12:5e618e97cb24 216 // functions
bieleluk 12:5e618e97cb24 217 // initialization function
bieleluk 12:5e618e97cb24 218 void init();
bieleluk 12:5e618e97cb24 219 // print 3 last breakpoints
bieleluk 12:5e618e97cb24 220 void print_3_breaks(int line_number);
bieleluk 12:5e618e97cb24 221 // print one breakpoint
bieleluk 12:5e618e97cb24 222 void print_one_break(int n);
bieleluk 12:5e618e97cb24 223 // clear screen from m line up to n line
bieleluk 12:5e618e97cb24 224 void clear_from_n_up_to_m(int m, int n);
bieleluk 12:5e618e97cb24 225 };
bieleluk 12:5e618e97cb24 226
bieleluk 12:5e618e97cb24 227
bieleluk 12:5e618e97cb24 228
bieleluk 12:5e618e97cb24 229
bieleluk 12:5e618e97cb24 230 /** Debug_led class.
bieleluk 15:a9db6d4c2a8f 231 * Class for stepping the program with debug LED and button, that is connected to GND(default) or VCC.
bieleluk 12:5e618e97cb24 232 *
bieleluk 15:a9db6d4c2a8f 233 * Example program:
bieleluk 12:5e618e97cb24 234 * @code
bieleluk 12:5e618e97cb24 235 * // ----------------------------------------------------------------------------
bieleluk 12:5e618e97cb24 236 * // Author: Lukas Bielesch
bieleluk 12:5e618e97cb24 237 * // Department of Measurement, Czech technical university in Prague, Czech Republic
bieleluk 12:5e618e97cb24 238 * // Date of publication: 15. Apr 2019
bieleluk 12:5e618e97cb24 239 * // ----------------------------------------------------------------------------
bieleluk 14:5a3b0cabbcd4 240 * #include "Debug.h"
bieleluk 18:4b27f04a54dd 241 * AnalogIn analog(PA_3);
bieleluk 18:4b27f04a54dd 242 * PwmOut pwm(PA_4);
bieleluk 18:4b27f04a54dd 243 * DigitalOut out(PA_2);
bieleluk 15:a9db6d4c2a8f 244 * Debug_led deb(PA_5, PA_6, "BUTTON_VDD"); //debug led on PA5, debug button connected to VDD on PA6
bieleluk 12:5e618e97cb24 245 * int main(){
bieleluk 12:5e618e97cb24 246 *
bieleluk 12:5e618e97cb24 247 * out = 1;
bieleluk 12:5e618e97cb24 248 * deb.breakpoint(1);
bieleluk 12:5e618e97cb24 249 * pwm = 0.5;
bieleluk 12:5e618e97cb24 250 * pwm.period(1);
bieleluk 12:5e618e97cb24 251 * deb.breakpoint(2);
bieleluk 12:5e618e97cb24 252 *
bieleluk 12:5e618e97cb24 253 * while(1){
bieleluk 12:5e618e97cb24 254 * deb.breakpoint();
bieleluk 12:5e618e97cb24 255 * pwm = pwm + 0.1;
bieleluk 12:5e618e97cb24 256 * wait(2);
bieleluk 12:5e618e97cb24 257 * }
bieleluk 12:5e618e97cb24 258 * }
bieleluk 12:5e618e97cb24 259 * @endcode
bieleluk 12:5e618e97cb24 260 */
bieleluk 12:5e618e97cb24 261 // class Debug_led
bieleluk 12:5e618e97cb24 262 //------------------------------------------------------------------------------------------------------------------
bieleluk 12:5e618e97cb24 263 class Debug_led {
bieleluk 12:5e618e97cb24 264 public:
bieleluk 12:5e618e97cb24 265
bieleluk 12:5e618e97cb24 266 /** Create object of class Debug_led
bieleluk 12:5e618e97cb24 267 * @param led_pin pin of of debug led
bieleluk 12:5e618e97cb24 268 * @param button_pin pin of of debug button
bieleluk 12:5e618e97cb24 269 * @param mode mode of button connection("BUTTON_GND", "BUTTON_VCC", "BUTTON_VDD")
bieleluk 12:5e618e97cb24 270 */
bieleluk 12:5e618e97cb24 271 Debug_led(PinName led_pin, PinName button_pin, char mode[11] = "BUTTON_GND");
bieleluk 12:5e618e97cb24 272
bieleluk 12:5e618e97cb24 273 /** Perform one breakpoint
bieleluk 12:5e618e97cb24 274 * @param number number of flashes of LED during the breakpoint(optional)
bieleluk 12:5e618e97cb24 275 */
bieleluk 12:5e618e97cb24 276 void breakpoint(int number = -1);
bieleluk 12:5e618e97cb24 277
bieleluk 12:5e618e97cb24 278 private:
bieleluk 12:5e618e97cb24 279 // objects
bieleluk 12:5e618e97cb24 280 DigitalOut led; //debug led
bieleluk 12:5e618e97cb24 281 InterruptIn button; //debug button
bieleluk 12:5e618e97cb24 282 // variables
bieleluk 12:5e618e97cb24 283 int button_mode; //mode of button 1->pullupt, 0->pulldown
bieleluk 12:5e618e97cb24 284 volatile bool end_breakpoint;
bieleluk 12:5e618e97cb24 285 int number_of_breakpoints;
bieleluk 12:5e618e97cb24 286
bieleluk 12:5e618e97cb24 287 /** Initialization */
bieleluk 12:5e618e97cb24 288 void init(char mode[11]);
bieleluk 12:5e618e97cb24 289
bieleluk 12:5e618e97cb24 290 /** Blinks the debug led n-times with blink period wait_time_ms */
bieleluk 12:5e618e97cb24 291 void flash_n_times(int wait_time_ms, int n);
bieleluk 12:5e618e97cb24 292
bieleluk 12:5e618e97cb24 293 /** end the break after the button is pushed */
bieleluk 12:5e618e97cb24 294 void end_break();
bieleluk 12:5e618e97cb24 295
bieleluk 12:5e618e97cb24 296
bieleluk 12:5e618e97cb24 297 };