debug tool for STM32F042F6P6
Debug.h@24:bc7c4e8f3fe0, 2019-05-27 (annotated)
- Committer:
- bieleluk
- Date:
- Mon May 27 00:15:37 2019 +0000
- Revision:
- 24:bc7c4e8f3fe0
- Parent:
- 23:2e1f37405365
- Child:
- 25:807b447e4995
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bieleluk | 12:5e618e97cb24 | 1 | #pragma once |
bieleluk | 12:5e618e97cb24 | 2 | |
bieleluk | 24:bc7c4e8f3fe0 | 3 | // define constants |
bieleluk | 24:bc7c4e8f3fe0 | 4 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 24:bc7c4e8f3fe0 | 5 | #define AFRL_Offset 0x20 |
bieleluk | 24:bc7c4e8f3fe0 | 6 | #define AFRH_Offset 0x24 |
bieleluk | 24:bc7c4e8f3fe0 | 7 | #define MODER_Offset 0x00 |
bieleluk | 24:bc7c4e8f3fe0 | 8 | #define PUPDR_Offset 0x0C |
bieleluk | 24:bc7c4e8f3fe0 | 9 | #define OSPEEDR_Offset 0x08 |
bieleluk | 24:bc7c4e8f3fe0 | 10 | #define OTYPER_Offset 0x04 |
bieleluk | 24:bc7c4e8f3fe0 | 11 | #define IDR_Offset 0x10 |
bieleluk | 24:bc7c4e8f3fe0 | 12 | #define ODR_Offset 0x14 |
bieleluk | 24:bc7c4e8f3fe0 | 13 | #define gpioa 0x48000000 |
bieleluk | 24:bc7c4e8f3fe0 | 14 | #define gpiob 0x48000400 |
bieleluk | 24:bc7c4e8f3fe0 | 15 | #define gpiof 0x48001400 |
bieleluk | 24:bc7c4e8f3fe0 | 16 | |
bieleluk | 12:5e618e97cb24 | 17 | // include files |
bieleluk | 12:5e618e97cb24 | 18 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 19 | #include "mbed.h" |
bieleluk | 12:5e618e97cb24 | 20 | |
bieleluk | 12:5e618e97cb24 | 21 | // macros |
bieleluk | 12:5e618e97cb24 | 22 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 23 | #define name(var) #var |
bieleluk | 12:5e618e97cb24 | 24 | |
bieleluk | 12:5e618e97cb24 | 25 | |
bieleluk | 12:5e618e97cb24 | 26 | // assembly functions |
bieleluk | 12:5e618e97cb24 | 27 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 28 | extern "C" int check_1_bit(uint32_t gpiox, uint32_t offset, uint32_t pin); |
bieleluk | 12:5e618e97cb24 | 29 | extern "C" int check_2_bit(uint32_t gpiox, uint32_t offset, uint32_t pin); |
bieleluk | 12:5e618e97cb24 | 30 | extern "C" int check_alternative_mode(uint32_t gpiox, uint32_t offset, uint32_t pin); |
bieleluk | 12:5e618e97cb24 | 31 | |
bieleluk | 12:5e618e97cb24 | 32 | // structs |
bieleluk | 12:5e618e97cb24 | 33 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 34 | typedef struct Pin { |
bieleluk | 12:5e618e97cb24 | 35 | char port; |
bieleluk | 12:5e618e97cb24 | 36 | int number; |
bieleluk | 12:5e618e97cb24 | 37 | } pin_t; |
bieleluk | 12:5e618e97cb24 | 38 | |
bieleluk | 12:5e618e97cb24 | 39 | |
bieleluk | 12:5e618e97cb24 | 40 | /** Debug_complete class. |
bieleluk | 15:a9db6d4c2a8f | 41 | * Class for stepping programme and printing actual position and complete configuration of certain peripherals. |
bieleluk | 16:e232e16e4f46 | 42 | * |
bieleluk | 15:a9db6d4c2a8f | 43 | * Functions printf, putc and getc are also defined in the class. |
bieleluk | 16:e232e16e4f46 | 44 | * |
bieleluk | 15:a9db6d4c2a8f | 45 | * Example program: |
bieleluk | 12:5e618e97cb24 | 46 | * @code |
bieleluk | 12:5e618e97cb24 | 47 | * // ---------------------------------------------------------------------------- |
bieleluk | 12:5e618e97cb24 | 48 | * // Author: Lukas Bielesch |
bieleluk | 12:5e618e97cb24 | 49 | * // Department of Measurement, Czech technical university in Prague, Czech Republic |
bieleluk | 12:5e618e97cb24 | 50 | * // Date of publication: 15. Apr 2019 |
bieleluk | 12:5e618e97cb24 | 51 | * // ---------------------------------------------------------------------------- |
bieleluk | 14:5a3b0cabbcd4 | 52 | * #include "Debug.h" |
bieleluk | 12:5e618e97cb24 | 53 | * AnalogIn analog(PA_5); |
bieleluk | 12:5e618e97cb24 | 54 | * PwmOut pwm(PA_6); |
bieleluk | 12:5e618e97cb24 | 55 | * DigitalOut out(PA_4); |
bieleluk | 12:5e618e97cb24 | 56 | * Debug_complete pc(PA_2, PA_3, 115200); |
bieleluk | 12:5e618e97cb24 | 57 | * |
bieleluk | 12:5e618e97cb24 | 58 | * int main(){ |
bieleluk | 12:5e618e97cb24 | 59 | * out = 1; |
bieleluk | 12:5e618e97cb24 | 60 | * pc.breakpoint(__LINE__); |
bieleluk | 12:5e618e97cb24 | 61 | * pwm = 0.5; |
bieleluk | 12:5e618e97cb24 | 62 | * pwm.period(1); |
bieleluk | 12:5e618e97cb24 | 63 | * while(1){ |
bieleluk | 23:2e1f37405365 | 64 | * pwm = analog; |
bieleluk | 12:5e618e97cb24 | 65 | * pc.breakpoint(__LINE__); |
bieleluk | 23:2e1f37405365 | 66 | * wait(0.5); |
bieleluk | 23:2e1f37405365 | 67 | * pwm.period_ms(analog.read_u16()%2000); |
bieleluk | 12:5e618e97cb24 | 68 | * pc.breakpoint(); |
bieleluk | 12:5e618e97cb24 | 69 | * } |
bieleluk | 12:5e618e97cb24 | 70 | * } |
bieleluk | 12:5e618e97cb24 | 71 | * @endcode |
bieleluk | 12:5e618e97cb24 | 72 | */ |
bieleluk | 12:5e618e97cb24 | 73 | class Debug_complete { |
bieleluk | 12:5e618e97cb24 | 74 | public: |
bieleluk | 12:5e618e97cb24 | 75 | |
bieleluk | 12:5e618e97cb24 | 76 | /** Create object of class Debug_complete |
bieleluk | 12:5e618e97cb24 | 77 | * @param tx_pin TX pin of serial port of the board |
bieleluk | 12:5e618e97cb24 | 78 | * @param rx_pin RX pin of serial port of the board |
bieleluk | 12:5e618e97cb24 | 79 | * @param baudrate desired baudrate value of serial port |
bieleluk | 12:5e618e97cb24 | 80 | */ |
bieleluk | 12:5e618e97cb24 | 81 | Debug_complete(PinName tx_pin, PinName rx_pin, int baudrate = 115200); |
bieleluk | 12:5e618e97cb24 | 82 | |
bieleluk | 12:5e618e97cb24 | 83 | /** Perform one breakpoint |
bieleluk | 12:5e618e97cb24 | 84 | * @param line_number line number of the breakpoint |
bieleluk | 12:5e618e97cb24 | 85 | */ |
bieleluk | 12:5e618e97cb24 | 86 | void breakpoint(int line_number = -1); |
bieleluk | 12:5e618e97cb24 | 87 | |
bieleluk | 12:5e618e97cb24 | 88 | |
bieleluk | 12:5e618e97cb24 | 89 | |
bieleluk | 12:5e618e97cb24 | 90 | private: |
bieleluk | 12:5e618e97cb24 | 91 | // objects |
bieleluk | 12:5e618e97cb24 | 92 | Serial pc; //debug serial device |
bieleluk | 12:5e618e97cb24 | 93 | // variables |
bieleluk | 12:5e618e97cb24 | 94 | int breakpoint_count; //stores number of the current breakpoint |
bieleluk | 12:5e618e97cb24 | 95 | //functions |
bieleluk | 12:5e618e97cb24 | 96 | // print alternate function of pin |
bieleluk | 12:5e618e97cb24 | 97 | void print_af_mode( char portx, int pin_number, int af_mode); |
bieleluk | 19:841a5c532145 | 98 | // show configuration of all pins |
bieleluk | 19:841a5c532145 | 99 | void show_all_pins_config(); |
bieleluk | 19:841a5c532145 | 100 | // show configuration of one pin |
bieleluk | 12:5e618e97cb24 | 101 | void show_pin_config(pin_t pin); |
bieleluk | 19:841a5c532145 | 102 | // print config of all timers |
bieleluk | 19:841a5c532145 | 103 | void show_all_timers_config(); |
bieleluk | 12:5e618e97cb24 | 104 | // print configuration of timer |
bieleluk | 12:5e618e97cb24 | 105 | void show_tim_config(int timer); |
bieleluk | 12:5e618e97cb24 | 106 | // print configuration of pin in pwm output mode |
bieleluk | 12:5e618e97cb24 | 107 | void show_pwm_config(int timer, int channel); |
bieleluk | 12:5e618e97cb24 | 108 | // print configuration of pin in analog input mode |
bieleluk | 12:5e618e97cb24 | 109 | void show_analog_config(int channel); |
bieleluk | 24:bc7c4e8f3fe0 | 110 | // print configuration of adc1 |
bieleluk | 12:5e618e97cb24 | 111 | void show_adc1_config(); |
bieleluk | 24:bc7c4e8f3fe0 | 112 | //print configuration of system clock |
bieleluk | 12:5e618e97cb24 | 113 | void show_clk_config(); |
bieleluk | 24:bc7c4e8f3fe0 | 114 | // initialization function |
bieleluk | 12:5e618e97cb24 | 115 | void init(); |
bieleluk | 24:bc7c4e8f3fe0 | 116 | // prit line to serial port |
bieleluk | 19:841a5c532145 | 117 | void line(); |
bieleluk | 12:5e618e97cb24 | 118 | }; |
bieleluk | 12:5e618e97cb24 | 119 |