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 | |
| 17 | /** Highlevel */ |
| 18 | #include "trace.h" |
| 19 | #include "stdio.h" |
Christina Quast | 99f9f7b | 2014-12-13 13:30:31 +0100 | [diff] [blame] | 20 | #include "stdlib.h" |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 21 | #include "string.h" |
Christina Quast | f6264fa | 2015-01-28 17:58:30 +0100 | [diff] [blame] | 22 | #include "inttypes.h" |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 23 | |
| 24 | #ifdef __GNUC__ |
| 25 | #undef __GNUC__ |
| 26 | #endif |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 27 | |
| 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 Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 37 | #define BOARD_MAINOSC 18432000 |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 38 | #define BOARD_MCK 48000000 |
| 39 | |
| 40 | #define LED_RED PIO_PA17 |
| 41 | #define LED_GREEN PIO_PA18 |
| 42 | |
Christina Quast | 0f1b36f | 2014-12-16 10:54:59 +0100 | [diff] [blame] | 43 | #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 Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 50 | /** 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 Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 59 | |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 60 | /** 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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 73 | /** 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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 83 | /// Smartcard detection pin |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 84 | // 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] | 85 | #define USART_SIM USART0 |
| 86 | #define ID_USART_SIM ID_USART0 |
| 87 | #define USART_PHONE USART1 |
| 88 | #define ID_USART_PHONE ID_USART1 |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 89 | |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 90 | #define SIM_PWEN PIO_PA5 |
| 91 | #define VCC_FWD PIO_PA26 |
| 92 | |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 93 | #define SIM_PWEN_PIN {PIO_PA5, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} |
| 94 | |
| 95 | #define SW_SIM PIO_PA8 |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 96 | #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] | 97 | //#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] | 98 | |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 99 | /// PIN used for resetting the smartcard |
Christina Quast | 11e80ae | 2014-12-19 19:14:02 +0100 | [diff] [blame] | 100 | #define RST_SIM (1 << 7) |
| 101 | // 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] | 102 | #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] | 103 | |
Christina Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 104 | /// Pins used for connect the smartcard |
Christina Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame^] | 105 | #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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 109 | //#define PINS_ISO7816 PIN_USART1_TXD, PIN_USART1_SCK, PIN_ISO7816_RSTMC |
Christina Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame^] | 110 | #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] | 111 | |
Christina Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 112 | |
| 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 Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame^] | 115 | #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] | 116 | #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 Quast | b455427 | 2015-01-30 16:28:45 +0100 | [diff] [blame^] | 118 | //#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 Quast | f7c28e0 | 2015-01-23 20:57:52 +0100 | [diff] [blame] | 120 | #define PINS_ISO7816_PHONE PIN_PHONE_IO, PIN_PHONE_CLK, PIN_ISO7816_RST_PHONE |
| 121 | //, VCC_PHONE |
| 122 | |
| 123 | |
Christina Quast | 5f46d04 | 2015-01-03 22:16:11 +0100 | [diff] [blame] | 124 | //** 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 Quast | dcb67a2 | 2014-12-10 16:30:24 +0100 | [diff] [blame] | 163 | |
Christina Quast | d51b5f4 | 2014-12-02 13:21:17 +0100 | [diff] [blame] | 164 | #endif |