Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.
Diff: Debug.h
- Revision:
- 16:7fc964b6d127
- Parent:
- 15:83d4dced2a28
- Child:
- 17:5b0dd2a6b130
diff -r 83d4dced2a28 -r 7fc964b6d127 Debug.h --- a/Debug.h Mon May 27 02:11:53 2019 +0000 +++ b/Debug.h Mon Jun 03 19:36:48 2019 +0000 @@ -4,6 +4,8 @@ //------------------------------------------------------------------------------------------------------------------ #include "mbed.h" #include <stdlib.h> +#include "SWO.h" + // macros @@ -13,7 +15,6 @@ #define max(a, b) (((a) > (b)) ? (a) : (b)) - //------------------------------------------------------------------------------------------------------------------ /** Debug_serial class. * Class for stepping programme and printing actual position of the running programme with optional print of one variable (int, float, char or char*). @@ -390,4 +391,71 @@ // initialization function void init(); +}; + +//------------------------------------------------------------------------------------------------------------------ +/** Debug_swo class. + * + * Example program: + * @code + * // ---------------------------------------------------------------------------- + * // Author: Lukas Bielesch + * // Department of Measurement, Czech technical university in Prague, Czech Republic + * // Date of publication: 15. Apr 2019 + * // ---------------------------------------------------------------------------- + * #include "Debug.h" + * AnalogIn analog(PA_4); + * PwmOut pwm(PA_6); + * DigitalOut out(PA_5); + * Debug_swo pc; + * + * int main(){ + * pc.format(2,2,1,3);//breakpoint count,line number, address, value + * pc.breakpoint(__LINE__,0x48000001, 2); + * DigitalOut out2 (PA_0); + * pc.breakpoint(__LINE__,0x48000014, -3); + * AnalogIn analog2 (PA_1); + * pc.breakpoint(__LINE__,0x48000008); + * + * while(1){ + * wait(1); + * } + * } + * @endcode + */ +class Debug_swo { +public: + + /** Create object of Debug_swo class + */ + Debug_swo(); + + /** Set format of breakpoint message + * @param break_number format of number of actual breakpoint: 0->not show, 1->show in hexadecimal, 2->show in decimal(default) + * @param line format of line of actual breakpoint: 0->not show, 1->show in hexadecimal, 2->show in decimal(default) + * @param address format of address of register: 0->not show, 1->show in hexadecimal(default), 2->show in decimal + * @param value format of register value: 0->not show, 1->show in hexadecimal, 2->show in decimal, 3->show in binary(default) + */ + void format(int break_number = 2, int line = 2, int address = 1, int value = 3); + + /** Perform one breakpoint and print one register value + * @param line_number line number of breakpoint, macro __LINE__ is recommended + * @param address address of register , must be divisible by 4 + */ + void breakpoint(int line_number, uint32_t address, int number_of_words = 1); + + +protected: +// objects: + SWO_Channel pc; //debug serial device +// variables: + int breakpoint_count; //number of the current breakpoint + int count_format; // format of breakpoint count, 0->not show, 1->show in hexadecimal, 2->show in decimal + int line_format; // format of lineof breakpoint, 0->not show, 1->show in hexadecimal, 2->show in decimal + int address_format; // format of address of register, 0->not show, 1->show in hexadecimal, 2->show in decimal + int register_format;// format of register value, 0->not show, 1->show in hexadecimal, 2->show in decimal, 3->show in binary +// functions + // initialization function + void init(); + }; \ No newline at end of file