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

Revision:
0:e36b454cc2e6
Child:
3:3d7837ae4a37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug_register_print.cpp	Mon May 06 00:01:17 2019 +0000
@@ -0,0 +1,77 @@
+#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
+
+}