debug tool for STM32F042F6P6
debug_complete.cpp@12:5e618e97cb24, 2019-04-16 (annotated)
- Committer:
- bieleluk
- Date:
- Tue Apr 16 16:26:37 2019 +0000
- Revision:
- 12:5e618e97cb24
- Child:
- 19:841a5c532145
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bieleluk | 12:5e618e97cb24 | 1 | #include "Debug.h" |
bieleluk | 12:5e618e97cb24 | 2 | |
bieleluk | 12:5e618e97cb24 | 3 | |
bieleluk | 12:5e618e97cb24 | 4 | // create object of class Debug_led |
bieleluk | 12:5e618e97cb24 | 5 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 6 | |
bieleluk | 12:5e618e97cb24 | 7 | Debug_complete::Debug_complete(PinName tx_pin, PinName rx_pin, int baudrate) : pc(tx_pin,rx_pin, baudrate) { |
bieleluk | 12:5e618e97cb24 | 8 | init(); |
bieleluk | 12:5e618e97cb24 | 9 | } |
bieleluk | 12:5e618e97cb24 | 10 | |
bieleluk | 12:5e618e97cb24 | 11 | |
bieleluk | 12:5e618e97cb24 | 12 | // init function |
bieleluk | 12:5e618e97cb24 | 13 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 14 | void Debug_complete::init() { |
bieleluk | 12:5e618e97cb24 | 15 | |
bieleluk | 12:5e618e97cb24 | 16 | pc.printf("\ec"); |
bieleluk | 12:5e618e97cb24 | 17 | wait_ms(50); |
bieleluk | 12:5e618e97cb24 | 18 | pc.printf("-----------------\n\r|\e[1m\e[97;40m\e[93;40mBREAKPOINT AREA\e[22m\e[97;40m|\n\r-----------------\n\r\033[s"); |
bieleluk | 12:5e618e97cb24 | 19 | pc.printf("serial successfully initialised\n\r\e[32;40mto start program press any button\e[97;40m"); |
bieleluk | 12:5e618e97cb24 | 20 | breakpoint_count=0; |
bieleluk | 12:5e618e97cb24 | 21 | pc.getc(); |
bieleluk | 12:5e618e97cb24 | 22 | pc.printf("\r\e[2K\e[31;40mprogram is running\e[97;40m\r"); |
bieleluk | 12:5e618e97cb24 | 23 | pc.printf("\033[60;0H------------------\n\r|\e[1m\e[93;40mSERIAL PORT AREA\e[22m\e[97;40m|\n\r------------------\n\r\033[s"); |
bieleluk | 12:5e618e97cb24 | 24 | } |
bieleluk | 12:5e618e97cb24 | 25 | |
bieleluk | 12:5e618e97cb24 | 26 | |
bieleluk | 12:5e618e97cb24 | 27 | // perform one breakpoint |
bieleluk | 12:5e618e97cb24 | 28 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 29 | void Debug_complete::breakpoint(int line_number) { |
bieleluk | 12:5e618e97cb24 | 30 | breakpoint_count++; |
bieleluk | 12:5e618e97cb24 | 31 | clear_from_n_up_to_m(59,3); |
bieleluk | 12:5e618e97cb24 | 32 | if (line_number == -1){ |
bieleluk | 12:5e618e97cb24 | 33 | pc.printf("Breakpoint number %d\tunknown line number \n\r",breakpoint_count); |
bieleluk | 12:5e618e97cb24 | 34 | }else{ |
bieleluk | 12:5e618e97cb24 | 35 | pc.printf("Breakpoint number %d\tline number %d\n\r",breakpoint_count,line_number); |
bieleluk | 12:5e618e97cb24 | 36 | } |
bieleluk | 12:5e618e97cb24 | 37 | |
bieleluk | 12:5e618e97cb24 | 38 | |
bieleluk | 12:5e618e97cb24 | 39 | // show pin configuration |
bieleluk | 12:5e618e97cb24 | 40 | pin_t pins_F042[] = { |
bieleluk | 12:5e618e97cb24 | 41 | {'A',0},{'A',1},{'A',2},{'A',3},{'A',4},{'A',5},{'A',6},{'A',7}, |
bieleluk | 12:5e618e97cb24 | 42 | {'A',9},{'A',10},{'A',13},{'A',14},{'B',1},{'B',8},{'F',0},{'F',1} }; |
bieleluk | 12:5e618e97cb24 | 43 | int num_of_pins = 16; |
bieleluk | 12:5e618e97cb24 | 44 | |
bieleluk | 12:5e618e97cb24 | 45 | show_clk_config(); |
bieleluk | 12:5e618e97cb24 | 46 | show_adc1_config(); |
bieleluk | 12:5e618e97cb24 | 47 | pc.printf("\e[93;40mTimer configuration:\e[97;40m\n\r"); |
bieleluk | 12:5e618e97cb24 | 48 | pc.printf("-----------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 49 | pc.printf("| TIM\t| Prescaler\t| Auto reload value\t| Alignment\t|\n\r"); |
bieleluk | 12:5e618e97cb24 | 50 | pc.printf("-----------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 51 | show_tim_config(1); |
bieleluk | 12:5e618e97cb24 | 52 | pc.printf("\n\r-----------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 53 | show_tim_config(3); |
bieleluk | 12:5e618e97cb24 | 54 | pc.printf("\n\r-----------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 55 | show_tim_config(14); |
bieleluk | 12:5e618e97cb24 | 56 | pc.printf("\n\r-----------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 57 | show_tim_config(16); |
bieleluk | 12:5e618e97cb24 | 58 | pc.printf("\n\r-----------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 59 | pc.printf("\e[93;40mPin configurations:\e[97;40m\n\r"); |
bieleluk | 12:5e618e97cb24 | 60 | pc.printf("-------------------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 61 | pc.printf("| PIN\t| mode of pin\t\t| Configuration\t\t\t| value\t|\n\r"); |
bieleluk | 12:5e618e97cb24 | 62 | pc.printf("-------------------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 63 | |
bieleluk | 12:5e618e97cb24 | 64 | for (int i = 0; i < num_of_pins; i++ ){ |
bieleluk | 12:5e618e97cb24 | 65 | show_pin_config(pins_F042[i]); |
bieleluk | 12:5e618e97cb24 | 66 | pc.printf("-------------------------------------------------------------------------\n\r"); |
bieleluk | 12:5e618e97cb24 | 67 | } |
bieleluk | 12:5e618e97cb24 | 68 | |
bieleluk | 12:5e618e97cb24 | 69 | pc.printf("\n\r\e[32;40mto continue press any button\e[97;40m"); |
bieleluk | 12:5e618e97cb24 | 70 | pc.getc(); |
bieleluk | 12:5e618e97cb24 | 71 | pc.printf("\r\e[2K\e[31;40mprogram is running\e[97;40m\n\r"); |
bieleluk | 12:5e618e97cb24 | 72 | pc.printf("\e[u"); |
bieleluk | 12:5e618e97cb24 | 73 | wait(0.1); |
bieleluk | 12:5e618e97cb24 | 74 | } |
bieleluk | 12:5e618e97cb24 | 75 | |
bieleluk | 12:5e618e97cb24 | 76 | |
bieleluk | 12:5e618e97cb24 | 77 | // show configuration of pin |
bieleluk | 12:5e618e97cb24 | 78 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 79 | void Debug_complete::show_pin_config(pin_t pin){ |
bieleluk | 12:5e618e97cb24 | 80 | char portx = pin.port; |
bieleluk | 12:5e618e97cb24 | 81 | int pin_number = pin.number; |
bieleluk | 12:5e618e97cb24 | 82 | |
bieleluk | 12:5e618e97cb24 | 83 | // definition of important constants |
bieleluk | 12:5e618e97cb24 | 84 | const uint32_t AFRL_Offset = 0x20; |
bieleluk | 12:5e618e97cb24 | 85 | const uint32_t AFRH_Offset = 0x24; |
bieleluk | 12:5e618e97cb24 | 86 | |
bieleluk | 12:5e618e97cb24 | 87 | const uint32_t MODER_Offset = 0x00; |
bieleluk | 12:5e618e97cb24 | 88 | const uint32_t PUPDR_Offset = 0x0C; |
bieleluk | 12:5e618e97cb24 | 89 | const uint32_t OSPEEDR_Offset = 0x08; |
bieleluk | 12:5e618e97cb24 | 90 | |
bieleluk | 12:5e618e97cb24 | 91 | const uint32_t OTYPER_Offset = 0x04; |
bieleluk | 12:5e618e97cb24 | 92 | const uint32_t IDR_Offset = 0x10; |
bieleluk | 12:5e618e97cb24 | 93 | const uint32_t ODR_Offset = 0x14; |
bieleluk | 12:5e618e97cb24 | 94 | |
bieleluk | 12:5e618e97cb24 | 95 | const uint32_t gpioa = 0x48000000; |
bieleluk | 12:5e618e97cb24 | 96 | const uint32_t gpiob = 0x48000400; |
bieleluk | 12:5e618e97cb24 | 97 | const uint32_t gpiof = 0x48001400; |
bieleluk | 12:5e618e97cb24 | 98 | |
bieleluk | 12:5e618e97cb24 | 99 | uint32_t reg_0; |
bieleluk | 12:5e618e97cb24 | 100 | switch (portx){ |
bieleluk | 12:5e618e97cb24 | 101 | case 'A': |
bieleluk | 12:5e618e97cb24 | 102 | case 'a': |
bieleluk | 12:5e618e97cb24 | 103 | reg_0 = gpioa; |
bieleluk | 12:5e618e97cb24 | 104 | pc.printf("| PA"); |
bieleluk | 12:5e618e97cb24 | 105 | break; |
bieleluk | 12:5e618e97cb24 | 106 | case 'B': |
bieleluk | 12:5e618e97cb24 | 107 | case 'b': |
bieleluk | 12:5e618e97cb24 | 108 | reg_0 = gpiob; |
bieleluk | 12:5e618e97cb24 | 109 | pc.printf("| PB"); |
bieleluk | 12:5e618e97cb24 | 110 | break; |
bieleluk | 12:5e618e97cb24 | 111 | case 'f': |
bieleluk | 12:5e618e97cb24 | 112 | case 'F': |
bieleluk | 12:5e618e97cb24 | 113 | reg_0 = gpiof; |
bieleluk | 12:5e618e97cb24 | 114 | pc.printf("| PF"); |
bieleluk | 12:5e618e97cb24 | 115 | break; |
bieleluk | 12:5e618e97cb24 | 116 | default: |
bieleluk | 12:5e618e97cb24 | 117 | pc.printf("non existing port\n\r"); |
bieleluk | 12:5e618e97cb24 | 118 | return; |
bieleluk | 12:5e618e97cb24 | 119 | |
bieleluk | 12:5e618e97cb24 | 120 | } |
bieleluk | 12:5e618e97cb24 | 121 | pc.printf("%d\t| ",pin_number); |
bieleluk | 12:5e618e97cb24 | 122 | |
bieleluk | 12:5e618e97cb24 | 123 | // check the mode of pin |
bieleluk | 12:5e618e97cb24 | 124 | int return_value; |
bieleluk | 12:5e618e97cb24 | 125 | uint32_t reg_1 = MODER_Offset; |
bieleluk | 12:5e618e97cb24 | 126 | return_value = check_2_bit(reg_0,reg_1,pin_number); |
bieleluk | 12:5e618e97cb24 | 127 | |
bieleluk | 12:5e618e97cb24 | 128 | // check other meaningful features depending on mode of the pin |
bieleluk | 12:5e618e97cb24 | 129 | if (return_value == 0){ //input mode |
bieleluk | 12:5e618e97cb24 | 130 | pc.printf("input mode\t\t| "); |
bieleluk | 12:5e618e97cb24 | 131 | // chceck pupdr register |
bieleluk | 12:5e618e97cb24 | 132 | reg_1 = PUPDR_Offset; |
bieleluk | 12:5e618e97cb24 | 133 | return_value = check_2_bit(reg_0,reg_1,pin_number); |
bieleluk | 12:5e618e97cb24 | 134 | if (return_value == 0){ // pull none |
bieleluk | 12:5e618e97cb24 | 135 | pc.printf("no resistor\t|\t\t"); |
bieleluk | 12:5e618e97cb24 | 136 | }else if (return_value == 1){ // pull up |
bieleluk | 12:5e618e97cb24 | 137 | pc.printf("pull up\t|\t\t"); |
bieleluk | 12:5e618e97cb24 | 138 | }else if (return_value == 2){ // pull down |
bieleluk | 12:5e618e97cb24 | 139 | pc.printf("pull down\t|\t\t"); |
bieleluk | 12:5e618e97cb24 | 140 | }else{ |
bieleluk | 12:5e618e97cb24 | 141 | pc.printf("ERROR, reserved value\n\r"); |
bieleluk | 12:5e618e97cb24 | 142 | return; |
bieleluk | 12:5e618e97cb24 | 143 | } |
bieleluk | 12:5e618e97cb24 | 144 | pc.printf("| "); |
bieleluk | 12:5e618e97cb24 | 145 | // check input value |
bieleluk | 12:5e618e97cb24 | 146 | reg_1 = IDR_Offset; |
bieleluk | 12:5e618e97cb24 | 147 | return_value = check_1_bit(reg_0,reg_1,pin_number); |
bieleluk | 12:5e618e97cb24 | 148 | if (return_value == 0){ // log.0 |
bieleluk | 12:5e618e97cb24 | 149 | pc.printf("log.0"); |
bieleluk | 12:5e618e97cb24 | 150 | }else { // log.1 |
bieleluk | 12:5e618e97cb24 | 151 | pc.printf("log.1"); |
bieleluk | 12:5e618e97cb24 | 152 | } |
bieleluk | 12:5e618e97cb24 | 153 | pc.printf(" |\n\r"); |
bieleluk | 12:5e618e97cb24 | 154 | }else if (return_value == 1){ //output mode |
bieleluk | 12:5e618e97cb24 | 155 | pc.printf("output mode\t\t| "); |
bieleluk | 12:5e618e97cb24 | 156 | |
bieleluk | 12:5e618e97cb24 | 157 | // check output mode register |
bieleluk | 12:5e618e97cb24 | 158 | reg_1 = OTYPER_Offset; |
bieleluk | 12:5e618e97cb24 | 159 | return_value = check_1_bit(reg_0,reg_1,pin_number); |
bieleluk | 12:5e618e97cb24 | 160 | if (return_value == 0){ // push pull |
bieleluk | 12:5e618e97cb24 | 161 | pc.printf("push pull\t"); |
bieleluk | 12:5e618e97cb24 | 162 | }else{ // open drain |
bieleluk | 12:5e618e97cb24 | 163 | pc.printf("open drain\t"); |
bieleluk | 12:5e618e97cb24 | 164 | } |
bieleluk | 12:5e618e97cb24 | 165 | pc.printf("| "); |
bieleluk | 12:5e618e97cb24 | 166 | |
bieleluk | 12:5e618e97cb24 | 167 | // check speed of output pin |
bieleluk | 12:5e618e97cb24 | 168 | reg_1 = OSPEEDR_Offset; |
bieleluk | 12:5e618e97cb24 | 169 | return_value = check_2_bit(reg_0,reg_1,pin_number); |
bieleluk | 12:5e618e97cb24 | 170 | if (return_value == 0 || return_value == 2){ // low speed |
bieleluk | 12:5e618e97cb24 | 171 | pc.printf("low speed\t"); |
bieleluk | 12:5e618e97cb24 | 172 | }else if (return_value == 1){ // medium speed |
bieleluk | 12:5e618e97cb24 | 173 | pc.printf("medium speed\t"); |
bieleluk | 12:5e618e97cb24 | 174 | }else{ // high speed |
bieleluk | 12:5e618e97cb24 | 175 | pc.printf("high speed\t"); |
bieleluk | 12:5e618e97cb24 | 176 | } |
bieleluk | 12:5e618e97cb24 | 177 | pc.printf("| "); |
bieleluk | 12:5e618e97cb24 | 178 | |
bieleluk | 12:5e618e97cb24 | 179 | // check output value |
bieleluk | 12:5e618e97cb24 | 180 | reg_1 = ODR_Offset; |
bieleluk | 12:5e618e97cb24 | 181 | return_value = check_1_bit(reg_0,reg_1,pin_number); |
bieleluk | 12:5e618e97cb24 | 182 | if (return_value == 0){ // log.0 |
bieleluk | 12:5e618e97cb24 | 183 | pc.printf("log.0"); |
bieleluk | 12:5e618e97cb24 | 184 | }else{ // log.1 |
bieleluk | 12:5e618e97cb24 | 185 | pc.printf("log.1"); |
bieleluk | 12:5e618e97cb24 | 186 | } |
bieleluk | 12:5e618e97cb24 | 187 | pc.printf("\n\r"); |
bieleluk | 12:5e618e97cb24 | 188 | }else if(return_value == 2){ // alternate mode |
bieleluk | 12:5e618e97cb24 | 189 | pc.printf("alternate mode\t| "); |
bieleluk | 12:5e618e97cb24 | 190 | int af_mode; |
bieleluk | 12:5e618e97cb24 | 191 | // chceck whether the pin belongs between the lower 8 pins and use AFRL register |
bieleluk | 12:5e618e97cb24 | 192 | // or he pin belongs between the higher 8 pins and use AFRH register |
bieleluk | 12:5e618e97cb24 | 193 | if (pin_number <= 7){ |
bieleluk | 12:5e618e97cb24 | 194 | af_mode = check_alternative_mode(reg_0,AFRL_Offset,pin_number); |
bieleluk | 12:5e618e97cb24 | 195 | }else{ |
bieleluk | 12:5e618e97cb24 | 196 | af_mode = check_alternative_mode(reg_0,AFRH_Offset,pin_number - 8); |
bieleluk | 12:5e618e97cb24 | 197 | } |
bieleluk | 12:5e618e97cb24 | 198 | // print exact alternate functionality |
bieleluk | 12:5e618e97cb24 | 199 | print_af_mode(portx, pin_number, af_mode); |
bieleluk | 12:5e618e97cb24 | 200 | |
bieleluk | 12:5e618e97cb24 | 201 | }else{ //analog mode |
bieleluk | 12:5e618e97cb24 | 202 | pc.printf("analog mode\t\t|"); |
bieleluk | 12:5e618e97cb24 | 203 | if ((portx == 'A' || portx == 'a') && pin_number >= 0 && pin_number <= 7){ |
bieleluk | 12:5e618e97cb24 | 204 | show_analog_config(pin_number); |
bieleluk | 12:5e618e97cb24 | 205 | }else if((portx == 'B' || portx == 'b') && pin_number == 1){ |
bieleluk | 12:5e618e97cb24 | 206 | show_analog_config(9); |
bieleluk | 12:5e618e97cb24 | 207 | }else{ |
bieleluk | 12:5e618e97cb24 | 208 | pc.printf("error"); |
bieleluk | 12:5e618e97cb24 | 209 | return; |
bieleluk | 12:5e618e97cb24 | 210 | } |
bieleluk | 12:5e618e97cb24 | 211 | |
bieleluk | 12:5e618e97cb24 | 212 | } |
bieleluk | 12:5e618e97cb24 | 213 | } |
bieleluk | 12:5e618e97cb24 | 214 | |
bieleluk | 12:5e618e97cb24 | 215 | // print alternate function of pin |
bieleluk | 12:5e618e97cb24 | 216 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 217 | void Debug_complete::print_af_mode( char portx, int pin_number, int af_mode){ |
bieleluk | 12:5e618e97cb24 | 218 | if ( (portx == 'a' || portx == 'A') && pin_number == 0 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 219 | pc.printf("USART2_CTS"); |
bieleluk | 12:5e618e97cb24 | 220 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 0 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 221 | pc.printf("TIM2_CH1_ETR"); |
bieleluk | 12:5e618e97cb24 | 222 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 0 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 223 | pc.printf("TSC_G1_IO1"); |
bieleluk | 12:5e618e97cb24 | 224 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 1 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 225 | pc.printf("EVENTOUT"); |
bieleluk | 12:5e618e97cb24 | 226 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 1 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 227 | pc.printf("USART2_RTS"); |
bieleluk | 12:5e618e97cb24 | 228 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 1 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 229 | pc.printf("TIM2_CH2"); |
bieleluk | 12:5e618e97cb24 | 230 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 1 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 231 | pc.printf("TSC_G1_IO2"); |
bieleluk | 12:5e618e97cb24 | 232 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 2 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 233 | pc.printf("USART2_TX"); |
bieleluk | 12:5e618e97cb24 | 234 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 2 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 235 | pc.printf("TIM2_CH3"); |
bieleluk | 12:5e618e97cb24 | 236 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 2 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 237 | pc.printf("TSC_G1_IO3"); |
bieleluk | 12:5e618e97cb24 | 238 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 3 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 239 | pc.printf("USART2_RX"); |
bieleluk | 12:5e618e97cb24 | 240 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 3 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 241 | pc.printf("TIM2_CH4"); |
bieleluk | 12:5e618e97cb24 | 242 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 3 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 243 | pc.printf("TSC_G1_IO4"); |
bieleluk | 12:5e618e97cb24 | 244 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 4 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 245 | pc.printf("SPI1_NSS, I2S1_WS"); |
bieleluk | 12:5e618e97cb24 | 246 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 4 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 247 | pc.printf("USART2_CK"); |
bieleluk | 12:5e618e97cb24 | 248 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 4 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 249 | pc.printf("USB_NOE"); |
bieleluk | 12:5e618e97cb24 | 250 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 4 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 251 | pc.printf("TSC_G2_IO1"); |
bieleluk | 12:5e618e97cb24 | 252 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 4 && af_mode == 4){ |
bieleluk | 12:5e618e97cb24 | 253 | show_pwm_config(14, 1); |
bieleluk | 12:5e618e97cb24 | 254 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 5 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 255 | pc.printf("SPI1_SCK, I2S1_CK"); |
bieleluk | 12:5e618e97cb24 | 256 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 5 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 257 | pc.printf("CEC"); |
bieleluk | 12:5e618e97cb24 | 258 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 5 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 259 | pc.printf("TIM2_CH1_ETR"); |
bieleluk | 12:5e618e97cb24 | 260 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 5 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 261 | pc.printf("TSC_G2_IO2"); |
bieleluk | 12:5e618e97cb24 | 262 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 6 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 263 | pc.printf("SPI1_MISO, I2S1_MCK"); |
bieleluk | 12:5e618e97cb24 | 264 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 6 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 265 | show_pwm_config(3, 1); |
bieleluk | 12:5e618e97cb24 | 266 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 6 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 267 | pc.printf("TIM1_BKIN"); |
bieleluk | 12:5e618e97cb24 | 268 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 6 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 269 | pc.printf("TSC_G2_IO3"); |
bieleluk | 12:5e618e97cb24 | 270 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 6 && af_mode == 5){ |
bieleluk | 12:5e618e97cb24 | 271 | pc.printf("TIM16_CH1"); |
bieleluk | 12:5e618e97cb24 | 272 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 6 && af_mode == 6){ |
bieleluk | 12:5e618e97cb24 | 273 | pc.printf("EVENTOUT"); |
bieleluk | 12:5e618e97cb24 | 274 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 275 | pc.printf("SPI1_MOSI, I2S1_SD"); |
bieleluk | 12:5e618e97cb24 | 276 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 277 | pc.printf("TIM3_CH2"); |
bieleluk | 12:5e618e97cb24 | 278 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 279 | show_pwm_config(1, 1); |
bieleluk | 12:5e618e97cb24 | 280 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 281 | pc.printf("TSC_G2_IO4"); |
bieleluk | 12:5e618e97cb24 | 282 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 4){ |
bieleluk | 12:5e618e97cb24 | 283 | pc.printf("TIM14_CH1"); |
bieleluk | 12:5e618e97cb24 | 284 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 5){ |
bieleluk | 12:5e618e97cb24 | 285 | pc.printf("TIM17_CH1"); |
bieleluk | 12:5e618e97cb24 | 286 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 7 && af_mode == 6){ |
bieleluk | 12:5e618e97cb24 | 287 | pc.printf("EVENTOUT"); |
bieleluk | 12:5e618e97cb24 | 288 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 9 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 289 | pc.printf("USART1_TX"); |
bieleluk | 12:5e618e97cb24 | 290 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 9 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 291 | show_pwm_config(1, 2); |
bieleluk | 12:5e618e97cb24 | 292 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 9 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 293 | pc.printf("TSC_G4_IO1"); |
bieleluk | 12:5e618e97cb24 | 294 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 9 && af_mode == 4){ |
bieleluk | 12:5e618e97cb24 | 295 | pc.printf("I2C1_SCL"); |
bieleluk | 12:5e618e97cb24 | 296 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 9 && af_mode == 5){ |
bieleluk | 12:5e618e97cb24 | 297 | pc.printf("MCO"); |
bieleluk | 12:5e618e97cb24 | 298 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 10 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 299 | pc.printf("TIM17_BKIN"); |
bieleluk | 12:5e618e97cb24 | 300 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 10 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 301 | pc.printf("USART1_RX"); |
bieleluk | 12:5e618e97cb24 | 302 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 10 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 303 | show_pwm_config(1, 3); |
bieleluk | 12:5e618e97cb24 | 304 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 10 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 305 | pc.printf("TSC_G4_IO2"); |
bieleluk | 12:5e618e97cb24 | 306 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 10 && af_mode == 4){ |
bieleluk | 12:5e618e97cb24 | 307 | pc.printf("I2C1_SDA"); |
bieleluk | 12:5e618e97cb24 | 308 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 13 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 309 | pc.printf("SWDIO"); |
bieleluk | 12:5e618e97cb24 | 310 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 13 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 311 | pc.printf("IR_OUT"); |
bieleluk | 12:5e618e97cb24 | 312 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 13 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 313 | pc.printf("USB_NOE"); |
bieleluk | 12:5e618e97cb24 | 314 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 14 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 315 | pc.printf("SWCLK"); |
bieleluk | 12:5e618e97cb24 | 316 | }else if ( (portx == 'a' || portx == 'A') && pin_number == 14 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 317 | pc.printf("USART2_TX"); |
bieleluk | 12:5e618e97cb24 | 318 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 1 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 319 | pc.printf("TIM14_CH1"); |
bieleluk | 12:5e618e97cb24 | 320 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 1 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 321 | pc.printf("TIM3_CH4"); |
bieleluk | 12:5e618e97cb24 | 322 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 1 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 323 | show_pwm_config(1, 3); |
bieleluk | 12:5e618e97cb24 | 324 | }else if ( (portx == 'a' || portx == 'B') && pin_number == 1 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 325 | pc.printf("TSC_G3_IO3"); |
bieleluk | 12:5e618e97cb24 | 326 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 8 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 327 | pc.printf("CEC"); |
bieleluk | 12:5e618e97cb24 | 328 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 8 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 329 | pc.printf("I2C1_SCL"); |
bieleluk | 12:5e618e97cb24 | 330 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 8 && af_mode == 2){ |
bieleluk | 12:5e618e97cb24 | 331 | show_pwm_config(16, 1); |
bieleluk | 12:5e618e97cb24 | 332 | }else if ( (portx == 'b' || portx == 'B') && pin_number == 8 && af_mode == 3){ |
bieleluk | 12:5e618e97cb24 | 333 | pc.printf("TSC_SYNC"); |
bieleluk | 12:5e618e97cb24 | 334 | }else if ( (portx == 'a' || portx == 'B') && pin_number == 8 && af_mode == 4){ |
bieleluk | 12:5e618e97cb24 | 335 | pc.printf("CAN_RX"); |
bieleluk | 12:5e618e97cb24 | 336 | }else if ( (portx == 'f' || portx == 'F') && pin_number == 0 && af_mode == 0){ |
bieleluk | 12:5e618e97cb24 | 337 | pc.printf("CRS_SYNC"); |
bieleluk | 12:5e618e97cb24 | 338 | }else if ( (portx == 'f' || portx == 'F') && pin_number == 0 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 339 | pc.printf("I2C1_SDA"); |
bieleluk | 12:5e618e97cb24 | 340 | }else if ( (portx == 'f' || portx == 'F') && pin_number == 1 && af_mode == 1){ |
bieleluk | 12:5e618e97cb24 | 341 | pc.printf("I2C1_SCL"); |
bieleluk | 12:5e618e97cb24 | 342 | }else{ |
bieleluk | 12:5e618e97cb24 | 343 | pc.printf("ERROR"); |
bieleluk | 12:5e618e97cb24 | 344 | } |
bieleluk | 12:5e618e97cb24 | 345 | pc.printf("\t|\n\r"); |
bieleluk | 12:5e618e97cb24 | 346 | } |
bieleluk | 12:5e618e97cb24 | 347 | |
bieleluk | 12:5e618e97cb24 | 348 | // show configuration of pin in analog mode |
bieleluk | 12:5e618e97cb24 | 349 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 350 | void Debug_complete::show_analog_config(int channel){ |
bieleluk | 12:5e618e97cb24 | 351 | int config = ADC1->CHSELR; |
bieleluk | 12:5e618e97cb24 | 352 | ADC1->CR|=ADC_CR_ADSTP; |
bieleluk | 12:5e618e97cb24 | 353 | ADC1->CR &= !ADC_CR_ADSTART; |
bieleluk | 12:5e618e97cb24 | 354 | ADC1->CHSELR = 1 << channel; |
bieleluk | 12:5e618e97cb24 | 355 | |
bieleluk | 12:5e618e97cb24 | 356 | ADC1->CR |= ADC_CR_ADEN; |
bieleluk | 12:5e618e97cb24 | 357 | while ( (ADC1->ISR & ADC_ISR_ADRDY) == 0){} |
bieleluk | 12:5e618e97cb24 | 358 | ADC1->CR |= ADC_CR_ADSTART; /* Start the ADC conversion */ |
bieleluk | 12:5e618e97cb24 | 359 | while ((ADC1->ISR & ADC_ISR_EOC) == 0){} |
bieleluk | 12:5e618e97cb24 | 360 | |
bieleluk | 12:5e618e97cb24 | 361 | pc.printf("\t\t|\t\t| %d\t|\n\r",ADC1->DR); |
bieleluk | 12:5e618e97cb24 | 362 | ADC1->CHSELR = config; |
bieleluk | 12:5e618e97cb24 | 363 | } |
bieleluk | 12:5e618e97cb24 | 364 | |
bieleluk | 12:5e618e97cb24 | 365 | // print configuration of pin in pwm output mode |
bieleluk | 12:5e618e97cb24 | 366 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 367 | void Debug_complete::show_pwm_config(int timer, int channel){ |
bieleluk | 12:5e618e97cb24 | 368 | |
bieleluk | 12:5e618e97cb24 | 369 | pc.printf("CCR = "); |
bieleluk | 12:5e618e97cb24 | 370 | if (timer == 1 && channel == 1){ |
bieleluk | 12:5e618e97cb24 | 371 | pc.printf("%3d",TIM1->CCR1); |
bieleluk | 12:5e618e97cb24 | 372 | }else if (timer == 1 && channel == 2 ){ |
bieleluk | 12:5e618e97cb24 | 373 | pc.printf("%3d",TIM1->CCR2); |
bieleluk | 12:5e618e97cb24 | 374 | }else if (timer == 1 && channel == 3 ){ |
bieleluk | 12:5e618e97cb24 | 375 | pc.printf("%3d",TIM1->CCR3); |
bieleluk | 12:5e618e97cb24 | 376 | }else if (timer == 3 && channel == 1){ |
bieleluk | 12:5e618e97cb24 | 377 | pc.printf("%3d",TIM3->CCR1); |
bieleluk | 12:5e618e97cb24 | 378 | }else if (timer == 14 && channel == 1){ |
bieleluk | 12:5e618e97cb24 | 379 | pc.printf("%3d",TIM14->CCR1); |
bieleluk | 12:5e618e97cb24 | 380 | }else if (timer == 16 && channel == 1){ |
bieleluk | 12:5e618e97cb24 | 381 | pc.printf("%3d",TIM16->CCR1); |
bieleluk | 12:5e618e97cb24 | 382 | } |
bieleluk | 12:5e618e97cb24 | 383 | } |
bieleluk | 12:5e618e97cb24 | 384 | |
bieleluk | 12:5e618e97cb24 | 385 | // print configuration of timer |
bieleluk | 12:5e618e97cb24 | 386 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 387 | void Debug_complete::show_tim_config(int timer){ |
bieleluk | 12:5e618e97cb24 | 388 | int alignment; |
bieleluk | 12:5e618e97cb24 | 389 | pc.printf("| TIM%d\t| ",timer); |
bieleluk | 12:5e618e97cb24 | 390 | if (timer == 1){ |
bieleluk | 12:5e618e97cb24 | 391 | pc.printf("%3d\t\t| %5d\t\t| ",TIM1->PSC,TIM1->ARR); |
bieleluk | 12:5e618e97cb24 | 392 | alignment = ((TIM1->CR1&TIM_CR1_CMS)>>5); |
bieleluk | 12:5e618e97cb24 | 393 | if (alignment){ |
bieleluk | 12:5e618e97cb24 | 394 | pc.printf("center mode %d\t|",alignment); |
bieleluk | 12:5e618e97cb24 | 395 | }else{ |
bieleluk | 12:5e618e97cb24 | 396 | pc.printf("edge mode\t|"); |
bieleluk | 12:5e618e97cb24 | 397 | } |
bieleluk | 12:5e618e97cb24 | 398 | }else if (timer == 3){ |
bieleluk | 12:5e618e97cb24 | 399 | pc.printf("%3d\t\t| %5d\t\t| ",TIM3->PSC,TIM3->ARR); |
bieleluk | 12:5e618e97cb24 | 400 | alignment = ((TIM3->CR1&TIM_CR1_CMS)>>5); |
bieleluk | 12:5e618e97cb24 | 401 | if (alignment){ |
bieleluk | 12:5e618e97cb24 | 402 | pc.printf("center mode %d\t|",alignment); |
bieleluk | 12:5e618e97cb24 | 403 | }else{ |
bieleluk | 12:5e618e97cb24 | 404 | pc.printf("edge mode\t|"); |
bieleluk | 12:5e618e97cb24 | 405 | } |
bieleluk | 12:5e618e97cb24 | 406 | }else if (timer == 14){ |
bieleluk | 12:5e618e97cb24 | 407 | pc.printf("%3d\t\t| %5d\t\t| ",TIM14->PSC,TIM14->ARR); |
bieleluk | 12:5e618e97cb24 | 408 | alignment = ((TIM14->CR1&TIM_CR1_CMS)>>5); |
bieleluk | 12:5e618e97cb24 | 409 | if (alignment){ |
bieleluk | 12:5e618e97cb24 | 410 | pc.printf("center mode %d\t|",alignment); |
bieleluk | 12:5e618e97cb24 | 411 | }else{ |
bieleluk | 12:5e618e97cb24 | 412 | pc.printf("edge mode\t|"); |
bieleluk | 12:5e618e97cb24 | 413 | } |
bieleluk | 12:5e618e97cb24 | 414 | }else if (timer == 16){ |
bieleluk | 12:5e618e97cb24 | 415 | pc.printf("%3d\t\t| %5d\t\t| ",TIM16->PSC,TIM16->ARR); |
bieleluk | 12:5e618e97cb24 | 416 | alignment = ((TIM16->CR1&TIM_CR1_CMS)>>5); |
bieleluk | 12:5e618e97cb24 | 417 | if (alignment){ |
bieleluk | 12:5e618e97cb24 | 418 | pc.printf("center mode %d\t|",alignment); |
bieleluk | 12:5e618e97cb24 | 419 | }else{ |
bieleluk | 12:5e618e97cb24 | 420 | pc.printf("edge mode\t|"); |
bieleluk | 12:5e618e97cb24 | 421 | } |
bieleluk | 12:5e618e97cb24 | 422 | } |
bieleluk | 12:5e618e97cb24 | 423 | } |
bieleluk | 12:5e618e97cb24 | 424 | |
bieleluk | 12:5e618e97cb24 | 425 | // print configuration of adc1 converter |
bieleluk | 12:5e618e97cb24 | 426 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 427 | void Debug_complete::show_adc1_config(){ |
bieleluk | 12:5e618e97cb24 | 428 | |
bieleluk | 12:5e618e97cb24 | 429 | pc.printf("\e[93;40mADC configuration:\e[97;40m\n\r"); |
bieleluk | 12:5e618e97cb24 | 430 | |
bieleluk | 12:5e618e97cb24 | 431 | //configuration of adc clock |
bieleluk | 12:5e618e97cb24 | 432 | pc.printf("ADC Clock = "); |
bieleluk | 12:5e618e97cb24 | 433 | switch ((ADC1->CFGR2&ADC_CFGR2_CKMODE)>>30){ |
bieleluk | 12:5e618e97cb24 | 434 | case 0: |
bieleluk | 12:5e618e97cb24 | 435 | pc.printf("ADCCLK"); |
bieleluk | 12:5e618e97cb24 | 436 | break; |
bieleluk | 12:5e618e97cb24 | 437 | case 1: |
bieleluk | 12:5e618e97cb24 | 438 | pc.printf("PCLK/2"); |
bieleluk | 12:5e618e97cb24 | 439 | break; |
bieleluk | 12:5e618e97cb24 | 440 | case 2: |
bieleluk | 12:5e618e97cb24 | 441 | pc.printf("PCLK/4"); |
bieleluk | 12:5e618e97cb24 | 442 | break; |
bieleluk | 12:5e618e97cb24 | 443 | case 3: |
bieleluk | 12:5e618e97cb24 | 444 | pc.printf("Reserved"); |
bieleluk | 12:5e618e97cb24 | 445 | break; |
bieleluk | 12:5e618e97cb24 | 446 | |
bieleluk | 12:5e618e97cb24 | 447 | } |
bieleluk | 12:5e618e97cb24 | 448 | |
bieleluk | 12:5e618e97cb24 | 449 | // resolution of adc1 |
bieleluk | 12:5e618e97cb24 | 450 | pc.printf("\t Resolution = %d bits\t Sampling time = ", 12-2*((ADC1->CFGR1&ADC_CFGR1_RES)>>2)); |
bieleluk | 12:5e618e97cb24 | 451 | switch (ADC1->SMPR&ADC_SMPR_SMP){ |
bieleluk | 12:5e618e97cb24 | 452 | case 0: |
bieleluk | 12:5e618e97cb24 | 453 | pc.printf("1.5"); |
bieleluk | 12:5e618e97cb24 | 454 | break; |
bieleluk | 12:5e618e97cb24 | 455 | case 1: |
bieleluk | 12:5e618e97cb24 | 456 | pc.printf("7.5"); |
bieleluk | 12:5e618e97cb24 | 457 | break; |
bieleluk | 12:5e618e97cb24 | 458 | case 2: |
bieleluk | 12:5e618e97cb24 | 459 | pc.printf("13.5"); |
bieleluk | 12:5e618e97cb24 | 460 | break; |
bieleluk | 12:5e618e97cb24 | 461 | case 3:pc.printf("28.5"); |
bieleluk | 12:5e618e97cb24 | 462 | break; |
bieleluk | 12:5e618e97cb24 | 463 | case 4:pc.printf("41.5"); |
bieleluk | 12:5e618e97cb24 | 464 | break; |
bieleluk | 12:5e618e97cb24 | 465 | case 5:pc.printf("55.5"); |
bieleluk | 12:5e618e97cb24 | 466 | break; |
bieleluk | 12:5e618e97cb24 | 467 | case 6: |
bieleluk | 12:5e618e97cb24 | 468 | pc.printf("71.5"); |
bieleluk | 12:5e618e97cb24 | 469 | break; |
bieleluk | 12:5e618e97cb24 | 470 | case 7:pc.printf("239.5"); |
bieleluk | 12:5e618e97cb24 | 471 | break; |
bieleluk | 12:5e618e97cb24 | 472 | } |
bieleluk | 12:5e618e97cb24 | 473 | pc.printf("clk cycles\n\r"); |
bieleluk | 12:5e618e97cb24 | 474 | } |
bieleluk | 12:5e618e97cb24 | 475 | |
bieleluk | 12:5e618e97cb24 | 476 | //print configuration of board's clock |
bieleluk | 12:5e618e97cb24 | 477 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 478 | void Debug_complete::show_clk_config(){ |
bieleluk | 12:5e618e97cb24 | 479 | pc.printf("\e[93;40mClock configuration:\e[97;40m\n\r"); |
bieleluk | 12:5e618e97cb24 | 480 | |
bieleluk | 12:5e618e97cb24 | 481 | // type of clock |
bieleluk | 12:5e618e97cb24 | 482 | int clk_typede = RCC->CFGR & RCC_CFGR_SW; |
bieleluk | 12:5e618e97cb24 | 483 | if (clk_typede == 0 && RCC->CR&RCC_CR_HSION){ // hsi clock |
bieleluk | 12:5e618e97cb24 | 484 | pc.printf("HSI\t"); |
bieleluk | 12:5e618e97cb24 | 485 | |
bieleluk | 12:5e618e97cb24 | 486 | }else if (clk_typede == 1 && RCC->CR&RCC_CR_HSEON){ // hse clock |
bieleluk | 12:5e618e97cb24 | 487 | pc.printf("HSE\t"); |
bieleluk | 12:5e618e97cb24 | 488 | if (RCC->CR & RCC_CR_HSEBYP){ // bypassed hse clock |
bieleluk | 12:5e618e97cb24 | 489 | pc.printf(" BYPASS"); |
bieleluk | 12:5e618e97cb24 | 490 | } |
bieleluk | 12:5e618e97cb24 | 491 | |
bieleluk | 12:5e618e97cb24 | 492 | }else if (clk_typede == 2 && RCC->CR&RCC_CR_PLLON){ // pll clock |
bieleluk | 12:5e618e97cb24 | 493 | pc.printf("PLL\t"); |
bieleluk | 12:5e618e97cb24 | 494 | int var = (RCC->CFGR&RCC_CFGR_PLLMUL)>>18; // multiplication factor of pll clock |
bieleluk | 12:5e618e97cb24 | 495 | pc.printf("mul. factor = %d\t",(var<14)?(var+2):16); |
bieleluk | 12:5e618e97cb24 | 496 | |
bieleluk | 12:5e618e97cb24 | 497 | var = (RCC->CFGR2&RCC_CFGR2_PREDIV); // divider of pll input clock |
bieleluk | 12:5e618e97cb24 | 498 | pc.printf("PREDIV = %d\tPLL input:",var+1); |
bieleluk | 12:5e618e97cb24 | 499 | |
bieleluk | 12:5e618e97cb24 | 500 | int pllscr = (RCC->CFGR&0x00018000)>>15; // type of pll input clock |
bieleluk | 12:5e618e97cb24 | 501 | switch (pllscr){ |
bieleluk | 12:5e618e97cb24 | 502 | case 0: |
bieleluk | 12:5e618e97cb24 | 503 | pc.printf(" HSI/2"); |
bieleluk | 12:5e618e97cb24 | 504 | break; |
bieleluk | 12:5e618e97cb24 | 505 | case 1: |
bieleluk | 12:5e618e97cb24 | 506 | pc.printf(" HSI/PREDIV"); |
bieleluk | 12:5e618e97cb24 | 507 | break; |
bieleluk | 12:5e618e97cb24 | 508 | case 2: |
bieleluk | 12:5e618e97cb24 | 509 | pc.printf(" HSE/PREDIV"); |
bieleluk | 12:5e618e97cb24 | 510 | break; |
bieleluk | 12:5e618e97cb24 | 511 | case 3: |
bieleluk | 12:5e618e97cb24 | 512 | pc.printf("HSI48/PREDIV"); |
bieleluk | 12:5e618e97cb24 | 513 | break; |
bieleluk | 12:5e618e97cb24 | 514 | } |
bieleluk | 12:5e618e97cb24 | 515 | pc.printf(" "); |
bieleluk | 12:5e618e97cb24 | 516 | |
bieleluk | 12:5e618e97cb24 | 517 | }else if (clk_typede == 3 && (RCC->CR2&RCC_CR2_HSI48ON)){ //hsi48 clock |
bieleluk | 12:5e618e97cb24 | 518 | pc.printf("HSI48"); |
bieleluk | 12:5e618e97cb24 | 519 | }else{ // none of previous options |
bieleluk | 12:5e618e97cb24 | 520 | pc.printf("ERROR"); |
bieleluk | 12:5e618e97cb24 | 521 | } |
bieleluk | 12:5e618e97cb24 | 522 | pc.printf("\n\r"); |
bieleluk | 12:5e618e97cb24 | 523 | } |
bieleluk | 12:5e618e97cb24 | 524 | |
bieleluk | 12:5e618e97cb24 | 525 | // clear screen from m line up to n line |
bieleluk | 12:5e618e97cb24 | 526 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 527 | void Debug_complete::clear_from_n_up_to_m(int m, int n){ |
bieleluk | 12:5e618e97cb24 | 528 | pc.printf("\033[%d;0H",m); |
bieleluk | 12:5e618e97cb24 | 529 | wait(1); |
bieleluk | 12:5e618e97cb24 | 530 | while (m > n){ |
bieleluk | 12:5e618e97cb24 | 531 | m--; |
bieleluk | 12:5e618e97cb24 | 532 | pc.printf("\033[K\033[%d;0H",m); |
bieleluk | 12:5e618e97cb24 | 533 | } |
bieleluk | 12:5e618e97cb24 | 534 | pc.printf("\n\r"); |
bieleluk | 12:5e618e97cb24 | 535 | |
bieleluk | 12:5e618e97cb24 | 536 | } |
bieleluk | 12:5e618e97cb24 | 537 | |
bieleluk | 12:5e618e97cb24 | 538 | //print formatted string to debug serial port |
bieleluk | 12:5e618e97cb24 | 539 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 540 | int Debug_complete::printf(const char* format, ...){ |
bieleluk | 12:5e618e97cb24 | 541 | |
bieleluk | 12:5e618e97cb24 | 542 | int ret = pc.printf(format); |
bieleluk | 12:5e618e97cb24 | 543 | pc.printf("\e[s"); |
bieleluk | 12:5e618e97cb24 | 544 | return ret; |
bieleluk | 12:5e618e97cb24 | 545 | } |
bieleluk | 12:5e618e97cb24 | 546 | |
bieleluk | 12:5e618e97cb24 | 547 | //print character to debug serial port |
bieleluk | 12:5e618e97cb24 | 548 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 549 | int Debug_complete::putc(int character){ |
bieleluk | 12:5e618e97cb24 | 550 | |
bieleluk | 12:5e618e97cb24 | 551 | int ret = pc.putc(character); |
bieleluk | 12:5e618e97cb24 | 552 | pc.printf("\e[s"); |
bieleluk | 12:5e618e97cb24 | 553 | return ret; |
bieleluk | 12:5e618e97cb24 | 554 | } |
bieleluk | 12:5e618e97cb24 | 555 | |
bieleluk | 12:5e618e97cb24 | 556 | //read character from debug serial port |
bieleluk | 12:5e618e97cb24 | 557 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 558 | int Debug_complete::getc(){ |
bieleluk | 12:5e618e97cb24 | 559 | return pc.getc(); |
bieleluk | 12:5e618e97cb24 | 560 | } |
bieleluk | 12:5e618e97cb24 | 561 | |
bieleluk | 12:5e618e97cb24 | 562 | //print one 32-bit word from memory |
bieleluk | 12:5e618e97cb24 | 563 | //------------------------------------------------------------------------------------------------------------------ |
bieleluk | 12:5e618e97cb24 | 564 | void Debug_complete::print_reg(uint32_t address, uint32_t offset){ |
bieleluk | 12:5e618e97cb24 | 565 | |
bieleluk | 12:5e618e97cb24 | 566 | uint32_t word = read_word(address,offset); |
bieleluk | 12:5e618e97cb24 | 567 | pc.printf("\n\r-----------------------------------------------------------------------\n\r| ADDRESS: 0x%-8x |\t OFFSET: 0x%-8X |\t HEX VAL: 0x%-8x |",address,offset,word); |
bieleluk | 12:5e618e97cb24 | 568 | pc.printf("\n\r-----------------------------------------------------------------------"); |
bieleluk | 12:5e618e97cb24 | 569 | pc.printf("\n\r| bit | 31| 30| 29| 28| 27| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| \n\r"); |
bieleluk | 12:5e618e97cb24 | 570 | pc.printf( "-----------------------------------------------------------------------\n\r| val | "); |
bieleluk | 12:5e618e97cb24 | 571 | for (int i = 31; i>= 16; i--){ |
bieleluk | 12:5e618e97cb24 | 572 | pc.printf("%d | ",(word&(0x1U<<i))>>i); |
bieleluk | 12:5e618e97cb24 | 573 | } |
bieleluk | 12:5e618e97cb24 | 574 | pc.printf("\n\r-----------------------------------------------------------------------\n\r-----------------------------------------------------------------------"); |
bieleluk | 12:5e618e97cb24 | 575 | pc.printf("\n\r| bit | 15| 14| 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n\r"); |
bieleluk | 12:5e618e97cb24 | 576 | pc.printf("-----------------------------------------------------------------------\n\r| val | "); |
bieleluk | 12:5e618e97cb24 | 577 | for (int i = 15; i>= 0; i--){ |
bieleluk | 12:5e618e97cb24 | 578 | pc.printf("%d | ",(word&(0x1U<<i))>>i); |
bieleluk | 12:5e618e97cb24 | 579 | } |
bieleluk | 12:5e618e97cb24 | 580 | pc.printf("\n\r-----------------------------------------------------------------------"); |
bieleluk | 12:5e618e97cb24 | 581 | pc.printf("\e[s"); |
bieleluk | 12:5e618e97cb24 | 582 | |
bieleluk | 12:5e618e97cb24 | 583 | |
bieleluk | 12:5e618e97cb24 | 584 | } |