aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-08-21 18:32:12 +0200
committerHarald Welte <laforge@gnumonks.org>2016-08-21 18:32:12 +0200
commita02b641650175c1a728cf26769b2dd0e28ff4ea6 (patch)
tree1cd615b7977604b20b7328b6f12a6daeabc39aea
parentfd9c041ec88a1fb7da55f08daa2ceaf3fc621a8e (diff)
Add support for 'qmod' (quad-modem) boardlaforge/cardemu
You can compile the firmware for this new target using 'make BOARD=qmod'. The QMOD differs from simtrace+owhw in terms of low-level initialization, as it has an external 12MHz clock at XIN, thus bypasses the main oscillator and needs different PLL configuration.
-rw-r--r--firmware/Makefile3
-rw-r--r--firmware/include_board/board_common.h1
-rw-r--r--firmware/include_board/owhw/board.h2
-rw-r--r--firmware/include_board/qmod/board.h52
-rw-r--r--firmware/include_board/simtrace/board.h2
-rw-r--r--firmware/src_board/board_lowlevel.c20
6 files changed, 75 insertions, 5 deletions
diff --git a/firmware/Makefile b/firmware/Makefile
index a32ddc6..588601d 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -96,8 +96,7 @@ INCLUDES_USB = -Iatmel_softpack_libraries/usb/include
INCLUDES = -Iinclude_board -Iinclude_sam3s -Iinclude -Isrc_simtrace
# FIXME: This must be made configurable!
-#INCLUDES += -Iinclude_board/simtrace
-INCLUDES += -Iinclude_board/owhw
+INCLUDES += -Iinclude_board/$(BOARD)
INCLUDES += -Icmsis
INCLUDES += $(INCLUDES_USB)
diff --git a/firmware/include_board/board_common.h b/firmware/include_board/board_common.h
index cac0ef8..eda500f 100644
--- a/firmware/include_board/board_common.h
+++ b/firmware/include_board/board_common.h
@@ -36,7 +36,6 @@
/** Core definition */
#define cortexm3
-#define BOARD_MAINOSC 18432000
#define BOARD_MCK 48000000
#define LED_RED PIO_PA17
diff --git a/firmware/include_board/owhw/board.h b/firmware/include_board/owhw/board.h
index ebfc618..c5e67d1 100644
--- a/firmware/include_board/owhw/board.h
+++ b/firmware/include_board/owhw/board.h
@@ -6,6 +6,8 @@
/** Board definition */
#define owhw
+#define BOARD_MAINOSC 18432000
+
/* USIM 2 interface (USART) */
#define PIN_USIM2_CLK {PIO_PA2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
#define PIN_USIM2_IO {PIO_PA6, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
diff --git a/firmware/include_board/qmod/board.h b/firmware/include_board/qmod/board.h
new file mode 100644
index 0000000..28d064f
--- /dev/null
+++ b/firmware/include_board/qmod/board.h
@@ -0,0 +1,52 @@
+#pragma once
+#include "board_common.h"
+
+/** Name of the board */
+#define BOARD_NAME "QMOD"
+/** Board definition */
+#define qmod
+
+#define BOARD_MAINOSC 12000000
+
+/* USIM 2 interface (USART) */
+#define PIN_USIM2_CLK {PIO_PA2, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
+#define PIN_USIM2_IO {PIO_PA6, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
+#define PINS_ISO7816_USIM2 PIN_USIM2_CLK, PIN_USIM2_IO
+
+/* USIM 2 interface (TC) */
+#define PIN_USIM2_IO_TC {PIO_PA1, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
+#define PIN_USIM2_CLK_TC {PIO_PA4, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
+#define PINS_TC_USIM2 PIN_USIM2_IO_TC, PIN_USIM2_CLK_TC
+
+/* USIM 1 interface (USART) */
+#define PIN_USIM1_IO {PIO_PA22, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
+#define PIN_USIM1_CLK {PIO_PA23, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
+#define PINS_ISO7816_USIM1 PIN_USIM1_CLK, PIN_USIM1_IO
+
+/* USIM 1 interface (TC) */
+#define PIN_USIM1_IO_TC {PIO_PA27, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
+#define PIN_USIM1_CLK_TC {PIO_PA29, PIOA, ID_PIOA, PIO_PERIPH_B, PIO_DEFAULT}
+#define PINS_TC_USIM1 PIN_USIM1_IO_TC, PIN_USIM1_CLK_TC
+
+#define PIN_SET_USIM1_PRES {PIO_PA12, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+#define PIN_USIM1_nRST {PIO_PA24, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
+#define PIN_USIM1_VCC {PIO_PB3, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
+
+#define PIN_SET_USIM2_PRES {PIO_PA14, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+#define PIN_USIM2_nRST {PIO_PA7, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT}
+#define PIN_USIM2_VCC {PIO_PB2, PIOB, ID_PIOB, PIO_INPUT, PIO_DEFAULT}
+
+#define PINS_USIM1 PINS_TC_USIM1, PINS_ISO7816_USIM1, PIN_USIM1_nRST, PIN_SET_USIM1_PRES
+#define PINS_USIM2 PINS_TC_USIM2, PINS_ISO7816_USIM2, PIN_USIM2_nRST, PIN_SET_USIM2_PRES
+
+#define PINS_CARDSIM { PIN_SET_USIM1_PRES, PIN_SET_USIM2_PRES }
+
+#define SIMTRACE_VENDOR_ID 0x1d50
+#define SIMTRACE_PRODUCT_ID 0x60e3 /* FIXME */
+#define USB_VENDOR_ID SIMTRACE_VENDOR_ID
+#define USB_PRODUCT_ID SIMTRACE_PRODUCT_ID
+
+#define CARDEMU_SECOND_UART
+#define DETECT_VCC_BY_ADC
+
+#define HAVE_CARDEM
diff --git a/firmware/include_board/simtrace/board.h b/firmware/include_board/simtrace/board.h
index d7d94f5..6d11dae 100644
--- a/firmware/include_board/simtrace/board.h
+++ b/firmware/include_board/simtrace/board.h
@@ -6,6 +6,8 @@
/** Board definition */
#define simtrace
+#define BOARD_MAINOSC 18432000
+
/** Phone (SIM card emulator)/CCID Reader/MITM configuration **/
/* Normally the communication lines between phone and SIM card are disconnected */
// Disconnect SIM card I/O, VPP line from the phone lines
diff --git a/firmware/src_board/board_lowlevel.c b/firmware/src_board/board_lowlevel.c
index 786a09a..e207001 100644
--- a/firmware/src_board/board_lowlevel.c
+++ b/firmware/src_board/board_lowlevel.c
@@ -43,15 +43,23 @@
* Local definitions
*----------------------------------------------------------------------------*/
-/* Clock settings at 48MHz for 18 MHz crystal */
#if (BOARD_MCK == 48000000)
+#ifndef qmod
+/* Clock settings at 48MHz for 18 MHz crystal */
#define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST(0x8))
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
| CKGR_PLLAR_MULA(0xc) \
| CKGR_PLLAR_PLLACOUNT(0x1) \
| CKGR_PLLAR_DIVA(0x5))
#define BOARD_MCKR (PMC_MCKR_PRES_CLK | PMC_MCKR_CSS_PLLA_CLK)
-
+#else /* qmod */
+/* QMod has 12 MHz clock, so multply by 4 and divide by 1 */
+#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
+ | CKGR_PLLAR_MULA(4-1) \
+ | CKGR_PLLAR_PLLACOUNT(0x1) \
+ | CKGR_PLLAR_DIVA(1))
+#define BOARD_MCKR (PMC_MCKR_PRES_CLK | PMC_MCKR_CSS_PLLA_CLK)
+#endif
/* Clock settings at 64MHz for 18 MHz crystal */
#elif (BOARD_MCK == 64000000)
#define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST(0x8))
@@ -98,6 +106,7 @@ extern WEAK void LowLevelInit( void )
}
*/
+#ifndef qmod
/* Initialize main oscillator */
if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) )
{
@@ -114,6 +123,13 @@ extern WEAK void LowLevelInit( void )
/* wait for Main XTAL oscillator stabilization */
timeout = 0;
while (!(PMC->PMC_SR & PMC_SR_MOSCSELS) && (timeout++ < CLOCK_TIMEOUT));
+#else
+ /* QMOD has external 12MHz clock source */
+ PIOB->PIO_PDR = (1 << 9);
+ PIOB->PIO_PUDR = (1 << 9);
+ PIOB->PIO_PPDDR = (1 << 9);
+ PMC->CKGR_MOR = CKGR_MOR_KEY(0x37) | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTBY| CKGR_MOR_MOSCSEL;
+#endif
/* disable the red LED after main clock initialization */
PIOA->PIO_SODR = LED_RED;