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