Debugging tool for mbed enabled microcontrollers, especially for NUCLEO-F303RE and STM32F042F6P6.
Diff: Debug.h
- Revision:
- 18:472b66aeb1f5
- Parent:
- 17:5b0dd2a6b130
- Child:
- 19:b355ad429450
diff -r 5b0dd2a6b130 -r 472b66aeb1f5 Debug.h --- a/Debug.h Mon Jun 03 19:51:15 2019 +0000 +++ b/Debug.h Sat Mar 20 12:53:37 2021 +0000 @@ -14,6 +14,16 @@ #define max(a, b) (((a) > (b)) ? (a) : (b)) +typedef enum +{ + GND = 0, + BUTTON_GND = 0, + VDD = 1, + BUTTON_VDD = 1, + VCC = 1, + BUTTON_VCC = 1, +} button_mode; + //------------------------------------------------------------------------------------------------------------------ /** Debug_serial class. * Class for stepping programme and printing actual position of the running programme with optional print of one variable (int, float, char or char*). @@ -163,29 +173,38 @@ * Example program: * @code * // ---------------------------------------------------------------------------- + * // Example program of Debug_led class for STM32F042F6P6 * // Author: Lukas Bielesch * // Department of Measurement, Czech technical university in Prague, Czech Republic - * // Date of publication: 13. May 2019 + * // Date of publication: 20. March 2021 * // ---------------------------------------------------------------------------- + * #include "mbed.h" * #include "Debug.h" - * AnalogIn analog(PA_0); - * PwmOut pwm(PA_4); - * DigitalOut out(PA_1); - * Debug_led deb(PA_5, PA_6, "BUTTON_VDD"); //debug led on PA5, debug button connected to VDD on PA6 + * + * PwmOut pwm(PA_4); + * DigitalOut led(PA_1); + * Debug_led deb(PA_5, PA_7, GND); //debug led on PA_5, debug button connected to ground on PA_7 + * * int main(){ * * out = 1; - * deb.breakpoint(1); + * deb.breakpoint(); // breakpoint with periodical flashing with 300 ms period until the button is pressed * pwm = 0.5; * pwm.period(1); - * deb.breakpoint(2); + * deb.breakpoint(2, 200); // breakpoint with periodical double-flashing with 200 ms period * * while(1){ - * deb.breakpoint(); + * deb.breakpoint(3); // breakpoint with periodical triple-flashing until the button is pressed * pwm = pwm + 0.1f; + * + * //init pwm on the pin without pwm functionality causes MbedOS Error + * // error message is sent to uart on PA_2 and PA_3 + * PwmOut pwm2(PA_0); + * * wait(2); * } * } + * * @endcode */ // class Debug_led @@ -195,31 +214,32 @@ /** Create object of class Debug_led * @param led_pin pin of of debug led * @param button_pin pin of of debug button - * @param mode mode of button connection("BUTTON_GND", "BUTTON_VCC", "BUTTON_VDD") + * @param mode (optional): mode of button connection(GND, VCC), default value value is GND */ - Debug_led(PinName led_pin, PinName button_pin, char mode[11] = "BUTTON_GND"); + Debug_led(PinName led_pin, PinName button_pin, button_mode mode = GND); /** Perform one breakpoint - * @param number(optional) number of flashes of periodic flashing of LED during the breakpoint, default is constant flashing + * @param number(optional): number of flashes of LED during the breakpoint, default value is 1 + * @param period_ms(optional): period of flashing of the LED in ms, default value is 300ms */ - void breakpoint(int number = -1); + void breakpoint(int number = 1, int period_ms = 300); private: // objects DigitalOut led; //debug led InterruptIn button; //debug button // variables - int button_mode; //mode of button 1->pullupt, 0->pulldown + int b_mode; // mode of button connection(GND = 0, VCC = 1) volatile bool end_breakpoint; //true when button was pushed - int number_of_breakpoints; //number of the current breakpoint +// int number_of_breakpoints; //number of the current breakpoint /** Initialization */ - void init(char mode[11]); + void init(button_mode mode); /** Blink the debug led n-times with blink period wait_time_ms */ void flash_n_times(int wait_time_ms, int n); - /** IRQ function, end breakpoint after the button is pushed */ + /** IRQ handler function, end breakpoint after the button is pushed */ void end_break(); };