debug tool for STM32F042F6P6

Committer:
bieleluk
Date:
Mon May 27 00:15:37 2019 +0000
Revision:
24:bc7c4e8f3fe0
Parent:
19:841a5c532145
Child:
27:e255eaf79cd2

        

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