blob: b7bec1cb21d2859aeec57999790f3bb45d10ed3e [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 Quast27c643d2015-02-24 19:09:08 +010027#define MIN(a, b) ((a < b) ? a : b)
28
Christina Quastdcb67a22014-12-10 16:30:24 +010029#ifdef __GNUC__
30#undef __GNUC__
31#endif
Christina Quastd51b5f42014-12-02 13:21:17 +010032
33/** Name of the board */
34#define BOARD_NAME "SAM3S-SIMTRACE"
35/** Board definition */
36#define simtrace
37/** Family definition (already defined) */
38#define sam3s
39/** Core definition */
40#define cortexm3
41
Christina Quast5f46d042015-01-03 22:16:11 +010042#define BOARD_MAINOSC 18432000
Christina Quastd51b5f42014-12-02 13:21:17 +010043#define BOARD_MCK 48000000
44
45#define LED_RED PIO_PA17
46#define LED_GREEN PIO_PA18
47
Christina Quast0f1b36f2014-12-16 10:54:59 +010048#define PIN_LED_RED {LED_RED, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
49#define PIN_LED_GREEN {LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
50#define PINS_LEDS PIN_LED_RED, PIN_LED_GREEN
51
52#define LED_NUM_RED 0
53#define LED_NUM_GREEN 1
54
Christina Quast27c643d2015-02-24 19:09:08 +010055/** Phone (SIM card emulator)/CCID Reader/MITM configuration **/
56/* Normally the communication lines between phone and SIM card are disconnected */
57// Disconnect SIM card I/O, VPP line from the phone lines
58// FIXME: Per default pins are input, therefore high-impedance, therefore they don not activate the bus switch, right?
59#define PIN_SC_SW_DEFAULT {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
60// Disconnect SIM card RST, CLK line from the phone lines
61#define PIN_IO_SW_DEFAULT {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
62#define PINS_BUS
63
64/** Sniffer configuration **/
Christina Quastf7c28e02015-01-23 20:57:52 +010065// Connect VPP, CLK and RST lines from smartcard to the phone
Christina Quast27c643d2015-02-24 19:09:08 +010066#define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
67#define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
68#define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF
69
70#define PINS_SIM_SNIFF_SIM PIN_PHONE_IO, PIN_PHONE_CLK
71
72
Christina Quast5f46d042015-01-03 22:16:11 +010073
Christina Quastd51b5f42014-12-02 13:21:17 +010074/** USART0 pin RX */
75#define PIN_USART0_RXD {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
76/** USART0 pin TX */
77#define PIN_USART0_TXD {PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
78
79#define BOARD_PIN_USART_RXD PIN_USART0_RXD
80#define BOARD_PIN_USART_TXD PIN_USART0_TXD
81
82#define BOARD_ID_USART ID_USART0
83#define BOARD_USART_BASE USART0
84
85#define PINS_UART { PIO_PA9A_URXD0|PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
86
Christina Quastdcb67a22014-12-10 16:30:24 +010087/** UART0 */
88/** Console baudrate always using 115200. */
89#define CONSOLE_BAUDRATE 115200
90/** Usart Hw interface used by the console (UART0). */
91#define CONSOLE_USART UART0
92/** Usart Hw ID used by the console (UART0). */
93#define CONSOLE_ID ID_UART0
94/** Pins description corresponding to Rxd,Txd, (UART pins) */
95#define CONSOLE_PINS {PINS_UART}
96
Christina Quastdcb67a22014-12-10 16:30:24 +010097/// Smartcard detection pin
Christina Quast11e80ae2014-12-19 19:14:02 +010098// FIXME: add connect pin as iso pin...should it be periph b or interrupt oder input?
Christina Quastf7c28e02015-01-23 20:57:52 +010099#define USART_SIM USART0
100#define ID_USART_SIM ID_USART0
101#define USART_PHONE USART1
102#define ID_USART_PHONE ID_USART1
Christina Quast11e80ae2014-12-19 19:14:02 +0100103
Christina Quast5f46d042015-01-03 22:16:11 +0100104#define SIM_PWEN PIO_PA5
105#define VCC_FWD PIO_PA26
106
Christina Quast11e80ae2014-12-19 19:14:02 +0100107#define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
108
109#define SW_SIM PIO_PA8
Christina Quast5f46d042015-01-03 22:16:11 +0100110#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 +0100111//#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 +0100112
Christina Quastf7c28e02015-01-23 20:57:52 +0100113/// PIN used for resetting the smartcard
Christina Quast11e80ae2014-12-19 19:14:02 +0100114#define RST_SIM (1 << 7)
115// FIXME: Card is resetted with pin set to 0 --> PIO_OUTPUT_1 as default is right?
Christina Quast5f46d042015-01-03 22:16:11 +0100116#define PIN_ISO7816_RSTMC {RST_SIM, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100117
Christina Quastdcb67a22014-12-10 16:30:24 +0100118/// Pins used for connect the smartcard
Christina Quastb4554272015-01-30 16:28:45 +0100119#define PIN_SIM_IO {PIO_PA1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
120#define PIN_SIM_IO_INPUT {PIO_PA6, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
121#define PIN_SIM_CLK {PIO_PA2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
122#define PIN_SIM_CLK_INPUT {PIO_PA4, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100123//#define PINS_ISO7816 PIN_USART1_TXD, PIN_USART1_SCK, PIN_ISO7816_RSTMC
Christina Quastb4554272015-01-30 16:28:45 +0100124#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 +0100125
Christina Quastf7c28e02015-01-23 20:57:52 +0100126
127#define VCC_PHONE {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
128#define PIN_ISO7816_RST_PHONE {PIO_PA24, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastb4554272015-01-30 16:28:45 +0100129#define PIN_PHONE_IO_INPUT {PIO_PA21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100130#define PIN_PHONE_IO {PIO_PA22, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
131#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 +0100132//#define PIN_PHONE_CLK {PIO_PA23A_SCK1, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} // External Clock Input on PA28
133#define PIN_PHONE_CLK_INPUT {PIO_PA29, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100134#define PINS_ISO7816_PHONE PIN_PHONE_IO, PIN_PHONE_CLK, PIN_ISO7816_RST_PHONE
135//, VCC_PHONE
136
137
Christina Quast5f46d042015-01-03 22:16:11 +0100138//** SPI interface **/
139/// SPI MISO pin definition (PA12).
140#define PIN_SPI_MISO {1 << 12, PIOA, PIOA, PIO_PERIPH_A, PIO_PULLUP}
141/// SPI MOSI pin definition (PA13).
142#define PIN_SPI_MOSI {1 << 13, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
143/// SPI SPCK pin definition (PA14).
144#define PIN_SPI_SPCK {1 << 14, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
145/// SPI pins definition. Contains MISO, MOSI & SPCK (PA12, PA13 & PA14).
146#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SPCK
147/// SPI chip select 0 pin definition (PA11).
148#define PIN_SPI_NPCS0 {1 << 11, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
149
150//** USB **/
Christina Quast27c643d2015-02-24 19:09:08 +0100151// USB pull-up control pin definition (PA16).
152// Default: 1 (USB Pullup deactivated)
Christina Quast5f46d042015-01-03 22:16:11 +0100153#define PIN_USB_PULLUP {1 << 16, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
154
155// Board has UDP controller
156#define BOARD_USB_UDP
157// D+ has external pull-up
158#define BOARD_USB_PULLUP_EXTERNAL
159
160#define BOARD_USB_NUMENDPOINTS 8
161
162// FIXME: in all other cases return 0?
163#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 4) || (i == 5))? 512 : 64)
164#define BOARD_USB_ENDPOINTS_BANKS(i) (((i == 0) || (i == 3)) ? 1 : 2)
165
166/// USB attributes configuration descriptor (bus or self powered, remote wakeup)
167//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
168#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
169//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
170
171#define ATMEL_VENDOR_ID 0x03EB
172#define SIMTRACE_PRODUCT_ID 0x6004
173//#define OPENPCD_VENDOR_ID 0x16c0
174//#define SIMTRACE_PRODUCT_ID 0x0762
175#define USB_VENDOR_ID OPENPCD_VENDOR_ID
176#define USB_PRODUCT_ID SIMTRACE_PRODUCT_ID
177
Christina Quastdcb67a22014-12-10 16:30:24 +0100178
Christina Quastd51b5f42014-12-02 13:21:17 +0100179#endif