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

Committer:
bieleluk
Date:
Sat Mar 20 12:53:37 2021 +0000
Revision:
18:472b66aeb1f5
Parent:
12:a8ab6e018422
Child:
22:ac9b2cbb31a8
Debug_led class changed

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_led
bieleluk 0:e36b454cc2e6 4 //------------------------------------------------------------------------------------------------------------------
bieleluk 18:472b66aeb1f5 5 Debug_led::Debug_led(PinName led_pin, PinName button_pin, button_mode mode) : led(led_pin, 0),button(button_pin) {
bieleluk 0:e36b454cc2e6 6 init(mode);
bieleluk 0:e36b454cc2e6 7 }
bieleluk 0:e36b454cc2e6 8
bieleluk 0:e36b454cc2e6 9 // init function
bieleluk 0:e36b454cc2e6 10 //------------------------------------------------------------------------------------------------------------------
bieleluk 18:472b66aeb1f5 11 void Debug_led::init(button_mode mode) {
bieleluk 0:e36b454cc2e6 12 end_breakpoint = false;
bieleluk 18:472b66aeb1f5 13 // number_of_breakpoints = 0;
bieleluk 18:472b66aeb1f5 14 b_mode = mode;
bieleluk 18:472b66aeb1f5 15
bieleluk 18:472b66aeb1f5 16 // change mode and set up interrupt handler for button pin
bieleluk 18:472b66aeb1f5 17 if (mode == VDD || mode ==BUTTON_VDD || mode == VCC || mode == BUTTON_VCC ){ //debug button is connected to VDD
bieleluk 12:a8ab6e018422 18 button.mode(PullDown); // set internal pull-down for button connected to VCC
bieleluk 12:a8ab6e018422 19 button.rise(callback(this, &Debug_led::end_break));// set IRQ function for rising edge of pin button
bieleluk 12:a8ab6e018422 20 }else{ // debug button is connected to GND
bieleluk 18:472b66aeb1f5 21 button.mode(PullUp); // set internal pull-up for button connected to GND
bieleluk 12:a8ab6e018422 22 button.fall(callback(this, &Debug_led::end_break)); // set IRQ function for falling edge of pin button
bieleluk 0:e36b454cc2e6 23 }
bieleluk 18:472b66aeb1f5 24
bieleluk 0:e36b454cc2e6 25 }
bieleluk 0:e36b454cc2e6 26
bieleluk 0:e36b454cc2e6 27 // perform one breakpoint
bieleluk 0:e36b454cc2e6 28 //------------------------------------------------------------------------------------------------------------------
bieleluk 18:472b66aeb1f5 29 void Debug_led::breakpoint(int number, int period_ms) {
bieleluk 18:472b66aeb1f5 30 // number_of_breakpoints++; //increment number of breakpoints
bieleluk 18:472b66aeb1f5 31 led = 0;
bieleluk 18:472b66aeb1f5 32 while(button == b_mode){ //wait until the button is released from the previous brakpoint
bieleluk 0:e36b454cc2e6 33 wait(0.1);
bieleluk 0:e36b454cc2e6 34 }
bieleluk 12:a8ab6e018422 35 wait(0.1); //debounce time
bieleluk 18:472b66aeb1f5 36
bieleluk 0:e36b454cc2e6 37 end_breakpoint = false;
bieleluk 12:a8ab6e018422 38 button.enable_irq(); //enable interrupt for button
bieleluk 18:472b66aeb1f5 39 period_ms = (int)(period_ms/2);
bieleluk 12:a8ab6e018422 40 while (!end_breakpoint){ // LED is periodically flashing until the button is pushed
bieleluk 18:472b66aeb1f5 41
bieleluk 18:472b66aeb1f5 42 wait_ms(3*period_ms);// wait for visibility of periodical flashing
bieleluk 18:472b66aeb1f5 43 for(int i = 0; i < (number); i++){
bieleluk 18:472b66aeb1f5 44 led = 1;
bieleluk 18:472b66aeb1f5 45 wait_ms(period_ms);
bieleluk 18:472b66aeb1f5 46 led = 0;
bieleluk 18:472b66aeb1f5 47 wait_ms(period_ms);
bieleluk 18:472b66aeb1f5 48
bieleluk 18:472b66aeb1f5 49 }
bieleluk 18:472b66aeb1f5 50 led = 0;
bieleluk 0:e36b454cc2e6 51 }
bieleluk 0:e36b454cc2e6 52
bieleluk 0:e36b454cc2e6 53 }
bieleluk 0:e36b454cc2e6 54
bieleluk 0:e36b454cc2e6 55 // flash n times with breakpoint led with period 2*wait_time_ms
bieleluk 0:e36b454cc2e6 56 //------------------------------------------------------------------------------------------------------------------
bieleluk 18:472b66aeb1f5 57 //void Debug_led::flash_n_times(int wait_time_ms, int n) {
bieleluk 18:472b66aeb1f5 58 // led = 0;
bieleluk 18:472b66aeb1f5 59 // wait_ms(4*wait_time_ms);// wait for visibility of periodical flashing
bieleluk 18:472b66aeb1f5 60 // for(int i = 0; i < 2*n; i++){
bieleluk 18:472b66aeb1f5 61 // led = !led;
bieleluk 18:472b66aeb1f5 62 // wait_ms(wait_time_ms/2);
bieleluk 18:472b66aeb1f5 63 //
bieleluk 18:472b66aeb1f5 64 // }
bieleluk 18:472b66aeb1f5 65 // wait_ms(3*wait_time_ms);// wait for visibility of periodical flashing
bieleluk 18:472b66aeb1f5 66 //}
bieleluk 0:e36b454cc2e6 67
bieleluk 12:a8ab6e018422 68 // IRQ function after pushing the button
bieleluk 0:e36b454cc2e6 69 //------------------------------------------------------------------------------------------------------------------
bieleluk 0:e36b454cc2e6 70 void Debug_led::end_break() {
bieleluk 12:a8ab6e018422 71 button.disable_irq(); //disable interrupt until the next breakpoint
bieleluk 0:e36b454cc2e6 72 end_breakpoint = true;
bieleluk 0:e36b454cc2e6 73 }
bieleluk 0:e36b454cc2e6 74
bieleluk 0:e36b454cc2e6 75
bieleluk 0:e36b454cc2e6 76