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

Revision:
18:472b66aeb1f5
Parent:
12:a8ab6e018422
Child:
22:ac9b2cbb31a8
--- a/debug_led.cpp	Mon Jun 03 19:51:15 2019 +0000
+++ b/debug_led.cpp	Sat Mar 20 12:53:37 2021 +0000
@@ -2,59 +2,68 @@
 
 // create object of class Debug_led
 //------------------------------------------------------------------------------------------------------------------
-Debug_led::Debug_led(PinName led_pin, PinName button_pin, char mode[11]) : led(led_pin),button(button_pin) {
+Debug_led::Debug_led(PinName led_pin, PinName button_pin, button_mode mode) : led(led_pin, 0),button(button_pin) {
     init(mode);
 }
 
 // init function
 //------------------------------------------------------------------------------------------------------------------
-void Debug_led::init(char mode[11]) {
+void Debug_led::init(button_mode mode) {
     end_breakpoint = false;
-    number_of_breakpoints = 0;
-    if (strcmp(mode, "BUTTON_VDD") == 0 || strcmp(mode, "BUTTON_VCC") == 0){ //debug button is connected to VDD
+//    number_of_breakpoints = 0;
+    b_mode = mode;
+    
+    // change mode and set up interrupt handler for button pin
+    if (mode == VDD || mode ==BUTTON_VDD || mode == VCC || mode == BUTTON_VCC ){ //debug button is connected to VDD
         button.mode(PullDown); // set internal pull-down for button connected to VCC
-        button_mode = 0; // pull-down->0, pull-up->1
         button.rise(callback(this, &Debug_led::end_break));// set IRQ function for rising edge of pin button
     }else{ // debug button is connected to GND
-        button.mode(PullUp); // set internal pull-up for button connected to VCC
-        button_mode = 1;// pull-down->0, pull-up->1
+        button.mode(PullUp); // set internal pull-up for button connected to GND
         button.fall(callback(this, &Debug_led::end_break)); // set IRQ function for falling edge of pin button
     }
+
 }
 
 // perform one breakpoint
 //------------------------------------------------------------------------------------------------------------------
-void Debug_led::breakpoint(int number) {
-    number_of_breakpoints++; //increment number of breakpoints
-    while(button != button_mode){ //wait until is released in case that button was pushed at the begining of breakpoint
+void Debug_led::breakpoint(int number, int period_ms) {
+//    number_of_breakpoints++; //increment number of breakpoints
+    led = 0;
+    while(button == b_mode){ //wait until the button is released from the previous brakpoint
         wait(0.1);    
     }
     wait(0.1); //debounce time
+    
     end_breakpoint = false;    
     button.enable_irq(); //enable interrupt for button
+    period_ms = (int)(period_ms/2);
     while (!end_breakpoint){ // LED is periodically flashing until the button is pushed
-        if (number > 0){    // the number was inserted
-            flash_n_times(150,number);
-        }else{           // number was not inserted
-            flash_n_times(10,1);
-        }    
+        
+        wait_ms(3*period_ms);// wait for visibility of periodical flashing
+        for(int i = 0; i < (number); i++){
+            led = 1;
+            wait_ms(period_ms);
+            led = 0;
+            wait_ms(period_ms);
+    
+        }
+        led = 0;
     }
     
 }
 
 // flash n times with breakpoint led with period 2*wait_time_ms
 //------------------------------------------------------------------------------------------------------------------
-void Debug_led::flash_n_times(int wait_time_ms, int n) {
-    led = 0;
-    wait_ms(4*wait_time_ms);// wait for visibility of periodical flashing
-    for(int i = 0; i < n; i++){
-        led = 1;
-        wait_ms(wait_time_ms);
-        led = 0;
-        wait_ms(wait_time_ms);
-    }
-    wait_ms(3*wait_time_ms);// wait for visibility of periodical flashing
-}
+//void Debug_led::flash_n_times(int wait_time_ms, int n) {
+//    led = 0;
+//    wait_ms(4*wait_time_ms);// wait for visibility of periodical flashing
+//    for(int i = 0; i < 2*n; i++){
+//        led = !led;
+//        wait_ms(wait_time_ms/2);
+//
+//    }
+//    wait_ms(3*wait_time_ms);// wait for visibility of periodical flashing
+//}
 
 // IRQ function after pushing the button
 //------------------------------------------------------------------------------------------------------------------