Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.
debug_led.cpp@0:e36b454cc2e6, 2019-05-06 (annotated)
- Committer:
- bieleluk
- Date:
- Mon May 06 00:01:17 2019 +0000
- Revision:
- 0:e36b454cc2e6
- Child:
- 12:a8ab6e018422
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:e36b454cc2e6 | 5 | Debug_led::Debug_led(PinName led_pin, PinName button_pin, char mode[11]) : led(led_pin),button(button_pin) { |
bieleluk | 0:e36b454cc2e6 | 6 | init(mode); |
bieleluk | 0:e36b454cc2e6 | 7 | } |
bieleluk | 0:e36b454cc2e6 | 8 | |
bieleluk | 0:e36b454cc2e6 | 9 | |
bieleluk | 0:e36b454cc2e6 | 10 | // init function |
bieleluk | 0:e36b454cc2e6 | 11 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 12 | void Debug_led::init(char mode[11]) { |
bieleluk | 0:e36b454cc2e6 | 13 | end_breakpoint = false; |
bieleluk | 0:e36b454cc2e6 | 14 | number_of_breakpoints = 0; |
bieleluk | 0:e36b454cc2e6 | 15 | if (strcmp(mode, "BUTTON_VDD") == 0 || strcmp(mode, "BUTTON_VCC") == 0){ //debug button is connected to VDD |
bieleluk | 0:e36b454cc2e6 | 16 | button.mode(PullDown); |
bieleluk | 0:e36b454cc2e6 | 17 | button_mode = 0; |
bieleluk | 0:e36b454cc2e6 | 18 | button.rise(callback(this, &Debug_led::end_break)); |
bieleluk | 0:e36b454cc2e6 | 19 | }else{ |
bieleluk | 0:e36b454cc2e6 | 20 | button.mode(PullUp); // debug button is connected to GND |
bieleluk | 0:e36b454cc2e6 | 21 | button_mode = 1; |
bieleluk | 0:e36b454cc2e6 | 22 | button.fall(callback(this, &Debug_led::end_break)); |
bieleluk | 0:e36b454cc2e6 | 23 | } |
bieleluk | 0:e36b454cc2e6 | 24 | } |
bieleluk | 0:e36b454cc2e6 | 25 | |
bieleluk | 0:e36b454cc2e6 | 26 | // perform one breakpoint |
bieleluk | 0:e36b454cc2e6 | 27 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 28 | void Debug_led::breakpoint(int number) { |
bieleluk | 0:e36b454cc2e6 | 29 | number_of_breakpoints++; |
bieleluk | 0:e36b454cc2e6 | 30 | while(button != button_mode){ |
bieleluk | 0:e36b454cc2e6 | 31 | wait(0.1); |
bieleluk | 0:e36b454cc2e6 | 32 | } |
bieleluk | 0:e36b454cc2e6 | 33 | wait(0.1); |
bieleluk | 0:e36b454cc2e6 | 34 | end_breakpoint = false; |
bieleluk | 0:e36b454cc2e6 | 35 | button.enable_irq(); |
bieleluk | 0:e36b454cc2e6 | 36 | while (!end_breakpoint){ |
bieleluk | 0:e36b454cc2e6 | 37 | if (number > 0){ // the number was inserted |
bieleluk | 0:e36b454cc2e6 | 38 | flash_n_times(150,number); |
bieleluk | 0:e36b454cc2e6 | 39 | }else{ // number was not inserted |
bieleluk | 0:e36b454cc2e6 | 40 | flash_n_times(10,1); |
bieleluk | 0:e36b454cc2e6 | 41 | } |
bieleluk | 0:e36b454cc2e6 | 42 | } |
bieleluk | 0:e36b454cc2e6 | 43 | |
bieleluk | 0:e36b454cc2e6 | 44 | } |
bieleluk | 0:e36b454cc2e6 | 45 | |
bieleluk | 0:e36b454cc2e6 | 46 | // flash n times with breakpoint led with period 2*wait_time_ms |
bieleluk | 0:e36b454cc2e6 | 47 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 48 | void Debug_led::flash_n_times(int wait_time_ms, int n) { |
bieleluk | 0:e36b454cc2e6 | 49 | led = 0; |
bieleluk | 0:e36b454cc2e6 | 50 | wait_ms(4*wait_time_ms); |
bieleluk | 0:e36b454cc2e6 | 51 | for(int i = 0; i < n; i++){ |
bieleluk | 0:e36b454cc2e6 | 52 | led = 1; |
bieleluk | 0:e36b454cc2e6 | 53 | wait_ms(wait_time_ms); |
bieleluk | 0:e36b454cc2e6 | 54 | led = 0; |
bieleluk | 0:e36b454cc2e6 | 55 | wait_ms(wait_time_ms); |
bieleluk | 0:e36b454cc2e6 | 56 | } |
bieleluk | 0:e36b454cc2e6 | 57 | wait_ms(3*wait_time_ms); |
bieleluk | 0:e36b454cc2e6 | 58 | } |
bieleluk | 0:e36b454cc2e6 | 59 | |
bieleluk | 0:e36b454cc2e6 | 60 | // flash n times with breakpoint led |
bieleluk | 0:e36b454cc2e6 | 61 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 0:e36b454cc2e6 | 62 | void Debug_led::end_break() { |
bieleluk | 0:e36b454cc2e6 | 63 | button.disable_irq(); |
bieleluk | 0:e36b454cc2e6 | 64 | end_breakpoint = true; |
bieleluk | 0:e36b454cc2e6 | 65 | } |
bieleluk | 0:e36b454cc2e6 | 66 | |
bieleluk | 0:e36b454cc2e6 | 67 | |
bieleluk | 0:e36b454cc2e6 | 68 |