Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* SIMtrace with SAM3S board definition |
| 2 | * |
| 3 | * (C) 2016-2017 by Harald Welte <hwelte@hmw-consulting.de> |
| 4 | * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
| 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 | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 20 | #pragma once |
| 21 | #include "board_common.h" |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 22 | #include "simtrace_usb.h" |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 23 | |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 24 | /* Name of the board */ |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 25 | #define BOARD_NAME "SAM3S-SIMTRACE" |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 26 | /* Board definition */ |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 27 | #define simtrace |
| 28 | |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 29 | /* Board main oscillator frequency (in Hz) */ |
Harald Welte | a02b641 | 2016-08-21 18:32:12 +0200 | [diff] [blame] | 30 | #define BOARD_MAINOSC 18432000 |
| 31 | |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 32 | /** Pin configuration **/ |
| 33 | /* Button to force bootloader start (shorted to ground when pressed */ |
| 34 | #define PIN_BOOTLOADER_SW {PIO_PA31, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP} |
| 35 | /* Enable powering the card using the second 3.3 V output of the LDO (active high) */ |
| 36 | #define SIM_PWEN_PIN {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
Kévin Redon | ee62a9d | 2018-06-11 13:42:23 +0200 | [diff] [blame] | 37 | /* Enable powering the SIM card */ |
| 38 | #define PWR_PINS SIM_PWEN_PIN |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 39 | /* Card presence pin */ |
| 40 | #define SW_SIM PIO_PA8 |
| 41 | /* Pull card presence pin high (shorted to ground in card slot when card is present) */ |
| 42 | #define SMARTCARD_CONNECT_PIN {SW_SIM, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_DEGLITCH | PIO_IT_EDGE } |
| 43 | |
| 44 | /** Smart card connection **/ |
| 45 | /* Card RST reset signal input (active low; RST_SIM in schematic) */ |
Kévin Redon | 45ad62d | 2018-06-07 18:56:41 +0200 | [diff] [blame] | 46 | #define PIN_SIM_RST {PIO_PA7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 47 | /* Card I/O data signal input/output (I/O_SIM in schematic) */ |
| 48 | #define PIN_SIM_IO {PIO_PA6A_TXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 49 | /* Card CLK clock input (CLK_SIM in schematic) */ |
| 50 | #define PIN_SIM_CLK {PIO_PA2B_SCK0, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 51 | /* Pin to measure card I/O timing (to start measuring the ETU on I/O activity; connected I/O_SIM in schematic) */ |
| 52 | #define PIN_SIM_IO_INPUT {PIO_PA1B_TIOB0, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} |
| 53 | /* Pin used as clock input (to measure the ETU duration; connected to CLK_SIM in schematic) */ |
| 54 | #define PIN_SIM_CLK_INPUT {PIO_PA4B_TCLK0, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} |
| 55 | /* Pins used to measure ETU timing (using timer counter) */ |
| 56 | #define PINS_TC PIN_SIM_IO_INPUT, PIN_SIM_CLK_INPUT |
| 57 | |
| 58 | /** Phone connection **/ |
| 59 | /* Phone USIM slot 1 VCC pin (VCC_PHONE in schematic) */ |
| 60 | #define PIN_USIM1_VCC {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT} |
| 61 | /* Phone USIM slot 1 RST pin (active low; RST_PHONE in schematic) */ |
| 62 | #define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_RISE_EDGE | PIO_DEGLITCH } |
| 63 | /* Phone I/O data signal input/output (I/O_PHONE in schematic) */ |
| 64 | #define PIN_PHONE_IO {PIO_PA22A_TXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 65 | /* Phone CLK clock input (CLK_PHONE in schematic) */ |
| 66 | #define PIN_PHONE_CLK {PIO_PA23A_SCK1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 67 | /* Pin used for phone USIM slot 1 communication */ |
| 68 | #define PINS_USIM1 PIN_PHONE_IO, PIN_PHONE_CLK, PIN_PHONE_CLK_INPUT, PIN_USIM1_VCC, PIN_PHONE_IO_INPUT, PIN_USIM1_nRST |
| 69 | /* Phone I/O data signal input/output (unused USART RX input; connected to I/O_PHONE in schematic) */ |
| 70 | #define PIN_PHONE_IO_INPUT {PIO_PA21A_RXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 71 | /* Pin used as clock input (to measure the ETU duration; connected to CLK_PHONE in schematic) */ |
| 72 | #define PIN_PHONE_CLK_INPUT {PIO_PA29B_TCLK2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} |
| 73 | |
Kévin Redon | ee62a9d | 2018-06-11 13:42:23 +0200 | [diff] [blame] | 74 | /** Default pin configuration **/ |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 75 | /* Disconnect VPP, CLK, and RST lines between card and phone using bus switch (high sets bus switch to high-impedance) */ |
| 76 | #define PIN_SC_SW_DEFAULT {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
| 77 | /* Disconnect I/O line between card and phone using bus switch (high sets bus switch to high-impedance) */ |
| 78 | #define PIN_IO_SW_DEFAULT {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
| 79 | /* Disconnect all lines (VPP, CLK, RST, and I/O) between card and phone */ |
| 80 | #define PINS_BUS_DEFAULT PIN_SC_SW_DEFAULT, PIN_IO_SW_DEFAULT |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 81 | |
| 82 | /** Sniffer configuration **/ |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 83 | /* Connect VPP, CLK, and RST lines between card and phone using bus switch (low connects signals on bus switch) */ |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 84 | #define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 85 | /* Connect I/O line between card and phone using bus switch (low connects signals on bus switch) */ |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 86 | #define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 87 | /* Connect all lines (VPP, CLK, RST, and I/O) between card and phone */ |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 88 | #define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF |
Kévin Redon | a2b3676 | 2018-06-24 11:31:36 +0200 | [diff] [blame] | 89 | /* Card RST reset signal input (use as input since the phone will drive it) */ |
Kévin Redon | 7be52ec | 2018-06-25 15:49:28 +0200 | [diff] [blame] | 90 | #define PIN_SIM_RST_SNIFF {PIO_PA7, PIOA, ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_IT_EDGE} |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 91 | /* Pins used to sniff phone-card communication */ |
Kévin Redon | a2b3676 | 2018-06-24 11:31:36 +0200 | [diff] [blame] | 92 | #define PINS_SIM_SNIFF PIN_SIM_IO, PIN_SIM_CLK, PIN_SIM_RST_SNIFF |
Kévin Redon | 45ad62d | 2018-06-07 18:56:41 +0200 | [diff] [blame] | 93 | /* Disable power converter 4.5-6V to 3.3V (active high) */ |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 94 | #define PIN_SIM_PWEN_SNIFF {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
Kévin Redon | 45ad62d | 2018-06-07 18:56:41 +0200 | [diff] [blame] | 95 | /* Enable power switch to forward VCC_PHONE to VCC_SIM (active high) */ |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 96 | #define PIN_VCC_FWD_SNIFF {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
| 97 | /* Use phone VCC to power card */ |
Kévin Redon | ee62a9d | 2018-06-11 13:42:23 +0200 | [diff] [blame] | 98 | #define PINS_PWR_SNIFF PIN_SIM_PWEN_SNIFF, PIN_VCC_FWD_SNIFF |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 99 | |
Kévin Redon | 45ad62d | 2018-06-07 18:56:41 +0200 | [diff] [blame] | 100 | /** CCID configuration */ |
| 101 | /* Card RST reset signal input (active low; RST_SIM in schematic) */ |
| 102 | #define PIN_ISO7816_RSTMC {PIO_PA7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
| 103 | /* ISO7816-communication related pins */ |
| 104 | #define PINS_ISO7816 PIN_SIM_IO, PIN_SIM_CLK, PIN_ISO7816_RSTMC // SIM_PWEN_PIN, PIN_SIM_IO2, PIN_SIM_CLK2 |
| 105 | |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 106 | /** External SPI flash interface **/ |
| 107 | /* SPI MISO pin definition */ |
| 108 | #define PIN_SPI_MISO {PIO_PA12A_MISO, PIOA, PIOA, PIO_PERIPH_A, PIO_PULLUP} |
| 109 | /* SPI MOSI pin definition */ |
| 110 | #define PIN_SPI_MOSI {PIO_PA13A_MOSI, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 111 | /* SPI SCK pin definition */ |
| 112 | #define PIN_SPI_SCK {PIO_PA14A_SPCK, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 113 | /* SPI pins definition. Contains MISO, MOSI & SCK */ |
| 114 | #define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SCK |
| 115 | /* SPI chip select 0 pin definition */ |
| 116 | #define PIN_SPI_NPCS0 {PIO_PA11A_NPCS0, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} |
| 117 | /* SPI flash write protect pin (active low, pulled low) */ |
| 118 | #define PIN_SPI_WP {PA15, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
Harald Welte | 2d3371e | 2015-11-30 11:59:03 +0100 | [diff] [blame] | 119 | |
Kévin Redon | ff3d849 | 2018-08-06 17:57:20 +0200 | [diff] [blame] | 120 | /** Pin configuration to control USB pull-up on D+ |
| 121 | * @details the USB pull-up on D+ is enable by default on the board but can be disabled by setting PA16 high |
| 122 | */ |
| 123 | #define PIN_USB_PULLUP {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} |
| 124 | |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 125 | /** USB definitions */ |
| 126 | /* OpenMoko SIMtrace 2 USB vendor ID */ |
| 127 | #define BOARD_USB_VENDOR_ID USB_VENDOR_OPENMOKO |
| 128 | /* OpenMoko SIMtrace 2 USB product ID (main application/runtime mode) */ |
| 129 | #define BOARD_USB_PRODUCT_ID USB_PRODUCT_SIMTRACE2 |
| 130 | /* OpenMoko SIMtrace 2 DFU USB product ID (DFU bootloader/DFU mode) */ |
| 131 | #define BOARD_DFU_USB_PRODUCT_ID USB_PRODUCT_SIMTRACE2_DFU |
| 132 | /* USB release number (bcdDevice, shown as 0.00) */ |
| 133 | #define BOARD_USB_RELEASE 0x000 |
| 134 | /* Indicate SIMtrace is bus power in USB attributes */ |
Harald Welte | 3ecbf67 | 2017-03-03 02:10:34 +0100 | [diff] [blame] | 135 | #define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP |
| 136 | |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 137 | /** Supported modes */ |
| 138 | /* SIMtrace board supports sniffer mode */ |
Kévin Redon | 36abece | 2018-06-04 16:30:01 +0200 | [diff] [blame] | 139 | #define HAVE_SNIFFER |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 140 | /* SIMtrace board supports CCID mode */ |
Kévin Redon | 927ffb4 | 2018-06-24 11:30:31 +0200 | [diff] [blame] | 141 | //#define HAVE_CCID |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 142 | /* SIMtrace board supports card emulation mode */ |
Kévin Redon | 927ffb4 | 2018-06-24 11:30:31 +0200 | [diff] [blame] | 143 | //#define HAVE_CARDEM |
Kévin Redon | 2c4e2af | 2018-06-06 17:02:33 +0200 | [diff] [blame] | 144 | /* SIMtrace board supports man-in-the-middle mode */ |
Harald Welte | ba2ad56 | 2017-11-28 19:49:41 +0100 | [diff] [blame] | 145 | //#define HAVE_MITM |