blob: 35c9426b6c91b55c43221e8af7673cd94614bf70 [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 Redone2b0f972018-08-28 19:13:06 +020029/** oscillator used as main clock source (in Hz) */
Harald Weltea02b6412016-08-21 18:32:12 +020030#define BOARD_MAINOSC 18432000
Kévin Redone2b0f972018-08-28 19:13:06 +020031/** desired main clock frequency (in Hz, based on BOARD_MAINOSC) */
32#define BOARD_MCK 58982400 // 18.432 * 16 / 5
Harald Weltea02b6412016-08-21 18:32:12 +020033
Kévin Redon9acff5e2019-10-01 19:44:44 +020034/** 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 Redon2c4e2af2018-06-06 17:02:33 +020049/** 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 Redone5efbb12019-09-24 18:36:55 +020053#define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Kévin Redonee62a9d2018-06-11 13:42:23 +020054/* Enable powering the SIM card */
55#define PWR_PINS SIM_PWEN_PIN
Kévin Redon2c4e2af2018-06-06 17:02:33 +020056/* 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 Redon45ad62d2018-06-07 18:56:41 +020063#define PIN_SIM_RST {PIO_PA7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +020064/* 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 Redon2c4e2af2018-06-06 17:02:33 +020068/* 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) */
Kévin Redon8b6991c2019-05-14 23:20:15 +020077#define PIN_USIM1_VCC {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_EDGE | PIO_DEGLITCH }
Kévin Redon2c4e2af2018-06-06 17:02:33 +020078/* Phone USIM slot 1 RST pin (active low; RST_PHONE in schematic) */
Kévin Redon8b6991c2019-05-14 23:20:15 +020079#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_EDGE | PIO_DEGLITCH }
Kévin Redon2c4e2af2018-06-06 17:02:33 +020080/* 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 Redonee62a9d2018-06-11 13:42:23 +020091/** Default pin configuration **/
Kévin Redon2c4e2af2018-06-06 17:02:33 +020092/* 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 Welte2d3371e2015-11-30 11:59:03 +010098
99/** Sniffer configuration **/
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200100/* 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 +0100101#define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200102/* Connect I/O line between card and phone using bus switch (low connects signals on bus switch) */
Harald Welte2d3371e2015-11-30 11:59:03 +0100103#define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200104/* Connect all lines (VPP, CLK, RST, and I/O) between card and phone */
Harald Welte2d3371e2015-11-30 11:59:03 +0100105#define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF
Kévin Redona2b36762018-06-24 11:31:36 +0200106/* Card RST reset signal input (use as input since the phone will drive it) */
Kévin Redon7be52ec2018-06-25 15:49:28 +0200107#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 +0200108/* Pins used to sniff phone-card communication */
Kévin Redona2b36762018-06-24 11:31:36 +0200109#define PINS_SIM_SNIFF PIN_SIM_IO, PIN_SIM_CLK, PIN_SIM_RST_SNIFF
Kévin Redon45ad62d2018-06-07 18:56:41 +0200110/* Disable power converter 4.5-6V to 3.3V (active high) */
Kévin Redone5efbb12019-09-24 18:36:55 +0200111#define PIN_SIM_PWEN_SNIFF {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Kévin Redon45ad62d2018-06-07 18:56:41 +0200112/* Enable power switch to forward VCC_PHONE to VCC_SIM (active high) */
Kévin Redone5efbb12019-09-24 18:36:55 +0200113#define PIN_VCC_FWD_SNIFF {PIO_PA26, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200114/* Use phone VCC to power card */
Kévin Redonee62a9d2018-06-11 13:42:23 +0200115#define PINS_PWR_SNIFF PIN_SIM_PWEN_SNIFF, PIN_VCC_FWD_SNIFF
Harald Welte2d3371e2015-11-30 11:59:03 +0100116
Kévin Redon45ad62d2018-06-07 18:56:41 +0200117/** 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 Redon2c4e2af2018-06-06 17:02:33 +0200123/** 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 Welte2d3371e2015-11-30 11:59:03 +0100136
Kévin Redonff3d8492018-08-06 17:57:20 +0200137/** 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 Redon2c4e2af2018-06-06 17:02:33 +0200142/** 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 Welte3ecbf672017-03-03 02:10:34 +0100152#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
153
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200154/** Supported modes */
155/* SIMtrace board supports sniffer mode */
Kévin Redon36abece2018-06-04 16:30:01 +0200156#define HAVE_SNIFFER
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200157/* SIMtrace board supports CCID mode */
Kévin Redon927ffb42018-06-24 11:30:31 +0200158//#define HAVE_CCID
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200159/* SIMtrace board supports card emulation mode */
Kévin Redon927ffb42018-06-24 11:30:31 +0200160//#define HAVE_CARDEM
Kévin Redon2c4e2af2018-06-06 17:02:33 +0200161/* SIMtrace board supports man-in-the-middle mode */
Harald Welteba2ad562017-11-28 19:49:41 +0100162//#define HAVE_MITM