diff --git a/firmware/libboard/sam3p256/include/board.h b/firmware/libboard/sam3p256/include/board.h new file mode 100644 index 00000000..bd2ab498 --- /dev/null +++ b/firmware/libboard/sam3p256/include/board.h @@ -0,0 +1,148 @@ +/* Olimiex SAM3S-P256 board definition + * + * (C) 2019 by Harald Welte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA + */ +#pragma once +#include "board_common.h" +#include "simtrace_usb.h" + +/* Name of the board */ +#define BOARD_NAME "SAM3S-P256" +/* Board definition */ +#define simtrace + +/** oscillator used as main clock source (in Hz) */ +#define BOARD_MAINOSC 12000000 +/** desired main clock frequency (in Hz, based on BOARD_MAINOSC) */ +#define BOARD_MCK 58000000 + +/** Pin configuration **/ +/* Button to force bootloader start (shorted to ground when pressed */ +#define PIN_BOOTLOADER_SW {PIO_PA20, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT} +#if 0 +/* Enable powering the card using the second 3.3 V output of the LDO (active high) */ +#define SIM_PWEN_PIN {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +/* Enable powering the SIM card */ +#define PWR_PINS SIM_PWEN_PIN +/* Card presence pin */ +#define SW_SIM PIO_PA8 +/* Pull card presence pin high (shorted to ground in card slot when card is present) */ +#define SMARTCARD_CONNECT_PIN {SW_SIM, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEBOUNCE | PIO_DEGLITCH | PIO_IT_EDGE } + +/** Smart card connection **/ +/* Card RST reset signal input (active low; RST_SIM in schematic) */ +#define PIN_SIM_RST {PIO_PA7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +/* Card I/O data signal input/output (I/O_SIM in schematic) */ +#define PIN_SIM_IO {PIO_PA6A_TXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* Card CLK clock input (CLK_SIM in schematic) */ +#define PIN_SIM_CLK {PIO_PA2B_SCK0, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} +/* Pin to measure card I/O timing (to start measuring the ETU on I/O activity; connected I/O_SIM in schematic) */ +#define PIN_SIM_IO_INPUT {PIO_PA1B_TIOB0, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} +/* Pin used as clock input (to measure the ETU duration; connected to CLK_SIM in schematic) */ +#define PIN_SIM_CLK_INPUT {PIO_PA4B_TCLK0, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} +/* Pins used to measure ETU timing (using timer counter) */ +#define PINS_TC PIN_SIM_IO_INPUT, PIN_SIM_CLK_INPUT + +/** Phone connection **/ +/* Phone USIM slot 1 VCC pin (VCC_PHONE in schematic) */ +#define PIN_USIM1_VCC {PIO_PA25, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT} +/* Phone USIM slot 1 RST pin (active low; RST_PHONE in schematic) */ +#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_IT_RISE_EDGE | PIO_DEGLITCH } +/* Phone I/O data signal input/output (I/O_PHONE in schematic) */ +#define PIN_PHONE_IO {PIO_PA22A_TXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* Phone CLK clock input (CLK_PHONE in schematic) */ +#define PIN_PHONE_CLK {PIO_PA23A_SCK1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* Pin used for phone USIM slot 1 communication */ +#define PINS_USIM1 PIN_PHONE_IO, PIN_PHONE_CLK, PIN_PHONE_CLK_INPUT, PIN_USIM1_VCC, PIN_PHONE_IO_INPUT, PIN_USIM1_nRST +/* Phone I/O data signal input/output (unused USART RX input; connected to I/O_PHONE in schematic) */ +#define PIN_PHONE_IO_INPUT {PIO_PA21A_RXD1, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* Pin used as clock input (to measure the ETU duration; connected to CLK_PHONE in schematic) */ +#define PIN_PHONE_CLK_INPUT {PIO_PA29B_TCLK2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT} + +/** Default pin configuration **/ +/* Disconnect VPP, CLK, and RST lines between card and phone using bus switch (high sets bus switch to high-impedance) */ +#define PIN_SC_SW_DEFAULT {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +/* Disconnect I/O line between card and phone using bus switch (high sets bus switch to high-impedance) */ +#define PIN_IO_SW_DEFAULT {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +/* Disconnect all lines (VPP, CLK, RST, and I/O) between card and phone */ +#define PINS_BUS_DEFAULT PIN_SC_SW_DEFAULT, PIN_IO_SW_DEFAULT + +/** Sniffer configuration **/ +/* Connect VPP, CLK, and RST lines between card and phone using bus switch (low connects signals on bus switch) */ +#define PIN_SC_SW_SNIFF {PIO_PA20, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +/* Connect I/O line between card and phone using bus switch (low connects signals on bus switch) */ +#define PIN_IO_SW_SNIFF {PIO_PA19, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +/* Connect all lines (VPP, CLK, RST, and I/O) between card and phone */ +#define PINS_BUS_SNIFF PIN_SC_SW_SNIFF, PIN_IO_SW_SNIFF +/* Card RST reset signal input (use as input since the phone will drive it) */ +#define PIN_SIM_RST_SNIFF {PIO_PA7, PIOA, ID_PIOA, PIO_INPUT, PIO_DEGLITCH | PIO_IT_EDGE} +/* Pins used to sniff phone-card communication */ +#define PINS_SIM_SNIFF PIN_SIM_IO, PIN_SIM_CLK, PIN_SIM_RST_SNIFF +/* Disable power converter 4.5-6V to 3.3V (active high) */ +#define PIN_SIM_PWEN_SNIFF {SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +/* Enable power switch to forward VCC_PHONE to VCC_SIM (active high) */ +#define PIN_VCC_FWD_SNIFF {VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +/* Use phone VCC to power card */ +#define PINS_PWR_SNIFF PIN_SIM_PWEN_SNIFF, PIN_VCC_FWD_SNIFF + +/** CCID configuration */ +/* Card RST reset signal input (active low; RST_SIM in schematic) */ +#define PIN_ISO7816_RSTMC {PIO_PA7, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +/* ISO7816-communication related pins */ +#define PINS_ISO7816 PIN_SIM_IO, PIN_SIM_CLK, PIN_ISO7816_RSTMC // SIM_PWEN_PIN, PIN_SIM_IO2, PIN_SIM_CLK2 + +/** External SPI flash interface **/ +/* SPI MISO pin definition */ +#define PIN_SPI_MISO {PIO_PA12A_MISO, PIOA, PIOA, PIO_PERIPH_A, PIO_PULLUP} +/* SPI MOSI pin definition */ +#define PIN_SPI_MOSI {PIO_PA13A_MOSI, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* SPI SCK pin definition */ +#define PIN_SPI_SCK {PIO_PA14A_SPCK, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* SPI pins definition. Contains MISO, MOSI & SCK */ +#define PINS_SPI PIN_SPI_MISO, PIN_SPI_MOSI, PIN_SPI_SCK +/* SPI chip select 0 pin definition */ +#define PIN_SPI_NPCS0 {PIO_PA11A_NPCS0, PIOA, PIOA, PIO_PERIPH_A, PIO_DEFAULT} +/* SPI flash write protect pin (active low, pulled low) */ +#define PIN_SPI_WP {PA15, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} +#endif + +/** Pin configuration to control USB pull-up on D+ + * @details the USB pull-up on D+ is enable by default on the board but can be disabled by setting PA16 high + */ +#define PIN_USB_PULLUP {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} + +/** USB definitions */ +/* OpenMoko SIMtrace 2 USB vendor ID */ +#define BOARD_USB_VENDOR_ID USB_VENDOR_OPENMOKO +/* OpenMoko SIMtrace 2 USB product ID (main application/runtime mode) */ +#define BOARD_USB_PRODUCT_ID USB_PRODUCT_SIMTRACE2 +/* OpenMoko SIMtrace 2 DFU USB product ID (DFU bootloader/DFU mode) */ +#define BOARD_DFU_USB_PRODUCT_ID USB_PRODUCT_SIMTRACE2_DFU +/* USB release number (bcdDevice, shown as 0.00) */ +#define BOARD_USB_RELEASE 0x000 +/* Indicate SIMtrace is bus power in USB attributes */ +#define BOARD_USB_BMATTRIBUTES USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP + +/** Supported modes */ +/* SIMtrace board supports sniffer mode */ +#define HAVE_SNIFFER +/* SIMtrace board supports CCID mode */ +//#define HAVE_CCID +/* SIMtrace board supports card emulation mode */ +//#define HAVE_CARDEM +/* SIMtrace board supports man-in-the-middle mode */ +//#define HAVE_MITM diff --git a/firmware/libboard/sam3p256/source/board_sam3p256.c b/firmware/libboard/sam3p256/source/board_sam3p256.c new file mode 100644 index 00000000..4b6a4519 --- /dev/null +++ b/firmware/libboard/sam3p256/source/board_sam3p256.c @@ -0,0 +1,68 @@ +/* Olimex SAM3S-P256 specific application code + * + * (C) 2017,2019 by Harald Welte + * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA + */ +#include "board.h" +#include "simtrace.h" +#include "utils.h" +#include "sim_switch.h" +#include +#include "usb_buf.h" + +void board_exec_dbg_cmd(int ch) +{ + switch (ch) { + case '?': + printf("\t?\thelp\n\r"); + printf("\tR\treset SAM3\n\r"); + break; + case 'R': + printf("Asking NVIC to reset us\n\r"); + USBD_Disconnect(); + NVIC_SystemReset(); + break; + default: + printf("Unknown command '%c'\n\r", ch); + break; + } +} + +void board_main_top(void) +{ +#ifndef APPLICATION_dfu + usb_buf_init(); + + /* Initialize checking for card insert/remove events */ + //card_present_init(); +#endif +} + +int board_override_enter_dfu(void) +{ + const Pin bl_sw_pin = PIN_BOOTLOADER_SW; + + PIO_Configure(&bl_sw_pin, 1); + + /* Enter DFU bootloader in case the respective button is pressed */ + if (PIO_Get(&bl_sw_pin) == 0) { + /* do not print to early since the console is not initialized yet */ + //printf("BOOTLOADER switch pressed -> Force DFU\n\r"); + return 1; + } else + return 0; +} diff --git a/hardware/board_gpio.gnumeric b/hardware/board_gpio.gnumeric index 3d76b0a0..1ec9ff6b 100644 --- a/hardware/board_gpio.gnumeric +++ b/hardware/board_gpio.gnumeric @@ -1,6 +1,6 @@ - + WorkbookView::show_horizontal_scrollbar @@ -25,7 +25,7 @@ - 2017-05-05T14:31:27Z + 2019-02-28T17:12:35Z 2017-03-05T18:42:38Z @@ -35,11 +35,11 @@ Sheet2 Sheet3 - + Sheet1 - 7 + 9 67 1 @@ -1057,127 +1057,452 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1190,15 +1515,27 @@ - - - + + + + + + + + + + + + + + Pins / Ios of SAM3 based devices SIMtrace v1.x Quad Modem OWHW + SAM3-P256 Pin Number Pin Name Used Function @@ -1207,6 +1544,8 @@ Signal Name Used Function Signal Name + Used Function + Signal Name 1 ADVREF ADVREF @@ -1245,6 +1584,7 @@ LED_RED PA17 LED_RED + LED2 10 PA18 PA18 @@ -1253,6 +1593,7 @@ LED_GREEN PA18 LED_GREEN + LED1 11 PA21/RXD1/PCK1 RXD1 @@ -1261,6 +1602,7 @@ ST_USIM1_IO RXD1 ST_USIM1_IO + RXD1 12 VDDCORE 13 @@ -1270,6 +1612,7 @@ AD2 VERSION_DETECT12 NC + B1 14 PA22/TXD1/NPCS3 TXD1 @@ -1278,6 +1621,7 @@ ST_USIM1_IO TXD1 ST_USIM1_IO + TXD1 15 PA23/SCK1/PWM0 SCK1 @@ -1293,6 +1637,7 @@ PA20 !CONNECT_ST_USIM1 NC + B2 17 GND 18 @@ -1305,6 +1650,7 @@ WWAN2 PA16 UDP_PUP_CTL + DP_PUP 20 PA15/TF/TIOA1 PA15 @@ -1320,6 +1666,7 @@ ST12_ST34_SELECT PA14 SET_USIM2_PRES + SPCK 22 PA13/MOSI/PWM2 MOSI @@ -1327,6 +1674,7 @@ PA13 HUB_RESET NC + MOSI 23 PA24/RTS1/PWM1 PA24 @@ -1359,6 +1707,7 @@ SIMPRES1 PA12 SET_USIM1_PRES + MISO 28 PA11/NPCS0/PWM0 NPCS0 @@ -1366,6 +1715,7 @@ PA11 _SIMTRACE34_ERASE NC + NPCS0 29 PA10/DTXD/NCPS2 DTXD @@ -1374,6 +1724,7 @@ SIMTRACE1_DTXD DTXD SIMTRACE_DTXD + DTXD 30 PA9/DRXDNPCS1 DRXD @@ -1382,6 +1733,7 @@ SIMTRACE1_DRXD DRXD SIMTRACE_DRXD + DRXD 31 PA8/CTS0/ADTRG PA8 @@ -1389,6 +1741,7 @@ PA8 SIMPRES2 / ST12_PRTPWR-OVERRIDE NC + DM_PUP 32 PA7/RTS0/PWM3 PA7 @@ -1424,6 +1777,7 @@ ST_USIM2_CLK TCLK0 ST_USIM2_CLK + TWCK 37 PA27/DTR1/TIOB2 NC @@ -1470,6 +1824,7 @@ NC NC NC + TWD 44 PA2/PWM2/SCK0 SCK0 @@ -1522,6 +1877,7 @@ BOTLOADER_SW PA31 SCL + NPCS1 53 TCK TCK @@ -1565,7 +1921,7 @@ 64 VDDPLL - +