Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 1 | #ifndef _BOARD_ |
| 2 | #define _BOARD_ |
| 3 | |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 4 | /** Headers */ |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 5 | #include "chip.h" |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 6 | /* We need this for a nop instruction in USB_HAL.c */ |
| 7 | #define __CC_ARM |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 8 | |
| 9 | /** Board */ |
| 10 | #include "board_lowlevel.h" |
| 11 | #include "uart_console.h" |
| 12 | #include "iso7816_4.h" |
Christina Quast | 0f1b36f | 2014-12-16 10:54:59 +0100 | [diff] [blame] | 13 | #include "led.h" |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 14 | #include "cciddriver.h" |
| 15 | #include "USBD.h" |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 16 | |
Christina Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 17 | #include "USBD_Config.h" |
| 18 | #include "USBDDriver.h" |
| 19 | |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 20 | /** Highlevel */ |
| 21 | #include "trace.h" |
| 22 | #include "stdio.h" |
Christina Quast | 99f9f7b | 2014-12-13 13:30:31 +0100 | [diff] [blame] | 23 | #include "stdlib.h" |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 24 | #include "string.h" |
Christina Quast | f6264fa | 2015-01-28 17:58:30 +0100 | [diff] [blame] | 25 | #include "inttypes.h" |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 26 | |
Christina Quast | c0aa769 | 2015-02-25 14:02:01 +0100 | [diff] [blame] | 27 | #include "simtrace.h" |
| 28 | |
Christina Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 29 | #define MIN(a, b) ((a < b) ? a : b) |
| 30 | |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 31 | #ifdef __GNUC__ |
| 32 | #undef __GNUC__ |
| 33 | #endif |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 34 | |
| 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 Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 44 | #define BOARD_MAINOSC 18432000 |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 45 | #define BOARD_MCK 48000000 |
| 46 | |
| 47 | #define LED_RED PIO_PA17 |
| 48 | #define LED_GREEN PIO_PA18 |
| 49 | |
Christina Quast | 0f1b36f | 2014-12-16 10:54:59 +0100 | [diff] [blame] | 50 | #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 Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 57 | /** 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 Quast | 394b894 | 2015-02-27 15:31:09 +0100 | [diff] [blame] | 64 | #define PINS_BUS_DEFAULT PIN_SC_SW_DEFAULT, PIN_IO_SW_DEFAULT |
Christina Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 65 | |
| 66 | /** Sniffer configuration **/ |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 67 | // Connect VPP, CLK and RST lines from smartcard to the phone |
Christina Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 68 | #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 Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 75 | |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 76 | /** 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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 89 | /** 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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 99 | /// Smartcard detection pin |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 100 | // FIXME: add connect pin as iso pin...should it be periph b or interrupt oder input? |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 101 | #define USART_SIM USART0 |
| 102 | #define ID_USART_SIM ID_USART0 |
| 103 | #define USART_PHONE USART1 |
| 104 | #define ID_USART_PHONE ID_USART1 |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 105 | |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 106 | #define SIM_PWEN PIO_PA5 |
| 107 | #define VCC_FWD PIO_PA26 |
| 108 | |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 109 | #define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
| 110 | |
Christina Quast | 83628d4 | 2015-03-03 23:08:44 +0100 | [diff] [blame^] | 111 | #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 Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 118 | #define SW_SIM PIO_PA8 |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 119 | #define SMARTCARD_CONNECT_PIN {SW_SIM, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_DEGLITCH | PIO_IT_EDGE } |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 120 | //#define SMARTCARD_CONNECT_PIN {SW_SIM, PIOB, ID_PIOB, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_IT_EDGE} |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 121 | |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 122 | /// PIN used for resetting the smartcard |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 123 | #define RST_SIM (1 << 7) |
| 124 | // FIXME: Card is resetted with pin set to 0 --> PIO_OUTPUT_1 as default is right? |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 125 | #define PIN_ISO7816_RSTMC {RST_SIM, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 126 | |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 127 | /// Pins used for connect the smartcard |
Christina Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame] | 128 | #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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 132 | //#define PINS_ISO7816 PIN_USART1_TXD, PIN_USART1_SCK, PIN_ISO7816_RSTMC |
Christina Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame] | 133 | #define PINS_ISO7816 PIN_SIM_IO, PIN_SIM_CLK, PIN_ISO7816_RSTMC // SIM_PWEN_PIN, PIN_SIM_IO2, PIN_SIM_CLK2 |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 134 | |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 135 | |
| 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 Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame] | 138 | #define PIN_PHONE_IO_INPUT {PIO_PA21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT} |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 139 | #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 Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame] | 141 | //#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 Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 143 | #define PINS_ISO7816_PHONE PIN_PHONE_IO, PIN_PHONE_CLK, PIN_ISO7816_RST_PHONE |
| 144 | //, VCC_PHONE |
| 145 | |
| 146 | |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 147 | //** 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 Quast | 27c643d | 2015-02-24 19:09:08 +0100 | [diff] [blame] | 160 | // USB pull-up control pin definition (PA16). |
| 161 | // Default: 1 (USB Pullup deactivated) |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 162 | #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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 187 | |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 188 | #endif |