debug tool for STM32F042F6P6

Committer:
bieleluk
Date:
Mon May 27 00:23:26 2019 +0000
Revision:
25:807b447e4995
Parent:
24:bc7c4e8f3fe0
Child:
26:541255b7c539

        

Who changed what in which revision?

UserRevisionLine numberNew 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 25:807b447e4995 41 * Class for stepping program, printing actual position and complete configuration of certain peripherals.
bieleluk 16:e232e16e4f46 42 *
bieleluk 16:e232e16e4f46 43 *
bieleluk 15:a9db6d4c2a8f 44 * Example program:
bieleluk 12:5e618e97cb24 45 * @code
bieleluk 12:5e618e97cb24 46 * // ----------------------------------------------------------------------------
bieleluk 12:5e618e97cb24 47 * // Author: Lukas Bielesch
bieleluk 12:5e618e97cb24 48 * // Department of Measurement, Czech technical university in Prague, Czech Republic
bieleluk 12:5e618e97cb24 49 * // Date of publication: 15. Apr 2019
bieleluk 12:5e618e97cb24 50 * // ----------------------------------------------------------------------------
bieleluk 14:5a3b0cabbcd4 51 * #include "Debug.h"
bieleluk 12:5e618e97cb24 52 * AnalogIn analog(PA_5);
bieleluk 12:5e618e97cb24 53 * PwmOut pwm(PA_6);
bieleluk 12:5e618e97cb24 54 * DigitalOut out(PA_4);
bieleluk 12:5e618e97cb24 55 * Debug_complete pc(PA_2, PA_3, 115200);
bieleluk 12:5e618e97cb24 56 *
bieleluk 12:5e618e97cb24 57 * int main(){
bieleluk 12:5e618e97cb24 58 * out = 1;
bieleluk 12:5e618e97cb24 59 * pc.breakpoint(__LINE__);
bieleluk 12:5e618e97cb24 60 * pwm = 0.5;
bieleluk 12:5e618e97cb24 61 * pwm.period(1);
bieleluk 12:5e618e97cb24 62 * while(1){
bieleluk 23:2e1f37405365 63 * pwm = analog;
bieleluk 12:5e618e97cb24 64 * pc.breakpoint(__LINE__);
bieleluk 23:2e1f37405365 65 * wait(0.5);
bieleluk 23:2e1f37405365 66 * pwm.period_ms(analog.read_u16()%2000);
bieleluk 12:5e618e97cb24 67 * pc.breakpoint();
bieleluk 12:5e618e97cb24 68 * }
bieleluk 12:5e618e97cb24 69 * }
bieleluk 12:5e618e97cb24 70 * @endcode
bieleluk 12:5e618e97cb24 71 */
bieleluk 12:5e618e97cb24 72 class Debug_complete {
bieleluk 12:5e618e97cb24 73 public:
bieleluk 12:5e618e97cb24 74
bieleluk 12:5e618e97cb24 75 /** Create object of class Debug_complete
bieleluk 25:807b447e4995 76 * @param tx_pin TX pin of debug serial port of the board
bieleluk 25:807b447e4995 77 * @param rx_pin RX pin of debug serial port of the board
bieleluk 25:807b447e4995 78 * @param baudrate desired baudrate value of serial port, default value is 115200 Bd/s
bieleluk 12:5e618e97cb24 79 */
bieleluk 12:5e618e97cb24 80 Debug_complete(PinName tx_pin, PinName rx_pin, int baudrate = 115200);
bieleluk 12:5e618e97cb24 81
bieleluk 12:5e618e97cb24 82 /** Perform one breakpoint
bieleluk 25:807b447e4995 83 * function stops the program and shows configuration of certain peripherals,
bieleluk 25:807b447e4995 84 * then it waits until any character is received from PC and program continues
bieleluk 25:807b447e4995 85 * @param line_number line number of the breakpoint, __LINE__ is recommended to use
bieleluk 12:5e618e97cb24 86 */
bieleluk 12:5e618e97cb24 87 void breakpoint(int line_number = -1);
bieleluk 12:5e618e97cb24 88
bieleluk 12:5e618e97cb24 89
bieleluk 12:5e618e97cb24 90
bieleluk 12:5e618e97cb24 91 private:
bieleluk 12:5e618e97cb24 92 // objects
bieleluk 12:5e618e97cb24 93 Serial pc; //debug serial device
bieleluk 12:5e618e97cb24 94 // variables
bieleluk 12:5e618e97cb24 95 int breakpoint_count; //stores number of the current breakpoint
bieleluk 12:5e618e97cb24 96 //functions
bieleluk 12:5e618e97cb24 97 // print alternate function of pin
bieleluk 12:5e618e97cb24 98 void print_af_mode( char portx, int pin_number, int af_mode);
bieleluk 19:841a5c532145 99 // show configuration of all pins
bieleluk 19:841a5c532145 100 void show_all_pins_config();
bieleluk 19:841a5c532145 101 // show configuration of one pin
bieleluk 12:5e618e97cb24 102 void show_pin_config(pin_t pin);
bieleluk 19:841a5c532145 103 // print config of all timers
bieleluk 19:841a5c532145 104 void show_all_timers_config();
bieleluk 12:5e618e97cb24 105 // print configuration of timer
bieleluk 12:5e618e97cb24 106 void show_tim_config(int timer);
bieleluk 12:5e618e97cb24 107 // print configuration of pin in pwm output mode
bieleluk 12:5e618e97cb24 108 void show_pwm_config(int timer, int channel);
bieleluk 12:5e618e97cb24 109 // print configuration of pin in analog input mode
bieleluk 12:5e618e97cb24 110 void show_analog_config(int channel);
bieleluk 24:bc7c4e8f3fe0 111 // print configuration of adc1
bieleluk 12:5e618e97cb24 112 void show_adc1_config();
bieleluk 24:bc7c4e8f3fe0 113 //print configuration of system clock
bieleluk 12:5e618e97cb24 114 void show_clk_config();
bieleluk 24:bc7c4e8f3fe0 115 // initialization function
bieleluk 12:5e618e97cb24 116 void init();
bieleluk 24:bc7c4e8f3fe0 117 // prit line to serial port
bieleluk 19:841a5c532145 118 void line();
bieleluk 12:5e618e97cb24 119 };
bieleluk 12:5e618e97cb24 120