blob: 89655a3dcfcc4ce58b5afe5b0966e62a0322e5df [file] [log] [blame]
Christina Quastd51b5f42014-12-02 13:21:17 +01001#ifndef _BOARD_
2#define _BOARD_
3
Christina Quastdcb67a22014-12-10 16:30:24 +01004/** Headers */
Christina Quastd51b5f42014-12-02 13:21:17 +01005#include "chip.h"
Christina Quast5f46d042015-01-03 22:16:11 +01006/* We need this for a nop instruction in USB_HAL.c */
7#define __CC_ARM
Christina Quastdcb67a22014-12-10 16:30:24 +01008
9/** Board */
10#include "board_lowlevel.h"
11#include "uart_console.h"
12#include "iso7816_4.h"
Christina Quast0f1b36f2014-12-16 10:54:59 +010013#include "led.h"
Christina Quast5f46d042015-01-03 22:16:11 +010014#include "cciddriver.h"
15#include "USBD.h"
Christina Quastdcb67a22014-12-10 16:30:24 +010016
Christina Quast27c643d2015-02-24 19:09:08 +010017#include "USBD_Config.h"
18#include "USBDDriver.h"
19
Christina Quastdcb67a22014-12-10 16:30:24 +010020/** Highlevel */
21#include "trace.h"
22#include "stdio.h"
Christina Quast99f9f7b2014-12-13 13:30:31 +010023#include "stdlib.h"
Christina Quastdcb67a22014-12-10 16:30:24 +010024#include "string.h"
Christina Quastf6264fa2015-01-28 17:58:30 +010025#include "inttypes.h"
Christina Quastdcb67a22014-12-10 16:30:24 +010026
Christina Quastc0aa7692015-02-25 14:02:01 +010027#include "simtrace.h"
28
Christina Quast27c643d2015-02-24 19:09:08 +010029#define MIN(a, b) ((a < b) ? a : b)
30
Christina Quastdcb67a22014-12-10 16:30:24 +010031#ifdef __GNUC__
32#undef __GNUC__
33#endif
Christina Quastd51b5f42014-12-02 13:21:17 +010034
35/** Name of the board */
36#define BOARD_NAME "SAM3S-SIMTRACE"
37/** Board definition */
38#define simtrace
39/** Family definition (already defined) */
40#define sam3s
41/** Core definition */
42#define cortexm3
43
Christina Quast5f46d042015-01-03 22:16:11 +010044#define BOARD_MAINOSC 18432000
Christina Quastd51b5f42014-12-02 13:21:17 +010045#define BOARD_MCK 48000000
46
47#define LED_RED PIO_PA17
48#define LED_GREEN PIO_PA18
49
Christina Quast0f1b36f2014-12-16 10:54:59 +010050#define PIN_LED_RED {LED_RED, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
51#define PIN_LED_GREEN {LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
52#define PINS_LEDS PIN_LED_RED, PIN_LED_GREEN
53
54#define LED_NUM_RED 0
55#define LED_NUM_GREEN 1
56
Christina Quast27c643d2015-02-24 19:09:08 +010057/** Phone (SIM card emulator)/CCID Reader/MITM configuration **/
58/* Normally the communication lines between phone and SIM card are disconnected */
59// Disconnect SIM card I/O, VPP line from the phone lines
60// FIXME: Per default pins are input, therefore high-impedance, therefore they don not activate the bus switch, right?
61#define PIN_SC_SW_DEFAULT {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
62// Disconnect SIM card RST, CLK line from the phone lines
63#define PIN_IO_SW_DEFAULT {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quast394b8942015-02-27 15:31:09 +010064#define PINS_BUS_DEFAULT PIN_SC_SW_DEFAULT, PIN_IO_SW_DEFAULT
Christina Quast27c643d2015-02-24 19:09:08 +010065
66/** Sniffer configuration **/
Christina Quastf7c28e02015-01-23 20:57:52 +010067// Connect VPP, CLK and RST lines from smartcard to the phone
Christina Quast27c643d2015-02-24 19:09:08 +010068#define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
69#define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
70#define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF
71
72#define PINS_SIM_SNIFF_SIM PIN_PHONE_IO, PIN_PHONE_CLK
73
74
Christina Quast5f46d042015-01-03 22:16:11 +010075
Christina Quastd51b5f42014-12-02 13:21:17 +010076/** USART0 pin RX */
77#define PIN_USART0_RXD {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
78/** USART0 pin TX */
79#define PIN_USART0_TXD {PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
80
81#define BOARD_PIN_USART_RXD PIN_USART0_RXD
82#define BOARD_PIN_USART_TXD PIN_USART0_TXD
83
84#define BOARD_ID_USART ID_USART0
85#define BOARD_USART_BASE USART0
86
87#define PINS_UART { PIO_PA9A_URXD0|PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
88
Christina Quastdcb67a22014-12-10 16:30:24 +010089/** UART0 */
90/** Console baudrate always using 115200. */
91#define CONSOLE_BAUDRATE 115200
92/** Usart Hw interface used by the console (UART0). */
93#define CONSOLE_USART UART0
94/** Usart Hw ID used by the console (UART0). */
95#define CONSOLE_ID ID_UART0
96/** Pins description corresponding to Rxd,Txd, (UART pins) */
97#define CONSOLE_PINS {PINS_UART}
98
Christina Quastdcb67a22014-12-10 16:30:24 +010099/// Smartcard detection pin
Christina Quast11e80ae2014-12-19 19:14:02 +0100100// FIXME: add connect pin as iso pin...should it be periph b or interrupt oder input?
Christina Quast800019f2015-03-04 13:40:54 +0100101#define BOARD_ISO7816_BASE_USART USART0
102#define BOARD_ISO7816_ID_USART ID_USART0
103
Christina Quastf7c28e02015-01-23 20:57:52 +0100104#define USART_SIM USART0
105#define ID_USART_SIM ID_USART0
106#define USART_PHONE USART1
107#define ID_USART_PHONE ID_USART1
Christina Quast11e80ae2014-12-19 19:14:02 +0100108
Christina Quast5f46d042015-01-03 22:16:11 +0100109#define SIM_PWEN PIO_PA5
110#define VCC_FWD PIO_PA26
111
Christina Quast11e80ae2014-12-19 19:14:02 +0100112#define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
113
Christina Quast83628d42015-03-03 23:08:44 +0100114#define PWR_PINS \
115 /* Enable power converter 4.5-6V to 3.3V; low: off */ \
116 {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, \
117 /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */ \
118 {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
119
120
Christina Quast11e80ae2014-12-19 19:14:02 +0100121#define SW_SIM PIO_PA8
Christina Quast5f46d042015-01-03 22:16:11 +0100122#define SMARTCARD_CONNECT_PIN {SW_SIM, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_DEGLITCH | PIO_IT_EDGE }
Christina Quast11e80ae2014-12-19 19:14:02 +0100123//#define SMARTCARD_CONNECT_PIN {SW_SIM, PIOB, ID_PIOB, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_IT_EDGE}
Christina Quastdcb67a22014-12-10 16:30:24 +0100124
Christina Quastf7c28e02015-01-23 20:57:52 +0100125/// PIN used for resetting the smartcard
Christina Quast11e80ae2014-12-19 19:14:02 +0100126#define RST_SIM (1 << 7)
127// FIXME: Card is resetted with pin set to 0 --> PIO_OUTPUT_1 as default is right?
Christina Quast5f46d042015-01-03 22:16:11 +0100128#define PIN_ISO7816_RSTMC {RST_SIM, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100129
Christina Quastdcb67a22014-12-10 16:30:24 +0100130/// Pins used for connect the smartcard
Christina Quast800019f2015-03-04 13:40:54 +0100131#define PIN_SIM_IO_INPUT {PIO_PA1, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
132#define PIN_SIM_IO {PIO_PA6, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
Christina Quastb4554272015-01-30 16:28:45 +0100133#define PIN_SIM_CLK {PIO_PA2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
134#define PIN_SIM_CLK_INPUT {PIO_PA4, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100135//#define PINS_ISO7816 PIN_USART1_TXD, PIN_USART1_SCK, PIN_ISO7816_RSTMC
Christina Quastb4554272015-01-30 16:28:45 +0100136#define PINS_ISO7816 PIN_SIM_IO, PIN_SIM_CLK, PIN_ISO7816_RSTMC // SIM_PWEN_PIN, PIN_SIM_IO2, PIN_SIM_CLK2
Christina Quast5f46d042015-01-03 22:16:11 +0100137
Christina Quastf7c28e02015-01-23 20:57:52 +0100138
139#define VCC_PHONE {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quasta3496f42015-03-27 18:54:50 +0100140#define PIN_ISO7816_RST_PHONE {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_RISE_EDGE }
Christina Quastb4554272015-01-30 16:28:45 +0100141#define PIN_PHONE_IO_INPUT {PIO_PA21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100142#define PIN_PHONE_IO {PIO_PA22, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
Christina Quastfab4ce92015-04-06 20:22:59 +0200143#define PIN_PHONE_CLK {PIO_PA23A_SCK1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} // External Clock Input on PA28
Christina Quastb4554272015-01-30 16:28:45 +0100144//#define PIN_PHONE_CLK {PIO_PA23A_SCK1, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} // External Clock Input on PA28
Christina Quastfab4ce92015-04-06 20:22:59 +0200145#define PIN_PHONE_CLK_INPUT {PIO_PA29, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100146#define PINS_ISO7816_PHONE PIN_PHONE_IO, PIN_PHONE_CLK, PIN_ISO7816_RST_PHONE
147//, VCC_PHONE
148
149
Christina Quast5f46d042015-01-03 22:16:11 +0100150//** SPI interface **/
151/// SPI MISO pin definition (PA12).
152#define PIN_SPI_MISO {1 << 12, PIOA, PIOA, PIO_PERIPH_A, PIO_PULLUP}
153/// SPI MOSI pin definition (PA13).
154#define PIN_SPI_MOSI {1 << 13, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
155/// SPI SPCK pin definition (PA14).
156#define PIN_SPI_SPCK {1 << 14, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
157/// SPI pins definition. Contains MISO, MOSI & SPCK (PA12, PA13 & PA14).
158#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SPCK
159/// SPI chip select 0 pin definition (PA11).
160#define PIN_SPI_NPCS0 {1 << 11, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
161
162//** USB **/
Christina Quast27c643d2015-02-24 19:09:08 +0100163// USB pull-up control pin definition (PA16).
164// Default: 1 (USB Pullup deactivated)
Christina Quast5f46d042015-01-03 22:16:11 +0100165#define PIN_USB_PULLUP {1 << 16, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
166
167// Board has UDP controller
168#define BOARD_USB_UDP
169// D+ has external pull-up
170#define BOARD_USB_PULLUP_EXTERNAL
171
172#define BOARD_USB_NUMENDPOINTS 8
173
174// FIXME: in all other cases return 0?
175#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 4) || (i == 5))? 512 : 64)
176#define BOARD_USB_ENDPOINTS_BANKS(i) (((i == 0) || (i == 3)) ? 1 : 2)
177
178/// USB attributes configuration descriptor (bus or self powered, remote wakeup)
179//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
180#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
181//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
182
183#define ATMEL_VENDOR_ID 0x03EB
184#define SIMTRACE_PRODUCT_ID 0x6004
185//#define OPENPCD_VENDOR_ID 0x16c0
186//#define SIMTRACE_PRODUCT_ID 0x0762
187#define USB_VENDOR_ID OPENPCD_VENDOR_ID
188#define USB_PRODUCT_ID SIMTRACE_PRODUCT_ID
189
Christina Quastdcb67a22014-12-10 16:30:24 +0100190
Christina Quastd51b5f42014-12-02 13:21:17 +0100191#endif