blob: 6751863d84e00158c63276db0b8e9c93f75cc476 [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* 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 Welte2d3371e2015-11-30 11:59:03 +010020#pragma once
21#include "board_common.h"
Kévin Redona1012b12018-07-01 18:11:01 +020022#include "simtrace_usb.h"
Harald Welte2d3371e2015-11-30 11:59:03 +010023
Kévin Redon2c4e2af2018-06-06 17:02:33 +020024/* Name of the board */
Harald Welte2d3371e2015-11-30 11:59:03 +010025#define BOARD_NAME "SAM3S-SIMTRACE"
Kévin Redon2c4e2af2018-06-06 17:02:33 +020026/* Board definition */
Harald Welte2d3371e2015-11-30 11:59:03 +010027#define simtrace
28
Kévin Redon2c4e2af2018-06-06 17:02:33 +020029/* Board main oscillator frequency (in Hz) */
Harald Weltea02b6412016-08-21 18:32:12 +020030#define BOARD_MAINOSC 18432000
31
Kévin Redon2c4e2af2018-06-06 17:02:33 +020032/** 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 Redonee62a9d2018-06-11 13:42:23 +020037/* Enable powering the SIM card */
38#define PWR_PINS SIM_PWEN_PIN
Kévin Redon2c4e2af2018-06-06 17:02:33 +020039/* 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 Redon45ad62d2018-06-07 18:56:41 +020046#define PIN_SIM_RST {PIO_PA7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +020047/* 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 Redon2c4e2af2018-06-06 17:02:33 +020051/* 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 Redonee62a9d2018-06-11 13:42:23 +020074/** Default pin configuration **/
Kévin Redon2c4e2af2018-06-06 17:02:33 +020075/* 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 Welte2d3371e2015-11-30 11:59:03 +010081
82/** Sniffer configuration **/
Kévin Redon2c4e2af2018-06-06 17:02:33 +020083/* Connect VPP, CLK, and RST lines between card and phone using bus switch (low connects signals on bus switch) */
Harald Welte2d3371e2015-11-30 11:59:03 +010084#define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +020085/* Connect I/O line between card and phone using bus switch (low connects signals on bus switch) */
Harald Welte2d3371e2015-11-30 11:59:03 +010086#define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +020087/* Connect all lines (VPP, CLK, RST, and I/O) between card and phone */
Harald Welte2d3371e2015-11-30 11:59:03 +010088#define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF
Kévin Redona2b36762018-06-24 11:31:36 +020089/* Card RST reset signal input (use as input since the phone will drive it) */
Kévin Redon7be52ec2018-06-25 15:49:28 +020090#define PIN_SIM_RST_SNIFF {PIO_PA7, PIOA, ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_IT_EDGE}
Kévin Redon2c4e2af2018-06-06 17:02:33 +020091/* Pins used to sniff phone-card communication */
Kévin Redona2b36762018-06-24 11:31:36 +020092#define PINS_SIM_SNIFF PIN_SIM_IO, PIN_SIM_CLK, PIN_SIM_RST_SNIFF
Kévin Redon45ad62d2018-06-07 18:56:41 +020093/* Disable power converter 4.5-6V to 3.3V (active high) */
Kévin Redon2c4e2af2018-06-06 17:02:33 +020094#define PIN_SIM_PWEN_SNIFF {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon45ad62d2018-06-07 18:56:41 +020095/* Enable power switch to forward VCC_PHONE to VCC_SIM (active high) */
Kévin Redon2c4e2af2018-06-06 17:02:33 +020096#define PIN_VCC_FWD_SNIFF {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
97/* Use phone VCC to power card */
Kévin Redonee62a9d2018-06-11 13:42:23 +020098#define PINS_PWR_SNIFF PIN_SIM_PWEN_SNIFF, PIN_VCC_FWD_SNIFF
Harald Welte2d3371e2015-11-30 11:59:03 +010099
Kévin Redon45ad62d2018-06-07 18:56:41 +0200100/** 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 Redon2c4e2af2018-06-06 17:02:33 +0200106/** 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 Welte2d3371e2015-11-30 11:59:03 +0100119
Kévin Redonff3d8492018-08-06 17:57:20 +0200120/** 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 Redon2c4e2af2018-06-06 17:02:33 +0200125/** 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 Welte3ecbf672017-03-03 02:10:34 +0100135#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
136
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200137/** Supported modes */
138/* SIMtrace board supports sniffer mode */
Kévin Redon36abece2018-06-04 16:30:01 +0200139#define HAVE_SNIFFER
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200140/* SIMtrace board supports CCID mode */
Kévin Redon927ffb42018-06-24 11:30:31 +0200141//#define HAVE_CCID
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200142/* SIMtrace board supports card emulation mode */
Kévin Redon927ffb42018-06-24 11:30:31 +0200143//#define HAVE_CARDEM
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200144/* SIMtrace board supports man-in-the-middle mode */
Harald Welteba2ad562017-11-28 19:49:41 +0100145//#define HAVE_MITM