debug tool for STM32F042F6P6

Committer:
bieleluk
Date:
Tue May 28 09:45:17 2019 +0000
Revision:
27:e255eaf79cd2
Parent:
24:bc7c4e8f3fe0

        

Who changed what in which revision?

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