Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* sysmocom quad-modem sysmoQMOD application code |
| 2 | * |
| 3 | * (C) 2016-2017 by Harald Welte <hwelte@hmw-consulting.de> |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 4 | * (C) 2018-2019, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
| 19 | */ |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 20 | #include "board.h" |
| 21 | #include "simtrace.h" |
| 22 | #include "utils.h" |
Kévin Redon | 1dbcf62 | 2018-09-04 16:15:10 +0200 | [diff] [blame] | 23 | #include "led.h" |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 24 | #include "wwan_led.h" |
| 25 | #include "wwan_perst.h" |
Harald Welte | 5c583d3 | 2017-05-09 06:46:47 +0200 | [diff] [blame] | 26 | #include "sim_switch.h" |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 27 | #include "boardver_adc.h" |
Harald Welte | 6d1128e | 2017-05-05 20:23:10 +0200 | [diff] [blame] | 28 | #include "card_pres.h" |
Harald Welte | 9d90d28 | 2018-06-29 22:25:42 +0200 | [diff] [blame] | 29 | #include <osmocom/core/timer.h> |
Harald Welte | 8e7fca3 | 2017-05-07 16:14:33 +0200 | [diff] [blame] | 30 | #include "usb_buf.h" |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 31 | |
| 32 | static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE; |
| 33 | static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; |
| 34 | static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP}; |
| 35 | static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; |
| 36 | static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; |
| 37 | |
Harald Welte | 912b183 | 2017-03-06 09:28:13 +0100 | [diff] [blame] | 38 | /* array of generated USB Strings */ |
| 39 | extern unsigned char *usb_strings[]; |
| 40 | |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 41 | static int qmod_sam3_is_12(void) |
| 42 | { |
| 43 | if (PIO_Get(&pin_1234_detect) == 0) |
| 44 | return 1; |
| 45 | else |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | const unsigned char __eeprom_bin[256] = { |
Harald Welte | c6e482d | 2017-03-05 16:24:29 +0100 | [diff] [blame] | 50 | USB_VENDOR_OPENMOKO & 0xff, |
| 51 | USB_VENDOR_OPENMOKO >> 8, |
| 52 | USB_PRODUCT_QMOD_HUB & 0xff, |
| 53 | USB_PRODUCT_QMOD_HUB >> 8, |
Harald Welte | 705e899 | 2017-03-05 17:10:26 +0100 | [diff] [blame] | 54 | 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] | 55 | 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, /* 0x10 - 0x1f */ |
| 56 | 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00, /* 0x20 - 0x2f */ |
| 57 | 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00, 0x20, 0x00, 0x47, 0x00, /* 0x30 - 0x3f */ |
| 58 | 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x4f */ |
| 59 | 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00, /* 0x50 - 0x5f */ |
| 60 | 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00, 0x32, 0x00, 0x00, 0x00, /* 0x60 - 0x6f */ |
| 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x7f */ |
| 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x8f */ |
| 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x9f */ |
| 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 - 0xaf */ |
| 65 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 - 0xbf */ |
| 66 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 - 0xcf */ |
| 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 - 0xdf */ |
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0 - 0xef */ |
| 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56, 0x23, 0x71, 0x04, 0x00, /* 0xf0 - 0xff */ |
| 70 | }; |
| 71 | |
| 72 | #include "i2c.h" |
| 73 | static int write_hub_eeprom(void) |
| 74 | { |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 75 | int i; |
| 76 | |
| 77 | /* wait */ |
Harald Welte | 0e29598 | 2017-03-05 16:48:47 +0100 | [diff] [blame] | 78 | mdelay(100); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 79 | |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 80 | TRACE_INFO("Writing EEPROM...\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 81 | /* write the EEPROM once */ |
Kévin Redon | a71a6f4 | 2018-07-24 09:54:12 +0200 | [diff] [blame] | 82 | for (i = 0; i < ARRAY_SIZE(__eeprom_bin); i++) { |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 83 | int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]); |
Kévin Redon | a71a6f4 | 2018-07-24 09:54:12 +0200 | [diff] [blame] | 84 | if (rc < 0) { |
| 85 | TRACE_ERROR("Writing EEPROM failed at byte %u: 0x%02x\n\r", |
| 86 | i, __eeprom_bin[i]); |
| 87 | return 1; |
| 88 | } |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* then pursue re-reading it again and again */ |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 92 | TRACE_INFO("Verifying EEPROM...\n\r"); |
Kévin Redon | a71a6f4 | 2018-07-24 09:54:12 +0200 | [diff] [blame] | 93 | for (i = 0; i < ARRAY_SIZE(__eeprom_bin); i++) { |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 94 | int byte = eeprom_read_byte(0x50, i); |
Kévin Redon | a6bd717 | 2018-08-28 19:41:10 +0200 | [diff] [blame] | 95 | TRACE_DEBUG("0x%02x: %02x\n\r", i, byte); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 96 | if (byte != __eeprom_bin[i]) |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 97 | 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] | 98 | i, __eeprom_bin[i], byte); |
| 99 | } |
Kévin Redon | a6bd717 | 2018-08-28 19:41:10 +0200 | [diff] [blame] | 100 | TRACE_INFO("EEPROM written\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 101 | |
| 102 | /* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is |
| 103 | * again powering us up */ |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
Harald Welte | 9547e41 | 2018-07-03 22:31:16 +0200 | [diff] [blame] | 108 | static int erase_hub_eeprom(void) |
| 109 | { |
| 110 | int i; |
| 111 | |
| 112 | /* wait */ |
| 113 | mdelay(100); |
| 114 | |
| 115 | TRACE_INFO("Erasing EEPROM...\n\r"); |
| 116 | /* write the EEPROM once */ |
| 117 | for (i = 0; i < 256; i++) { |
| 118 | int rc = eeprom_write_byte(0x50, i, 0xff); |
Kévin Redon | c428516 | 2018-08-07 12:12:47 +0200 | [diff] [blame] | 119 | if (rc < 0) { |
| 120 | TRACE_ERROR("Erasing EEPROM failed at byte %u: 0x%02x\n\r", |
| 121 | i, __eeprom_bin[i]); |
| 122 | return 1; |
| 123 | } |
Harald Welte | 9547e41 | 2018-07-03 22:31:16 +0200 | [diff] [blame] | 124 | } |
Kévin Redon | a6bd717 | 2018-08-28 19:41:10 +0200 | [diff] [blame] | 125 | TRACE_INFO("EEPROM erased\n\r"); |
Harald Welte | 9547e41 | 2018-07-03 22:31:16 +0200 | [diff] [blame] | 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 131 | static void board_exec_dbg_cmd_st12only(int ch) |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 132 | { |
| 133 | uint32_t addr, val; |
| 134 | |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 135 | /* functions below only work on primary (ST12) */ |
| 136 | if (!qmod_sam3_is_12()) |
| 137 | return; |
| 138 | |
| 139 | switch (ch) { |
| 140 | case 'E': |
| 141 | write_hub_eeprom(); |
| 142 | break; |
Harald Welte | 9547e41 | 2018-07-03 22:31:16 +0200 | [diff] [blame] | 143 | case 'e': |
| 144 | erase_hub_eeprom(); |
| 145 | break; |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 146 | case 'O': |
| 147 | printf("Setting PRTPWR_OVERRIDE\n\r"); |
| 148 | PIO_Set(&pin_hubpwr_override); |
| 149 | break; |
| 150 | case 'o': |
| 151 | printf("Clearing PRTPWR_OVERRIDE\n\r"); |
| 152 | PIO_Clear(&pin_hubpwr_override); |
| 153 | break; |
| 154 | case 'H': |
| 155 | printf("Clearing _HUB_RESET -> HUB_RESET high (inactive)\n\r"); |
| 156 | PIO_Clear(&pin_hub_rst); |
| 157 | break; |
| 158 | case 'h': |
| 159 | /* high level drives transistor -> HUB_RESET low */ |
| 160 | printf("Asserting _HUB_RESET -> HUB_RESET low (active)\n\r"); |
| 161 | PIO_Set(&pin_hub_rst); |
| 162 | break; |
| 163 | case 'w': |
| 164 | if (PIO_GetOutputDataStatus(&pin_hub_rst) == 0) |
| 165 | printf("WARNING: attempting EEPROM access while HUB not in reset\n\r"); |
| 166 | printf("Please enter EEPROM offset:\n\r"); |
| 167 | UART_GetIntegerMinMax(&addr, 0, 255); |
| 168 | printf("Please enter EEPROM value:\n\r"); |
| 169 | UART_GetIntegerMinMax(&val, 0, 255); |
Kévin Redon | e5f891a | 2018-09-04 13:31:26 +0200 | [diff] [blame] | 170 | printf("Writing value 0x%02lx to EEPROM offset 0x%02lx\n\r", val, addr); |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 171 | eeprom_write_byte(0x50, addr, val); |
| 172 | break; |
| 173 | case 'r': |
| 174 | printf("Please enter EEPROM offset:\n\r"); |
| 175 | UART_GetIntegerMinMax(&addr, 0, 255); |
Kévin Redon | e5f891a | 2018-09-04 13:31:26 +0200 | [diff] [blame] | 176 | printf("EEPROM[0x%02lx] = 0x%02x\n\r", addr, eeprom_read_byte(0x50, addr)); |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 177 | break; |
| 178 | default: |
| 179 | printf("Unknown command '%c'\n\r", ch); |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /* returns '1' in case we should break any endless loop */ |
| 185 | void board_exec_dbg_cmd(int ch) |
| 186 | { |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 187 | #if (ALLOW_PEER_ERASE > 0) |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 188 | /* this variable controls if it is allowed to assert/release the ERASE line. |
| 189 | this is done to prevent accidental ERASE on noisy serial input since only one character can trigger the ERASE. |
| 190 | */ |
| 191 | static bool allow_erase = false; |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 192 | #endif |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 193 | |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 194 | switch (ch) { |
| 195 | case '?': |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 196 | printf("\t?\thelp\n\r"); |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 197 | printf("\tR\treset SAM3\n\r"); |
Kévin Redon | 1dbcf62 | 2018-09-04 16:15:10 +0200 | [diff] [blame] | 198 | printf("\tl\tswitch off LED 1\n\r"); |
| 199 | printf("\tL\tswitch off LED 1\n\r"); |
| 200 | printf("\tg\tswitch off LED 2\n\r"); |
| 201 | printf("\tG\tswitch off LED 2\n\r"); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 202 | if (qmod_sam3_is_12()) { |
| 203 | printf("\tE\tprogram EEPROM\n\r"); |
Harald Welte | 9547e41 | 2018-07-03 22:31:16 +0200 | [diff] [blame] | 204 | printf("\te\tErase EEPROM\n\r"); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 205 | printf("\tO\tEnable PRTPWR_OVERRIDE\n\r"); |
| 206 | printf("\to\tDisable PRTPWR_OVERRIDE\n\r"); |
| 207 | printf("\tH\tRelease HUB RESET (high)\n\r"); |
| 208 | printf("\th\tAssert HUB RESET (low)\n\r"); |
| 209 | printf("\tw\tWrite single byte in EEPROM\n\r"); |
| 210 | printf("\tr\tRead single byte from EEPROM\n\r"); |
| 211 | } |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 212 | printf("\tX\tRelease peer SAM3 from reset\n\r"); |
| 213 | printf("\tx\tAssert peer SAM3 reset\n\r"); |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 214 | #if (ALLOW_PEER_ERASE > 0) |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 215 | printf("\tY\tRelease peer SAM3 ERASE signal\n\r"); |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 216 | printf("\ta\tAllow asserting peer SAM3 ERASE signal\n\r"); |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 217 | printf("\ty\tAssert peer SAM3 ERASE signal\n\r"); |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 218 | #endif |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 219 | printf("\tU\tProceed to USB Initialization\n\r"); |
| 220 | printf("\t1\tGenerate 1ms reset pulse on WWAN1\n\r"); |
| 221 | printf("\t2\tGenerate 1ms reset pulse on WWAN2\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 222 | break; |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 223 | case 'R': |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 224 | printf("Asking NVIC to reset us\n\r"); |
Harald Welte | f415d71 | 2017-03-03 01:51:43 +0100 | [diff] [blame] | 225 | USBD_Disconnect(); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 226 | NVIC_SystemReset(); |
| 227 | break; |
Kévin Redon | 1dbcf62 | 2018-09-04 16:15:10 +0200 | [diff] [blame] | 228 | case 'l': |
| 229 | led_blink(LED_GREEN, BLINK_ALWAYS_OFF); |
| 230 | printf("LED 1 switched off\n\r"); |
| 231 | break; |
| 232 | case 'L': |
| 233 | led_blink(LED_GREEN, BLINK_ALWAYS_ON); |
| 234 | printf("LED 1 switched on\n\r"); |
| 235 | break; |
| 236 | case 'g': |
| 237 | led_blink(LED_RED, BLINK_ALWAYS_OFF); |
| 238 | printf("LED 2 switched off\n\r"); |
| 239 | break; |
| 240 | case 'G': |
| 241 | led_blink(LED_RED, BLINK_ALWAYS_ON); |
| 242 | printf("LED 2 switched on\n\r"); |
| 243 | break; |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 244 | case 'X': |
| 245 | printf("Clearing _SIMTRACExx_RST -> SIMTRACExx_RST high (inactive)\n\r"); |
| 246 | PIO_Clear(&pin_peer_rst); |
| 247 | break; |
| 248 | case 'x': |
| 249 | printf("Setting _SIMTRACExx_RST -> SIMTRACExx_RST low (active)\n\r"); |
| 250 | PIO_Set(&pin_peer_rst); |
| 251 | break; |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 252 | #if (ALLOW_PEER_ERASE > 0) |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 253 | case 'Y': |
| 254 | printf("Clearing SIMTRACExx_ERASE (inactive)\n\r"); |
| 255 | PIO_Clear(&pin_peer_erase); |
| 256 | break; |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 257 | case 'a': |
| 258 | printf("Asserting SIMTRACExx_ERASE allowed on next command\n\r"); |
| 259 | allow_erase = true; |
| 260 | break; |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 261 | case 'y': |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 262 | if (allow_erase) { |
| 263 | printf("Setting SIMTRACExx_ERASE (active)\n\r"); |
| 264 | PIO_Set(&pin_peer_erase); |
| 265 | } else { |
| 266 | printf("Please first allow setting SIMTRACExx_ERASE\n\r"); |
| 267 | } |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 268 | break; |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 269 | #endif |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 270 | case '1': |
| 271 | printf("Resetting Modem 1 (of this SAM3)\n\r"); |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 272 | wwan_perst_do_reset_pulse(0, 300); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 273 | break; |
| 274 | case '2': |
| 275 | printf("Resetting Modem 2 (of this SAM3)\n\r"); |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 276 | wwan_perst_do_reset_pulse(1, 300); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 277 | break; |
| 278 | case '!': |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 279 | sim_switch_use_physical(0, 0); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 280 | break; |
| 281 | case '@': |
Harald Welte | 44622df | 2017-05-11 00:04:50 +0200 | [diff] [blame] | 282 | sim_switch_use_physical(0, 0); |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 283 | break; |
| 284 | default: |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 285 | if (!qmod_sam3_is_12()) |
Harald Welte | 9164a6d | 2017-05-05 20:55:21 +0200 | [diff] [blame] | 286 | printf("Unknown command '%c'\n\r", ch); |
Harald Welte | ed1efc5 | 2017-05-07 22:49:45 +0200 | [diff] [blame] | 287 | else |
| 288 | board_exec_dbg_cmd_st12only(ch); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 289 | break; |
| 290 | } |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 291 | |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 292 | #if (ALLOW_PEER_ERASE > 0) |
Kévin Redon | a634c0e | 2019-05-23 16:31:58 +0200 | [diff] [blame] | 293 | // set protection back so it can only run for one command |
| 294 | if ('a' != ch) { |
| 295 | allow_erase = false; |
| 296 | } |
Kévin Redon | 6228d18 | 2019-05-23 17:33:45 +0200 | [diff] [blame^] | 297 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void board_main_top(void) |
| 301 | { |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 302 | #ifndef APPLICATION_dfu |
Harald Welte | 8e7fca3 | 2017-05-07 16:14:33 +0200 | [diff] [blame] | 303 | usb_buf_init(); |
| 304 | |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 305 | wwan_led_init(); |
| 306 | wwan_perst_init(); |
Harald Welte | 5c583d3 | 2017-05-09 06:46:47 +0200 | [diff] [blame] | 307 | sim_switch_init(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 308 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 309 | |
Harald Welte | 2817498 | 2017-05-07 16:45:10 +0200 | [diff] [blame] | 310 | /* make sure we can detect whether running in ST12 or ST34 */ |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 311 | PIO_Configure(&pin_1234_detect, 1); |
Harald Welte | 2817498 | 2017-05-07 16:45:10 +0200 | [diff] [blame] | 312 | |
| 313 | if (qmod_sam3_is_12()) { |
| 314 | /* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal |
| 315 | * pull-up on the input to keep SIMTRACE12 alive */ |
| 316 | PIO_Configure(&pin_hubpwr_override, 1); |
| 317 | PIO_Configure(&pin_hub_rst, 1); |
| 318 | } |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 319 | PIO_Configure(&pin_peer_rst, 1); |
| 320 | PIO_Configure(&pin_peer_erase, 1); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 321 | |
| 322 | #ifndef APPLICATION_dfu |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 323 | i2c_pin_init(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 324 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 325 | |
| 326 | if (qmod_sam3_is_12()) { |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 327 | TRACE_INFO("Detected Quad-Modem ST12\n\r"); |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 328 | } else { |
Harald Welte | ec0837c | 2017-03-03 01:33:24 +0100 | [diff] [blame] | 329 | TRACE_INFO("Detected Quad-Modem ST34\n\r"); |
Harald Welte | 912b183 | 2017-03-06 09:28:13 +0100 | [diff] [blame] | 330 | /* make sure we use the second set of USB Strings |
| 331 | * calling the interfaces "Modem 3" and "Modem 4" rather |
| 332 | * than 1+2 */ |
| 333 | usb_strings[7] = usb_strings[9]; |
| 334 | usb_strings[8] = usb_strings[10]; |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* Obtain the circuit board version (currently just prints voltage */ |
| 338 | get_board_version_adc(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 339 | #ifndef APPLICATION_dfu |
Harald Welte | 6d1128e | 2017-05-05 20:23:10 +0200 | [diff] [blame] | 340 | /* Initialize checking for card insert/remove events */ |
| 341 | card_present_init(); |
Harald Welte | 2539917 | 2017-05-11 00:47:29 +0200 | [diff] [blame] | 342 | #endif |
Harald Welte | aa3b867 | 2017-02-10 19:21:10 +0100 | [diff] [blame] | 343 | } |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 344 | |
| 345 | static int uart_has_loopback_jumper(void) |
| 346 | { |
| 347 | unsigned int i; |
| 348 | const Pin uart_loopback_pins[] = { |
| 349 | {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}, |
| 350 | {PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
| 351 | }; |
| 352 | |
| 353 | /* Configure UART pins as I/O */ |
| 354 | PIO_Configure(uart_loopback_pins, PIO_LISTSIZE(uart_loopback_pins)); |
| 355 | |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 356 | /* Send pattern over UART TX and check if it is received on RX |
| 357 | * If the loop doesn't get interrupted, RxD always follows TxD and thus a |
| 358 | * loopback jumper has been placed on RxD/TxD, and we will boot |
| 359 | * into DFU unconditionally |
| 360 | */ |
| 361 | int has_loopback_jumper = 1; |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 362 | for (i = 0; i < 10; i++) { |
| 363 | /* Set TxD high; abort if RxD doesn't go high either */ |
| 364 | PIO_Set(&uart_loopback_pins[1]); |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 365 | if (!PIO_Get(&uart_loopback_pins[0])) { |
| 366 | has_loopback_jumper = 0; |
| 367 | break; |
| 368 | } |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 369 | /* Set TxD low, abort if RxD doesn't go low either */ |
| 370 | PIO_Clear(&uart_loopback_pins[1]); |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 371 | if (PIO_Get(&uart_loopback_pins[0])) { |
| 372 | has_loopback_jumper = 0; |
| 373 | break; |
| 374 | } |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 375 | } |
Kévin Redon | d24e9bd | 2018-07-07 14:56:43 +0200 | [diff] [blame] | 376 | |
| 377 | /* Put pins back to UART mode */ |
| 378 | const Pin uart_pins[] = {PINS_UART}; |
| 379 | PIO_Configure(uart_pins, PIO_LISTSIZE(uart_pins)); |
| 380 | |
| 381 | return has_loopback_jumper; |
Harald Welte | 27f5fc6 | 2017-11-28 22:15:56 +0100 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | int board_override_enter_dfu(void) |
| 385 | { |
| 386 | /* If the loopback jumper is set, we enter DFU mode */ |
| 387 | if (uart_has_loopback_jumper()) |
| 388 | return 1; |
| 389 | |
| 390 | return 0; |
| 391 | } |