Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.

Committer:
bieleluk
Date:
Mon May 06 00:01:17 2019 +0000
Revision:
0:e36b454cc2e6
Child:
2:478ba8b83e3f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bieleluk 0:e36b454cc2e6 1 #include "Debug.h"
bieleluk 0:e36b454cc2e6 2
bieleluk 0:e36b454cc2e6 3 // create object of class Debug_register
bieleluk 0:e36b454cc2e6 4 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 5 Debug_register::Debug_register(PinName tx_pin, PinName rx_pin, int baudrate) : pc(tx_pin,rx_pin, baudrate) {
bieleluk 0:e36b454cc2e6 6 init();
bieleluk 0:e36b454cc2e6 7 }
bieleluk 0:e36b454cc2e6 8
bieleluk 0:e36b454cc2e6 9 // init function
bieleluk 0:e36b454cc2e6 10 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 11 void Debug_register::init() {
bieleluk 0:e36b454cc2e6 12 pc.printf("\ec");
bieleluk 0:e36b454cc2e6 13 wait_ms(50);
bieleluk 0:e36b454cc2e6 14 pc.printf("-----------------\n\r|\e[1m\e[97;40m\e[93;40mBREAKPOINT AREA\e[22m\e[97;40m|\n\r-----------------\n\r\033[s");
bieleluk 0:e36b454cc2e6 15 pc.printf("serial successfully initialised\n\r\e[32;40mto start program press any button\e[97;40m");
bieleluk 0:e36b454cc2e6 16 breakpoint_count=0;
bieleluk 0:e36b454cc2e6 17 pc.getc();
bieleluk 0:e36b454cc2e6 18 pc.printf("\r\e[2K\e[31;40mprogram is running\e[97;40m\r");
bieleluk 0:e36b454cc2e6 19
bieleluk 0:e36b454cc2e6 20 pc.printf("\033[14;0H------------------\n\r|\e[1m\e[93;40mSERIAL PORT AREA\e[22m\e[97;40m|\n\r------------------\n\r\033[s");
bieleluk 0:e36b454cc2e6 21 }
bieleluk 0:e36b454cc2e6 22
bieleluk 0:e36b454cc2e6 23
bieleluk 0:e36b454cc2e6 24
bieleluk 0:e36b454cc2e6 25
bieleluk 0:e36b454cc2e6 26 // perform one breakpoint and print one register
bieleluk 0:e36b454cc2e6 27 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 28 void Debug_register::breakpoint(int line_number, uint32_t address, uint32_t offset){
bieleluk 0:e36b454cc2e6 29
bieleluk 0:e36b454cc2e6 30 pc.printf("\e[s");
bieleluk 0:e36b454cc2e6 31 wait_ms(50);
bieleluk 0:e36b454cc2e6 32 breakpoint_count++;
bieleluk 0:e36b454cc2e6 33 clear_from_n_up_to_m(12,3);
bieleluk 0:e36b454cc2e6 34
bieleluk 0:e36b454cc2e6 35 if (line_number < 0){
bieleluk 0:e36b454cc2e6 36 pc.printf(" Breakpoint number %d\t unknown line number\n\r",breakpoint_count);
bieleluk 0:e36b454cc2e6 37 }else{
bieleluk 0:e36b454cc2e6 38 pc.printf("| Breakpoint number %d\tline number %d\n\r",breakpoint_count, line_number);
bieleluk 0:e36b454cc2e6 39 }
bieleluk 0:e36b454cc2e6 40
bieleluk 0:e36b454cc2e6 41 uint32_t reg = read_word(address, offset);
bieleluk 0:e36b454cc2e6 42 pc.printf("---------------------------------------------------------------------------------------------------------\n\r");
bieleluk 0:e36b454cc2e6 43 pc.printf("| address decimal %10u | address hex 0x%8x | value decimal %10u | value hex 0x%8x |\n\r",address+offset,address+offset, reg, reg);
bieleluk 0:e36b454cc2e6 44 pc.printf("---------------------------------------------------------------------------------------------------------\n\r");
bieleluk 0:e36b454cc2e6 45 pc.printf("|bit_num|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|\n\r");
bieleluk 0:e36b454cc2e6 46 pc.printf("---------------------------------------------------------------------------------------------------------\n\r|bit_val|");
bieleluk 0:e36b454cc2e6 47 for (int i = 0; i < 32; i++){
bieleluk 0:e36b454cc2e6 48 pc.printf("%2d|",reg >> (31 - i));
bieleluk 0:e36b454cc2e6 49 reg -= ((reg >> (31 - i)) << (31 - i));
bieleluk 0:e36b454cc2e6 50 }
bieleluk 0:e36b454cc2e6 51 pc.printf("\n\r---------------------------------------------------------------------------------------------------------\n\r");
bieleluk 0:e36b454cc2e6 52
bieleluk 0:e36b454cc2e6 53
bieleluk 0:e36b454cc2e6 54 pc.printf("\e[32;40mto continue press any button\e[97;40m");
bieleluk 0:e36b454cc2e6 55 pc.getc();
bieleluk 0:e36b454cc2e6 56 pc.printf("\r\e[2K\e[31;40mprogram is running\e[97;40m\n\r");
bieleluk 0:e36b454cc2e6 57 pc.printf("\e[u");
bieleluk 0:e36b454cc2e6 58 }
bieleluk 0:e36b454cc2e6 59
bieleluk 0:e36b454cc2e6 60
bieleluk 0:e36b454cc2e6 61
bieleluk 0:e36b454cc2e6 62 // print formatted string to debug serial port
bieleluk 0:e36b454cc2e6 63 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 64 int Debug_register::printf(const char* format, ...){
bieleluk 0:e36b454cc2e6 65
bieleluk 0:e36b454cc2e6 66 int ret = pc.printf(format);
bieleluk 0:e36b454cc2e6 67 return ret;
bieleluk 0:e36b454cc2e6 68 }
bieleluk 0:e36b454cc2e6 69
bieleluk 0:e36b454cc2e6 70 // print character to debug serial port
bieleluk 0:e36b454cc2e6 71 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 72 int Debug_register::putc(int character){
bieleluk 0:e36b454cc2e6 73
bieleluk 0:e36b454cc2e6 74 return pc.putc(character);
bieleluk 0:e36b454cc2e6 75 }
bieleluk 0:e36b454cc2e6 76
bieleluk 0:e36b454cc2e6 77 // read character from debug serial port
bieleluk 0:e36b454cc2e6 78 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 79 int Debug_register::getc(){
bieleluk 0:e36b454cc2e6 80 return pc.getc();
bieleluk 0:e36b454cc2e6 81 }
bieleluk 0:e36b454cc2e6 82
bieleluk 0:e36b454cc2e6 83 bool Debug_register::readable(){
bieleluk 0:e36b454cc2e6 84 return pc.readable();
bieleluk 0:e36b454cc2e6 85 }
bieleluk 0:e36b454cc2e6 86
bieleluk 0:e36b454cc2e6 87 // clear screen from m line up to n line
bieleluk 0:e36b454cc2e6 88 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 89 void Debug_register::clear_from_n_up_to_m(int m, int n){
bieleluk 0:e36b454cc2e6 90 pc.printf("\033[%d;0H",m);
bieleluk 0:e36b454cc2e6 91 wait(0.1);
bieleluk 0:e36b454cc2e6 92 while (m > n){
bieleluk 0:e36b454cc2e6 93 m--;
bieleluk 0:e36b454cc2e6 94 pc.printf("\033[K\033[%d;0H",m);
bieleluk 0:e36b454cc2e6 95 }
bieleluk 0:e36b454cc2e6 96 pc.printf("\n\r");
bieleluk 0:e36b454cc2e6 97
bieleluk 0:e36b454cc2e6 98 }
bieleluk 0:e36b454cc2e6 99