blob: d3644d4ce73b3812e463ff956985bf2b01b94192 [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 Quastf7c28e02015-01-23 20:57:52 +0100101#define USART_SIM USART0
102#define ID_USART_SIM ID_USART0
103#define USART_PHONE USART1
104#define ID_USART_PHONE ID_USART1
Christina Quast11e80ae2014-12-19 19:14:02 +0100105
Christina Quast5f46d042015-01-03 22:16:11 +0100106#define SIM_PWEN PIO_PA5
107#define VCC_FWD PIO_PA26
108
Christina Quast11e80ae2014-12-19 19:14:02 +0100109#define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
110
Christina Quast83628d42015-03-03 23:08:44 +0100111#define PWR_PINS \
112 /* Enable power converter 4.5-6V to 3.3V; low: off */ \
113 {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}, \
114 /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */ \
115 {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
116
117
Christina Quast11e80ae2014-12-19 19:14:02 +0100118#define SW_SIM PIO_PA8
Christina Quast5f46d042015-01-03 22:16:11 +0100119#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 +0100120//#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 +0100121
Christina Quastf7c28e02015-01-23 20:57:52 +0100122/// PIN used for resetting the smartcard
Christina Quast11e80ae2014-12-19 19:14:02 +0100123#define RST_SIM (1 << 7)
124// FIXME: Card is resetted with pin set to 0 --> PIO_OUTPUT_1 as default is right?
Christina Quast5f46d042015-01-03 22:16:11 +0100125#define PIN_ISO7816_RSTMC {RST_SIM, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100126
Christina Quastdcb67a22014-12-10 16:30:24 +0100127/// Pins used for connect the smartcard
Christina Quastb4554272015-01-30 16:28:45 +0100128#define PIN_SIM_IO {PIO_PA1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
129#define PIN_SIM_IO_INPUT {PIO_PA6, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
130#define PIN_SIM_CLK {PIO_PA2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
131#define PIN_SIM_CLK_INPUT {PIO_PA4, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100132//#define PINS_ISO7816 PIN_USART1_TXD, PIN_USART1_SCK, PIN_ISO7816_RSTMC
Christina Quastb4554272015-01-30 16:28:45 +0100133#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 +0100134
Christina Quastf7c28e02015-01-23 20:57:52 +0100135
136#define VCC_PHONE {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
137#define PIN_ISO7816_RST_PHONE {PIO_PA24, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastb4554272015-01-30 16:28:45 +0100138#define PIN_PHONE_IO_INPUT {PIO_PA21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100139#define PIN_PHONE_IO {PIO_PA22, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
140#define PIN_PHONE_CLK {PIO_PA23A_SCK1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} // External Clock Input on PA28
Christina Quastb4554272015-01-30 16:28:45 +0100141//#define PIN_PHONE_CLK {PIO_PA23A_SCK1, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} // External Clock Input on PA28
142#define PIN_PHONE_CLK_INPUT {PIO_PA29, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100143#define PINS_ISO7816_PHONE PIN_PHONE_IO, PIN_PHONE_CLK, PIN_ISO7816_RST_PHONE
144//, VCC_PHONE
145
146
Christina Quast5f46d042015-01-03 22:16:11 +0100147//** SPI interface **/
148/// SPI MISO pin definition (PA12).
149#define PIN_SPI_MISO {1 << 12, PIOA, PIOA, PIO_PERIPH_A, PIO_PULLUP}
150/// SPI MOSI pin definition (PA13).
151#define PIN_SPI_MOSI {1 << 13, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
152/// SPI SPCK pin definition (PA14).
153#define PIN_SPI_SPCK {1 << 14, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
154/// SPI pins definition. Contains MISO, MOSI & SPCK (PA12, PA13 & PA14).
155#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SPCK
156/// SPI chip select 0 pin definition (PA11).
157#define PIN_SPI_NPCS0 {1 << 11, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
158
159//** USB **/
Christina Quast27c643d2015-02-24 19:09:08 +0100160// USB pull-up control pin definition (PA16).
161// Default: 1 (USB Pullup deactivated)
Christina Quast5f46d042015-01-03 22:16:11 +0100162#define PIN_USB_PULLUP {1 << 16, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
163
164// Board has UDP controller
165#define BOARD_USB_UDP
166// D+ has external pull-up
167#define BOARD_USB_PULLUP_EXTERNAL
168
169#define BOARD_USB_NUMENDPOINTS 8
170
171// FIXME: in all other cases return 0?
172#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 4) || (i == 5))? 512 : 64)
173#define BOARD_USB_ENDPOINTS_BANKS(i) (((i == 0) || (i == 3)) ? 1 : 2)
174
175/// USB attributes configuration descriptor (bus or self powered, remote wakeup)
176//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
177#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
178//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
179
180#define ATMEL_VENDOR_ID 0x03EB
181#define SIMTRACE_PRODUCT_ID 0x6004
182//#define OPENPCD_VENDOR_ID 0x16c0
183//#define SIMTRACE_PRODUCT_ID 0x0762
184#define USB_VENDOR_ID OPENPCD_VENDOR_ID
185#define USB_PRODUCT_ID SIMTRACE_PRODUCT_ID
186
Christina Quastdcb67a22014-12-10 16:30:24 +0100187
Christina Quastd51b5f42014-12-02 13:21:17 +0100188#endif