Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 1 | /* Quad-modem speciic application code */ |
| 2 | /* (C) 2016-2016 by Harald Welte <laforge@gnumonks.org> */ |
| 3 | |
| 4 | #include "board.h" |
| 5 | #include "simtrace.h" |
| 6 | #include "utils.h" |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 7 | #include "wwan_led.h" |
| 8 | #include "wwan_perst.h" |
Harald Welte | 5c583d3 | 2017-05-09 06:46:47 +0200 | [diff] [blame] | 9 | #include "sim_switch.h" |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 10 | #include "boardver_adc.h" |
Harald Welte | 6d1128e | 2017-05-05 20:23:10 +0200 | [diff] [blame] | 11 | #include "card_pres.h" |
Harald Welte | 9d90d28 | 2018-06-29 22:25:42 +0200 | [diff] [blame] | 12 | #include <osmocom/core/timer.h> |
Harald Welte | 8e7fca3 | 2017-05-07 16:14:33 +0200 | [diff] [blame] | 13 | #include "usb_buf.h" |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 14 | |
| 15 | static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE; |
| 16 | static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; |
| 17 | static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP}; |
| 18 | static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; |
| 19 | static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; |
| 20 | |
Harald Welte | 912b183 | 2017-03-06 09:28:13 +0100 | [diff] [blame] | 21 | /* array of generated USB Strings */ |
| 22 | extern unsigned char *usb_strings[]; |
| 23 | |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 24 | static int qmod_sam3_is_12(void) |
| 25 | { |
| 26 | if (PIO_Get(&pin_1234_detect) == 0) |
| 27 | return 1; |
| 28 | else |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | const unsigned char __eeprom_bin[256] = { |
Harald Welte | c6e482d | 2017-03-05 16:24:29 +0100 | [diff] [blame] | 33 | USB_VENDOR_OPENMOKO & 0xff, |
| 34 | USB_VENDOR_OPENMOKO >> 8, |
| 35 | USB_PRODUCT_QMOD_HUB & 0xff, |
| 36 | USB_PRODUCT_QMOD_HUB >> 8, |
Harald Welte | 705e899 | 2017-03-05 17:10:26 +0100 | [diff] [blame] | 37 | 0x00, 0x00, 0x9b, 0x20, 0x09, 0x00, 0x00, 0x00, 0x32, 0x32, 0x32, 0x32, /* 0x00 - 0x0f */ |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 38 | 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, /* 0x10 - 0x1f */ |
| 39 | 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00, /* 0x20 - 0x2f */ |
| 40 | 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00, 0x20, 0x00, 0x47, 0x00, /* 0x30 - 0x3f */ |
| 41 | 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x4f */ |
| 42 | 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00, /* 0x50 - 0x5f */ |
| 43 | 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00, 0x32, 0x00, 0x00, 0x00, /* 0x60 - 0x6f */ |
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x7f */ |
| 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x8f */ |
| 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x9f */ |
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 - 0xaf */ |
| 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 - 0xbf */ |
| 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 - 0xcf */ |
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 - 0xdf */ |
| 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0 - 0xef */ |
| 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56, 0x23, 0x71, 0x04, 0x00, /* 0xf0 - 0xff */ |
| 53 | }; |
| 54 | |
| 55 | #include "i2c.h" |
| 56 | static int write_hub_eeprom(void) |
| 57 | { |
| 58 | const unsigned int __eeprom_bin_len = 256; |
| 59 | |
| 60 | int i; |
| 61 | |
| 62 | /* wait */ |
Harald Welte | 0e29598 | 2017-03-05 16:48:47 +0100 | [diff] [blame] | 63 | mdelay(100); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 64 | |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 65 | TRACE_INFO("Writing EEPROM...\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 66 | /* write the EEPROM once */ |
| 67 | for (i = 0; i < 256; i++) { |
| 68 | int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]); |
| 69 | /* if the result was negative, repeat that write */ |
| 70 | if (rc < 0) |
| 71 | i--; |
| 72 | } |
| 73 | |
| 74 | /* then pursue re-reading it again and again */ |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 75 | TRACE_INFO("Verifying EEPROM...\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 76 | for (i = 0; i < 256; i++) { |
| 77 | int byte = eeprom_read_byte(0x50, i); |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 78 | TRACE_INFO("0x%02x: %02x\n\r", i, byte); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 79 | if (byte != __eeprom_bin[i]) |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 80 | TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\n\r", |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 81 | i, __eeprom_bin[i], byte); |
| 82 | } |
| 83 | |
| 84 | /* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is |
| 85 | * again powering us up */ |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 90 | static void board_exec_dbg_cmd_st12only(int ch) |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 91 | { |
| 92 | uint32_t addr, val; |
| 93 | |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 94 | /* functions below only work on primary (ST12) */ |
| 95 | if (!qmod_sam3_is_12()) |
| 96 | return; |
| 97 | |
| 98 | switch (ch) { |
| 99 | case 'E': |
| 100 | write_hub_eeprom(); |
| 101 | break; |
| 102 | case 'O': |
| 103 | printf("Setting PRTPWR_OVERRIDE\n\r"); |
| 104 | PIO_Set(&pin_hubpwr_override); |
| 105 | break; |
| 106 | case 'o': |
| 107 | printf("Clearing PRTPWR_OVERRIDE\n\r"); |
| 108 | PIO_Clear(&pin_hubpwr_override); |
| 109 | break; |
| 110 | case 'H': |
| 111 | printf("Clearing _HUB_RESET -> HUB_RESET high (inactive)\n\r"); |
| 112 | PIO_Clear(&pin_hub_rst); |
| 113 | break; |
| 114 | case 'h': |
| 115 | /* high level drives transistor -> HUB_RESET low */ |
| 116 | printf("Asserting _HUB_RESET -> HUB_RESET low (active)\n\r"); |
| 117 | PIO_Set(&pin_hub_rst); |
| 118 | break; |
| 119 | case 'w': |
| 120 | if (PIO_GetOutputDataStatus(&pin_hub_rst) == 0) |
| 121 | printf("WARNING: attempting EEPROM access while HUB not in reset\n\r"); |
| 122 | printf("Please enter EEPROM offset:\n\r"); |
| 123 | UART_GetIntegerMinMax(&addr, 0, 255); |
| 124 | printf("Please enter EEPROM value:\n\r"); |
| 125 | UART_GetIntegerMinMax(&val, 0, 255); |
| 126 | printf("Writing value 0x%02x to EEPROM offset 0x%02x\n\r", val, addr); |
| 127 | eeprom_write_byte(0x50, addr, val); |
| 128 | break; |
| 129 | case 'r': |
| 130 | printf("Please enter EEPROM offset:\n\r"); |
| 131 | UART_GetIntegerMinMax(&addr, 0, 255); |
| 132 | printf("EEPROM[0x%02x] = 0x%02x\n\r", addr, eeprom_read_byte(0x50, addr)); |
| 133 | break; |
| 134 | default: |
| 135 | printf("Unknown command '%c'\n\r", ch); |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* returns '1' in case we should break any endless loop */ |
| 141 | void board_exec_dbg_cmd(int ch) |
| 142 | { |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 143 | switch (ch) { |
| 144 | case '?': |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 145 | printf("\t?\thelp\n\r"); |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 146 | printf("\tR\treset SAM3\n\r"); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 147 | if (qmod_sam3_is_12()) { |
| 148 | printf("\tE\tprogram EEPROM\n\r"); |
| 149 | printf("\tO\tEnable PRTPWR_OVERRIDE\n\r"); |
| 150 | printf("\to\tDisable PRTPWR_OVERRIDE\n\r"); |
| 151 | printf("\tH\tRelease HUB RESET (high)\n\r"); |
| 152 | printf("\th\tAssert HUB RESET (low)\n\r"); |
| 153 | printf("\tw\tWrite single byte in EEPROM\n\r"); |
| 154 | printf("\tr\tRead single byte from EEPROM\n\r"); |
| 155 | } |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 156 | printf("\tX\tRelease peer SAM3 from reset\n\r"); |
| 157 | printf("\tx\tAssert peer SAM3 reset\n\r"); |
| 158 | printf("\tY\tRelease peer SAM3 ERASE signal\n\r"); |
| 159 | printf("\ty\tAssert peer SAM3 ERASE signal\n\r"); |
| 160 | printf("\tU\tProceed to USB Initialization\n\r"); |
| 161 | printf("\t1\tGenerate 1ms reset pulse on WWAN1\n\r"); |
| 162 | printf("\t2\tGenerate 1ms reset pulse on WWAN2\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 163 | break; |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 164 | case 'R': |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 165 | printf("Asking NVIC to reset us\n\r"); |
Harald Welte | f415d71 | 2017-03-03 01:51:43 +0100 | [diff] [blame] | 166 | USBD_Disconnect(); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 167 | NVIC_SystemReset(); |
| 168 | break; |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 169 | case 'X': |
| 170 | printf("Clearing _SIMTRACExx_RST -> SIMTRACExx_RST high (inactive)\n\r"); |
| 171 | PIO_Clear(&pin_peer_rst); |
| 172 | break; |
| 173 | case 'x': |
| 174 | printf("Setting _SIMTRACExx_RST -> SIMTRACExx_RST low (active)\n\r"); |
| 175 | PIO_Set(&pin_peer_rst); |
| 176 | break; |
| 177 | case 'Y': |
| 178 | printf("Clearing SIMTRACExx_ERASE (inactive)\n\r"); |
| 179 | PIO_Clear(&pin_peer_erase); |
| 180 | break; |
| 181 | case 'y': |
| 182 | printf("Seetting SIMTRACExx_ERASE (active)\n\r"); |
| 183 | PIO_Set(&pin_peer_erase); |
| 184 | break; |
| 185 | case '1': |
| 186 | printf("Resetting Modem 1 (of this SAM3)\n\r"); |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 187 | wwan_perst_do_reset_pulse(0, 300); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 188 | break; |
| 189 | case '2': |
| 190 | printf("Resetting Modem 2 (of this SAM3)\n\r"); |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 191 | wwan_perst_do_reset_pulse(1, 300); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 192 | break; |
| 193 | case '!': |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 194 | sim_switch_use_physical(0, 0); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 195 | break; |
| 196 | case '@': |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 197 | sim_switch_use_physical(0, 0); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 198 | break; |
| 199 | default: |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 200 | if (!qmod_sam3_is_12()) |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 201 | printf("Unknown command '%c'\n\r", ch); |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 202 | else |
| 203 | board_exec_dbg_cmd_st12only(ch); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 204 | break; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | void board_main_top(void) |
| 209 | { |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 210 | #ifndef APPLICATION_dfu |
Harald Welte | 8e7fca3 | 2017-05-07 16:14:33 +0200 | [diff] [blame] | 211 | usb_buf_init(); |
| 212 | |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 213 | wwan_led_init(); |
| 214 | wwan_perst_init(); |
Harald Welte | 5c583d3 | 2017-05-09 06:46:47 +0200 | [diff] [blame] | 215 | sim_switch_init(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 216 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 217 | |
Harald Welte | 2817498 | 2017-05-07 16:45:10 +0200 | [diff] [blame] | 218 | /* make sure we can detect whether running in ST12 or ST34 */ |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 219 | PIO_Configure(&pin_1234_detect, 1); |
Harald Welte | 2817498 | 2017-05-07 16:45:10 +0200 | [diff] [blame] | 220 | |
| 221 | if (qmod_sam3_is_12()) { |
| 222 | /* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal |
| 223 | * pull-up on the input to keep SIMTRACE12 alive */ |
| 224 | PIO_Configure(&pin_hubpwr_override, 1); |
| 225 | PIO_Configure(&pin_hub_rst, 1); |
| 226 | } |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 227 | PIO_Configure(&pin_peer_rst, 1); |
| 228 | PIO_Configure(&pin_peer_erase, 1); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 229 | |
| 230 | #ifndef APPLICATION_dfu |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 231 | i2c_pin_init(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 232 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 233 | |
| 234 | if (qmod_sam3_is_12()) { |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 235 | TRACE_INFO("Detected Quad-Modem ST12\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 236 | } else { |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 237 | TRACE_INFO("Detected Quad-Modem ST34\n\r"); |
Harald Welte | 912b183 | 2017-03-06 09:28:13 +0100 | [diff] [blame] | 238 | /* make sure we use the second set of USB Strings |
| 239 | * calling the interfaces "Modem 3" and "Modem 4" rather |
| 240 | * than 1+2 */ |
| 241 | usb_strings[7] = usb_strings[9]; |
| 242 | usb_strings[8] = usb_strings[10]; |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /* Obtain the circuit board version (currently just prints voltage */ |
| 246 | get_board_version_adc(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 247 | #ifndef APPLICATION_dfu |
Harald Welte | 6d1128e | 2017-05-05 20:23:10 +0200 | [diff] [blame] | 248 | /* Initialize checking for card insert/remove events */ |
| 249 | card_present_init(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 250 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 251 | } |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 252 | |
| 253 | static int uart_has_loopback_jumper(void) |
| 254 | { |
| 255 | unsigned int i; |
| 256 | const Pin uart_loopback_pins[] = { |
| 257 | {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}, |
| 258 | {PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
| 259 | }; |
| 260 | |
| 261 | /* Configure UART pins as I/O */ |
| 262 | PIO_Configure(uart_loopback_pins, PIO_LISTSIZE(uart_loopback_pins)); |
| 263 | |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 264 | /* Send pattern over UART TX and check if it is received on RX |
| 265 | * If the loop doesn't get interrupted, RxD always follows TxD and thus a |
| 266 | * loopback jumper has been placed on RxD/TxD, and we will boot |
| 267 | * into DFU unconditionally |
| 268 | */ |
| 269 | int has_loopback_jumper = 1; |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 270 | for (i = 0; i < 10; i++) { |
| 271 | /* Set TxD high; abort if RxD doesn't go high either */ |
| 272 | PIO_Set(&uart_loopback_pins[1]); |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 273 | if (!PIO_Get(&uart_loopback_pins[0])) { |
| 274 | has_loopback_jumper = 0; |
| 275 | break; |
| 276 | } |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 277 | /* Set TxD low, abort if RxD doesn't go low either */ |
| 278 | PIO_Clear(&uart_loopback_pins[1]); |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 279 | if (PIO_Get(&uart_loopback_pins[0])) { |
| 280 | has_loopback_jumper = 0; |
| 281 | break; |
| 282 | } |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 283 | } |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 284 | |
| 285 | /* Put pins back to UART mode */ |
| 286 | const Pin uart_pins[] = {PINS_UART}; |
| 287 | PIO_Configure(uart_pins, PIO_LISTSIZE(uart_pins)); |
| 288 | |
| 289 | return has_loopback_jumper; |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | int board_override_enter_dfu(void) |
| 293 | { |
| 294 | /* If the loopback jumper is set, we enter DFU mode */ |
| 295 | if (uart_has_loopback_jumper()) |
| 296 | return 1; |
| 297 | |
| 298 | return 0; |
| 299 | } |