debug tool for STM32F042F6P6

Committer:
bieleluk
Date:
Sun May 05 21:43:08 2019 +0000
Revision:
21:f685c7326727
Parent:
19:841a5c532145
Child:
22:e63aa0ea925a

        

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