blob: 27f74097879c8ff23b5e2d9977a3ff438aff9f48 [file] [log] [blame]
Harald Welte2d3371e2015-11-30 11:59:03 +01001#ifndef _BOARD_
2#define _BOARD_
3
4/** Headers */
5#include "chip.h"
6/* We need this for a nop instruction in USB_HAL.c */
7#define __CC_ARM
8
9/** Board */
10#include "board_lowlevel.h"
11#include "uart_console.h"
12#include "iso7816_4.h"
13#include "led.h"
14#include "cciddriver.h"
15#include "usart.h"
16#include "USBD.h"
17
18#include "USBD_Config.h"
19#include "USBDDriver.h"
20
21/** Highlevel */
22#include "trace.h"
23#include "stdio.h"
24#include "stdlib.h"
25#include "string.h"
26#include "inttypes.h"
Harald Welte83207e02017-02-03 22:16:47 +010027#include "syscalls.h"
Harald Welte2d3371e2015-11-30 11:59:03 +010028
Harald Welte2d3371e2015-11-30 11:59:03 +010029#define MIN(a, b) ((a < b) ? a : b)
30
31#ifdef __GNUC__
32#undef __GNUC__
33#endif
34
35/** Family definition (already defined) */
36#define sam3s
37/** Core definition */
38#define cortexm3
39
Harald Welte2d3371e2015-11-30 11:59:03 +010040#define BOARD_MCK 48000000
41
Harald Welteabba8a82017-03-06 16:58:00 +010042#define PIO_LED_RED PIO_PA17
43#define PIO_LED_GREEN PIO_PA17
Harald Welte2d3371e2015-11-30 11:59:03 +010044
Harald Welteabba8a82017-03-06 16:58:00 +010045#define PIN_LED_RED {PIO_LED_RED, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
46#define PIN_LED_GREEN {PIO_LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Harald Welte2d3371e2015-11-30 11:59:03 +010047#define PINS_LEDS PIN_LED_RED, PIN_LED_GREEN
48
49#define LED_NUM_RED 0
50#define LED_NUM_GREEN 1
51
52/** USART0 pin RX */
53#define PIN_USART0_RXD {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
54/** USART0 pin TX */
55#define PIN_USART0_TXD {PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
56
57#define BOARD_PIN_USART_RXD PIN_USART0_RXD
58#define BOARD_PIN_USART_TXD PIN_USART0_TXD
59
60#define BOARD_ID_USART ID_USART0
61#define BOARD_USART_BASE USART0
62
63#define PINS_UART { PIO_PA9A_URXD0|PIO_PA10A_UTXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
64
65/** UART0 */
66/** Console baudrate always using 115200. */
Harald Welte67415e32016-09-01 20:57:56 +020067#define CONSOLE_BAUDRATE 115200
Kévin Redoneac1bec2018-06-25 15:55:33 +020068/** UART peripheral used by the console (UART0). */
69#define CONSOLE_UART UART0
70/** UART peripheral ID used by the console (UART0). */
Harald Welte2d3371e2015-11-30 11:59:03 +010071#define CONSOLE_ID ID_UART0
Kévin Redoneac1bec2018-06-25 15:55:33 +020072/** UART ISR used by the console (UART0). */
73#define CONSOLE_ISR UART0_IrqHandler
74/** UART IRQ used by the console (UART0). */
75#define CONSOLE_IRQ UART0_IRQn
Harald Welte2d3371e2015-11-30 11:59:03 +010076/** Pins description corresponding to Rxd,Txd, (UART pins) */
77#define CONSOLE_PINS {PINS_UART}
78
79/// Smartcard detection pin
80// FIXME: add connect pin as iso pin...should it be periph b or interrupt oder input?
81#define BOARD_ISO7816_BASE_USART USART0
82#define BOARD_ISO7816_ID_USART ID_USART0
83
Kévin Redon4091d782018-06-11 13:43:27 +020084/* USART peripherals for a phone and SIM card setup */
85/* USART peripheral connected to the SIM card */
Harald Welte2d3371e2015-11-30 11:59:03 +010086#define USART_SIM USART0
Kévin Redon4091d782018-06-11 13:43:27 +020087/* ID of USART peripheral connected to the SIM card */
Harald Welte2d3371e2015-11-30 11:59:03 +010088#define ID_USART_SIM ID_USART0
Kévin Redon4091d782018-06-11 13:43:27 +020089/* Interrupt request ID of USART peripheral connected to the SIM card */
90#define IRQ_USART_SIM USART0_IRQn
91/* USART peripheral connected to the phone */
92#define USART_PHONE USART1
93/* ID of USART peripheral connected to the phone */
94#define ID_USART_PHONE ID_USART1
95/* Interrupt request ID of USART peripheral connected to the phone */
96#define IRQ_USART_PHONE USART1_IRQn
Harald Welte2d3371e2015-11-30 11:59:03 +010097
98#define SIM_PWEN PIO_PA5
99#define VCC_FWD PIO_PA26
100
Kévin Redonf5869d42018-06-17 22:31:21 +0200101/** Pin configuration to control USB pull-up on D+
102 * @details the USB pull-up on D+ is enable by default on the board but can be disabled by setting PA16 high
103 */
104#define PIN_USB_PULLUP {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
Harald Welte2d3371e2015-11-30 11:59:03 +0100105
106// Board has UDP controller
107#define BOARD_USB_UDP
108// D+ has external pull-up
109#define BOARD_USB_PULLUP_EXTERNAL
110
111#define BOARD_USB_NUMENDPOINTS 8
112
113// FIXME: in all other cases return 0?
114#define BOARD_USB_ENDPOINTS_MAXPACKETSIZE(i) (((i == 4) || (i == 5))? 512 : 64)
115#define BOARD_USB_ENDPOINTS_BANKS(i) (((i == 0) || (i == 3)) ? 1 : 2)
116
Harald Weltec6e482d2017-03-05 16:24:29 +0100117#define USB_VENDOR_OPENMOKO 0x1d50
Harald Welte2cbc9b22017-05-05 00:34:28 +0200118#define USB_PRODUCT_OWHW_SAM3_DFU 0x4001 /* was 0x4000 */
Harald Weltec6e482d2017-03-05 16:24:29 +0100119#define USB_PRODUCT_OWHW_SAM3 0x4001
120#define USB_PRODUCT_QMOD_HUB 0x4002
Harald Welte2cbc9b22017-05-05 00:34:28 +0200121#define USB_PRODUCT_QMOD_SAM3_DFU 0x4004 /* was 0x4003 */
Harald Weltec6e482d2017-03-05 16:24:29 +0100122#define USB_PRODUCT_QMOD_SAM3 0x4004
Harald Welte2cbc9b22017-05-05 00:34:28 +0200123#define USB_PRODUCT_SIMTRACE2_DFU 0x60e3 /* was 0x60e2 */
Harald Weltec6e482d2017-03-05 16:24:29 +0100124#define USB_PRODUCT_SIMTRACE2 0x60e3
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100125
126#define BOARD_USB_DFU
127#define BOARD_DFU_BOOT_SIZE (16 * 1024)
Harald Welte32852bc2017-02-28 00:21:45 +0100128#define BOARD_DFU_RAM_SIZE (2 * 1024)
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100129#define BOARD_DFU_PAGE_SIZE 512
130#define BOARD_DFU_NUM_IF 2
Harald Welteaa3b8672017-02-10 19:21:10 +0100131
132extern void board_exec_dbg_cmd(int ch);
133extern void board_main_top(void);
Harald Welte27f5fc62017-11-28 22:15:56 +0100134extern int board_override_enter_dfu(void);
Harald Welte2d3371e2015-11-30 11:59:03 +0100135#endif