blob: cb58f159f3a0fcb7a16e4569dffd500892386b04 [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
17/** Highlevel */
18#include "trace.h"
19#include "stdio.h"
Christina Quast99f9f7b2014-12-13 13:30:31 +010020#include "stdlib.h"
Christina Quastdcb67a22014-12-10 16:30:24 +010021#include "string.h"
Christina Quastf6264fa2015-01-28 17:58:30 +010022#include "inttypes.h"
Christina Quastdcb67a22014-12-10 16:30:24 +010023
24#ifdef __GNUC__
25#undef __GNUC__
26#endif
Christina Quastd51b5f42014-12-02 13:21:17 +010027
28/** Name of the board */
29#define BOARD_NAME "SAM3S-SIMTRACE"
30/** Board definition */
31#define simtrace
32/** Family definition (already defined) */
33#define sam3s
34/** Core definition */
35#define cortexm3
36
Christina Quast5f46d042015-01-03 22:16:11 +010037#define BOARD_MAINOSC 18432000
Christina Quastd51b5f42014-12-02 13:21:17 +010038#define BOARD_MCK 48000000
39
40#define LED_RED PIO_PA17
41#define LED_GREEN PIO_PA18
42
Christina Quast0f1b36f2014-12-16 10:54:59 +010043#define PIN_LED_RED {LED_RED, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
44#define PIN_LED_GREEN {LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
45#define PINS_LEDS PIN_LED_RED, PIN_LED_GREEN
46
47#define LED_NUM_RED 0
48#define LED_NUM_GREEN 1
49
Christina Quastf7c28e02015-01-23 20:57:52 +010050/** Phone */
51// Connect VPP, CLK and RST lines from smartcard to the phone
52//#define PIN_SC_SW {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
53// Temporary fix: do not connect
54#define PIN_SC_SW {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
55// Connect SIM card I/O lines to the phone
56//#define PIN_IO_SW {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
57// FIXME: Temporary fix: do not connect
58#define PIN_IO_SW {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quast5f46d042015-01-03 22:16:11 +010059
Christina Quastd51b5f42014-12-02 13:21:17 +010060/** USART0 pin RX */
61#define PIN_USART0_RXD {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
62/** USART0 pin TX */
63#define PIN_USART0_TXD {PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
64
65#define BOARD_PIN_USART_RXD PIN_USART0_RXD
66#define BOARD_PIN_USART_TXD PIN_USART0_TXD
67
68#define BOARD_ID_USART ID_USART0
69#define BOARD_USART_BASE USART0
70
71#define PINS_UART { PIO_PA9A_URXD0|PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
72
Christina Quastdcb67a22014-12-10 16:30:24 +010073/** UART0 */
74/** Console baudrate always using 115200. */
75#define CONSOLE_BAUDRATE 115200
76/** Usart Hw interface used by the console (UART0). */
77#define CONSOLE_USART UART0
78/** Usart Hw ID used by the console (UART0). */
79#define CONSOLE_ID ID_UART0
80/** Pins description corresponding to Rxd,Txd, (UART pins) */
81#define CONSOLE_PINS {PINS_UART}
82
Christina Quastdcb67a22014-12-10 16:30:24 +010083/// Smartcard detection pin
Christina Quast11e80ae2014-12-19 19:14:02 +010084// FIXME: add connect pin as iso pin...should it be periph b or interrupt oder input?
Christina Quastf7c28e02015-01-23 20:57:52 +010085#define USART_SIM USART0
86#define ID_USART_SIM ID_USART0
87#define USART_PHONE USART1
88#define ID_USART_PHONE ID_USART1
Christina Quast11e80ae2014-12-19 19:14:02 +010089
Christina Quast5f46d042015-01-03 22:16:11 +010090#define SIM_PWEN PIO_PA5
91#define VCC_FWD PIO_PA26
92
Christina Quast11e80ae2014-12-19 19:14:02 +010093#define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
94
95#define SW_SIM PIO_PA8
Christina Quast5f46d042015-01-03 22:16:11 +010096#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 +010097//#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 +010098
Christina Quastf7c28e02015-01-23 20:57:52 +010099/// PIN used for resetting the smartcard
Christina Quast11e80ae2014-12-19 19:14:02 +0100100#define RST_SIM (1 << 7)
101// FIXME: Card is resetted with pin set to 0 --> PIO_OUTPUT_1 as default is right?
Christina Quast5f46d042015-01-03 22:16:11 +0100102#define PIN_ISO7816_RSTMC {RST_SIM, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100103
Christina Quastdcb67a22014-12-10 16:30:24 +0100104/// Pins used for connect the smartcard
Christina Quastb4554272015-01-30 16:28:45 +0100105#define PIN_SIM_IO {PIO_PA1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
106#define PIN_SIM_IO_INPUT {PIO_PA6, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
107#define PIN_SIM_CLK {PIO_PA2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
108#define PIN_SIM_CLK_INPUT {PIO_PA4, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastdcb67a22014-12-10 16:30:24 +0100109//#define PINS_ISO7816 PIN_USART1_TXD, PIN_USART1_SCK, PIN_ISO7816_RSTMC
Christina Quastb4554272015-01-30 16:28:45 +0100110#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 +0100111
Christina Quastf7c28e02015-01-23 20:57:52 +0100112
113#define VCC_PHONE {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
114#define PIN_ISO7816_RST_PHONE {PIO_PA24, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Christina Quastb4554272015-01-30 16:28:45 +0100115#define PIN_PHONE_IO_INPUT {PIO_PA21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100116#define PIN_PHONE_IO {PIO_PA22, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
117#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 +0100118//#define PIN_PHONE_CLK {PIO_PA23A_SCK1, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} // External Clock Input on PA28
119#define PIN_PHONE_CLK_INPUT {PIO_PA29, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
Christina Quastf7c28e02015-01-23 20:57:52 +0100120#define PINS_ISO7816_PHONE PIN_PHONE_IO, PIN_PHONE_CLK, PIN_ISO7816_RST_PHONE
121//, VCC_PHONE
122
123
Christina Quast5f46d042015-01-03 22:16:11 +0100124//** SPI interface **/
125/// SPI MISO pin definition (PA12).
126#define PIN_SPI_MISO {1 << 12, PIOA, PIOA, PIO_PERIPH_A, PIO_PULLUP}
127/// SPI MOSI pin definition (PA13).
128#define PIN_SPI_MOSI {1 << 13, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
129/// SPI SPCK pin definition (PA14).
130#define PIN_SPI_SPCK {1 << 14, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
131/// SPI pins definition. Contains MISO, MOSI & SPCK (PA12, PA13 & PA14).
132#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SPCK
133/// SPI chip select 0 pin definition (PA11).
134#define PIN_SPI_NPCS0 {1 << 11, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT}
135
136//** USB **/
137/// USB pull-up control pin definition (PA16).
138#define PIN_USB_PULLUP {1 << 16, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
139
140// Board has UDP controller
141#define BOARD_USB_UDP
142// D+ has external pull-up
143#define BOARD_USB_PULLUP_EXTERNAL
144
145#define BOARD_USB_NUMENDPOINTS 8
146
147// FIXME: in all other cases return 0?
148#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 4) || (i == 5))? 512 : 64)
149#define BOARD_USB_ENDPOINTS_BANKS(i) (((i == 0) || (i == 3)) ? 1 : 2)
150
151/// USB attributes configuration descriptor (bus or self powered, remote wakeup)
152//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
153#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
154//#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
155
156#define ATMEL_VENDOR_ID 0x03EB
157#define SIMTRACE_PRODUCT_ID 0x6004
158//#define OPENPCD_VENDOR_ID 0x16c0
159//#define SIMTRACE_PRODUCT_ID 0x0762
160#define USB_VENDOR_ID OPENPCD_VENDOR_ID
161#define USB_PRODUCT_ID SIMTRACE_PRODUCT_ID
162
Christina Quastdcb67a22014-12-10 16:30:24 +0100163
Christina Quastd51b5f42014-12-02 13:21:17 +0100164#endif