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

debug_register_print.cpp

Committer:
bieleluk
Date:
2019-05-06
Revision:
0:e36b454cc2e6
Child:
3:3d7837ae4a37

File content as of revision 0:e36b454cc2e6:

#include "Debug.h"

// create object of class Debug_register
//------------------------------------------------------------------------------------------------------------------ 
Debug_register_print::Debug_register_print(PinName tx_pin, PinName rx_pin, int baudrate) : pc(tx_pin,rx_pin, baudrate) {
    init();
}

// init function
//------------------------------------------------------------------------------------------------------------------ 
void Debug_register_print::init() {
    pc.printf("\ec");
    wait_ms(50);
    breakpoint_count=0;
    count_format = 2; //binary
    line_format = 2; //binary
    address_format = 1; //hexa
    register_format = 1; //hexa

}




// perform one breakpoint and print one register
//------------------------------------------------------------------------------------------------------------------  
void Debug_register_print::breakpoint(int line_number, uint32_t address, uint32_t offset){


    breakpoint_count++;

    if( count_format == 1){
        pc.printf("Break no. 0x%3x  ",breakpoint_count);
    }else if( count_format == 2){
        pc.printf("Break no. %3d  ",breakpoint_count);
    }
    
    if( line_format == 1){
        pc.printf("Line no. 0x%3x  ",line_number);
    }else if( line_format == 2){
        pc.printf("Line no. %3d  ",line_number);
    }

    if( address_format == 1){
        pc.printf("Address 0x%8x  ", address + offset);
    }else if( address_format == 2){
        pc.printf("Address %10u  ", address + offset);
    }
    
    uint32_t reg = read_word(address, offset);
    
    if( register_format == 1){
        pc.printf("Value 0x%8x  ", reg);
    }else if( register_format == 2){
        pc.printf("Value %10u  ", reg);
    }else if( register_format == 3){
        pc.printf("Value ");
        for (int i = 0; i < 32; i++){
            if (i%4 == 0) pc.printf(" ");
            pc.printf("%d",reg >> (31 - i));
            reg -= ((reg >> (31 - i)) << (31 - i));
        }
    }
    pc.printf("\n\r");



}

void Debug_register_print::format(int break_number, int line, int address, int value){

    count_format = break_number; //binay
    line_format = line; //binary
    address_format = address; //hexa
    register_format = value; //hexa

}